最近CUDAを触り始め、現在はプログラミングガイドや、理研の入門テキストを読みながら学習中です。
その中でプログラムの実行時間が知りたくなったので、以下のサイトを参考に実装したのですが……コンパイルエラーが出て動きませんでした。
/*タイマーを作成して計測開始*/
unsigned int timer = 0;
CUT_SAFE_CALL( cutCreateTimer( &timer));
CUT_SAFE_CALL( cutStartTimer( timer));
// 処理
/*タイマーを停止しかかった時間を表示*/
CUT_SAFE_CALL( cutStopTimer( timer));
printf("Processing time: %f (msec)\n", cutGetTimerValue( timer));
CUT_SAFE_CALL( cutDeleteTimer( timer));
調べてみたところ、どうやらCUDAのバージョンによって関数名やヘッダファイル等が違うそうで、以下のサイトによるとCUDA5からは以下のコードを使う必要があるようです。
#include <helper_functions.h>
#include <helper_cuda.h>
#include <helper_timer.h>
StopWatchInterface *timer=NULL;
sdkCreateTimer(&timer);
sdkResetTimer(&timer);
sdkStartTimer(&timer);
// 処理
sdkStopTimer(&timer);
float time = sdkGetTimerValue(&timer);
sdkDeleteTimer(&timer);
printf("Processing time: %f (msec)\n", time);
これをコンパイルしてみたのですが……StopWatchInterfaceなど無いと言われてしまいました。
調べてみると、helper_timer.h等の一部のヘッダファイルは、 /usr/local/cuda-6.0/samples/common/inc 入っているようです。
この場所を読み込むようにコンパイルオプションを追加します。
% nvcc -I/usr/local/cuda-6.0/samples/common/inc -O0 -o hoge hoge.cu
これで実行時間が計れるはずです( 正確に計りたい場合はcudaEventRecord関数などを使うといいみたいです)。
実行環境
$ uname -a Linux tegra-ubuntu 3.10.24-gf455cd4 #1 SMP PREEMPT Wed Jun 18 11:20:52 PDT 2014 armv7l armv7l armv7l GNU/Linux $ nvcc --version nvcc: NVIDIA (R) Cuda compiler driver Copyright (c) 2005-2013 NVIDIA Corporation Built on Sat_Mar_15_02:05:29_PDT_2014 Cuda compilation tools, release 6.0, V6.0.1
お願い
CUDAに関しては勉強を始めたばかりなので、初心者向けにおすすめな本やサイトが有りましたら、教えていただけると嬉しいです。
よろしくお願いします。