前提・実現したいこと
ここに質問の内容を詳しく書いてください。
cudaを用いた粒子法解析のサンプルプログラムを動かしているのですがエラーが出てきてうまくいきません。こちらのサンプルは参考書にあったものをダウンロードして使用しましたが下にある通りエラーが出ます。しかし、cuda9.1をインストールしたときにあった別のサンプルでは、同様に赤色の波線でプログラム上ではエラー[undeclared identifier]と表示されているのにも関わらず、ちゃんとビルドすることができプログラムを動かすことができます。参考書のプログラムのエラーを取り除くにはどのようにすればよいのでしょうか
発生している問題・エラーメッセージ
エラーメッセージ ```Error 3 error C2065: 'blockDim' : undeclared identifier C:\ProgramData\NVIDIA Corporation\CUDA Samples\v9.1\2_Graphics\simpleGL\Particle2D_kernel.cu 24 1 simpleGL Error 4 error C2228: left of '.x' must have class/struct/union C:\ProgramData\NVIDIA Corporation\CUDA Samples\v9.1\2_Graphics\simpleGL\Particle2D_kernel.cu 24 1 simpleGL Error 5 error C2065: 'blockIdx' : undeclared identifier C:\ProgramData\NVIDIA Corporation\CUDA Samples\v9.1\2_Graphics\simpleGL\Particle2D_kernel.cu 24 1 simpleGL Error 6 error C2065: 'threadIdx' : undeclared identifier C:\ProgramData\NVIDIA Corporation\CUDA Samples\v9.1\2_Graphics\simpleGL\Particle2D_kernel.cu 24 1 simpleGL Error 7 error C2059: syntax error : '<' C:\ProgramData\NVIDIA Corporation\CUDA Samples\v9.1\2_Graphics\simpleGL\Particle2D_kernel.cu 69 1 simpleGL 8 IntelliSense: identifier "blockDim" is undefined c:\ProgramData\NVIDIA Corporation\CUDA Samples\v9.1\2_Graphics\simpleGL\Particle2D_kernel.cu 24 10 simpleGL 9 IntelliSense: identifier "blockIdx" is undefined c:\ProgramData\NVIDIA Corporation\CUDA Samples\v9.1\2_Graphics\simpleGL\Particle2D_kernel.cu 24 23 simpleGL 10 IntelliSense: identifier "threadIdx" is undefined c:\ProgramData\NVIDIA Corporation\CUDA Samples\v9.1\2_Graphics\simpleGL\Particle2D_kernel.cu 24 36 simpleGL 11 IntelliSense: expected an expression c:\ProgramData\NVIDIA Corporation\CUDA Samples\v9.1\2_Graphics\simpleGL\Particle2D_kernel.cu 69 18 simpleGL ### 該当のソースコード ```C++ ソースコード ```#include <helper_math.h> #define PI 3.141592653589793 // GPU処理. #define d_U(x, y, t) (- 2.0f * (float)cos(PI * (t) / 8.0f) * (float)sin(PI * (x)) * (float)sin(PI * (x)) * (float)cos(PI * (y)) * (float)sin(PI * (y))) #define d_V(x, y, t) (2.0f * (float)cos(PI * (t) / 8.0f) * (float)cos(PI * (x)) * (float)sin(PI * (x)) * (float)sin(PI * (y)) * (float)sin(PI * (y))) // GPU用ルンゲ・クッタ法 __global__ void d_RungeKutta(unsigned int num_particles, float(*pos)[2], float time, float dt) // unsigned int num_particles; 粒子の総数. // float (*pos)[2]; 粒子位置. // float time; 時刻. // float dt; 時間刻み. { unsigned int index; float xn, yn, p1, q1, p2, q2, p3, q3, p4, q4; float x, y, t; // 処理対象の粒子の決定. index = blockDim.x * blockIdx.x + threadIdx.x; if (index >= num_particles) return; xn = pos[index][0]; yn = pos[index][1]; // 1段目. p1 = d_U(xn, yn, time); q1 = d_V(xn, yn, time); // 2段目. x = xn + 0.5f * p1 * dt; y = yn + 0.5f * q1 * dt; t = time + 0.5f * dt; p2 = d_U(x, y, t); q2 = d_V(x, y, t); // 3段目. x = xn + 0.5f * p2 * dt; y = yn + 0.5f * q2 * dt; t = time + 0.5f * dt; p3 = d_U(x, y, t); q3 = d_V(x, y, t); // 4段目. x = xn + p3 * dt; y = yn + q3 * dt; t = time + dt; p4 = d_U(x, y, t); q4 = d_V(x, y, t); // 粒子位置の更新. pos[index][0] = xn + (p1 + 2 * p2 + 2 * p3 + p4) / 6.0f * dt; pos[index][1] = yn + (q1 + 2 * q2 + 2 * q3 + q4) / 6.0f * dt; } // GPU処理の起動. void launchGPUKernel(unsigned int num_particles, float(*pos)[2], float time, float dt) // unsigned int num_particles; 粒子の総数. // float (*pos)[2]; 粒子位置. // float time; 時刻. // float dt; 時間刻み. { dim3 grid(num_particles / 512 + 1, 1); dim3 block(512, 1, 1); d_RungeKutta << < grid, block >> > (num_particles, pos, time, dt); } ### 補足情報(FW/ツールのバージョンなど) 参考書は「GPU並列図形処理入門」を使用しています。ただし、参考書ではvisual studio2010,cuda7.0を用いていますが 自分はvisual studio2013 cuda9.1で動かしています。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/02/01 12:21
2018/02/01 13:09