2010年11月20日 星期六
C語言: __FILE__, __LINE__
最近在書上看到一些使用__FILE__跟__LINE__的例子,所以就試著寫一段小程式print一下:
//-------------------------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
int main(){
printf("line: %d \n", __LINE__);
printf("file: %s \n", __FILE__);
printf("function: %s \n", __FUNCTION__);
printf("time: %s \n", __TIME__);
printf("date: %s \n", __DATE__);
printf("TIMESTAMP: %s \n", __TIMESTAMP__);
return 0;
}
//-------------------------------------------------------------------------
Result:
//-------------------------------------------------------------------------
line: 4
file: d:\cr project\rssi\test_print\test_print\test_print.cpp
function: main
time: 17:10:02
date: Nov 19 2010
TIMESTAMP: Fri Nov 19 17:10:01 2010
//-------------------------------------------------------------------------
//-------------------------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
int main(){
printf("line: %d \n", __LINE__);
printf("file: %s \n", __FILE__);
printf("function: %s \n", __FUNCTION__);
printf("time: %s \n", __TIME__);
printf("date: %s \n", __DATE__);
printf("TIMESTAMP: %s \n", __TIMESTAMP__);
return 0;
}
//-------------------------------------------------------------------------
Result:
//-------------------------------------------------------------------------
line: 4
file: d:\cr project\rssi\test_print\test_print\test_print.cpp
function: main
time: 17:10:02
date: Nov 19 2010
TIMESTAMP: Fri Nov 19 17:10:01 2010
//-------------------------------------------------------------------------
測量CUDA kernel的執行時間
以下是我找到一些測試kernel function的方法:
1. cutCreateTimer : 單位 ms ->據說在GPU上比較準(我自己實際測好像也是如此)
#include <cutil_inline.h>
....
// create and start timer
unsigned int timer = 0;
cutilCheckError(cutCreateTimer(&timer));
cutilCheckError(cutStartTimer(timer));
1. cutCreateTimer : 單位 ms ->據說在GPU上比較準(我自己實際測好像也是如此)
#include <cutil_inline.h>
....
// create and start timer
unsigned int timer = 0;
cutilCheckError(cutCreateTimer(&timer));
cutilCheckError(cutStartTimer(timer));
....
// stop and destroy timer
cutilCheckError(cutStopTimer(timer));
printf("GPU Processing time: %f (ms) \n", cutGetTimerValue(timer));
cutilCheckError(cutDeleteTimer(timer));
2. cuda event: 單位 ms ->還在測試準度...感覺沒上面來的精準
.....
cudaEvent_t gpu0,gpu1;
cudaEventCreate(&gpu0);
cudaEventCreate(&gpu0);
cudaEventCreate(&gpu1);
...
// Start
cudaEventRecord(gpu0, 0);
.... // your program
// stop
cudaEventRecord(gpu1, 0);
cudaEventSynchronize(gpu1); // not sure if we have to add this one....
float gpu_time;
cudaEventElapsedTime(&gputime, gpu0, gpu1);
printf(" %f " ,gpu_time);
...
// Start
cudaEventRecord(gpu0, 0);
.... // your program
// stop
cudaEventRecord(gpu1, 0);
cudaEventSynchronize(gpu1); // not sure if we have to add this one....
float gpu_time;
cudaEventElapsedTime(&gputime, gpu0, gpu1);
printf(" %f " ,gpu_time);
2010年11月19日 星期五
CUDA 3.2設定
NVIDIA CUDA 3.2終於從RC變成正式版了。有興趣可以前往此網址下載:
http://developer.nvidia.com/object/cuda_3_2_downloads.html
關於詳細的更新內容,就上網查看囉~
不過這次SDK資料夾有點改變...害我之前好多程式都不能跑@@這邊附上今天改寫好的路徑,這樣下次就不會忘了~
3.2版:
$(CUDA_INC_PATH);C:\ProgramData\NVIDIA Corporation\NVIDIA GPU Computing SDK 3.2\C\common\inc;C:\ProgramData\NVIDIA Corporation\NVIDIA GPU Computing SDK 3.2\shared\inc
$(CUDA_LIB_PATH);C:\ProgramData\NVIDIA Corporation\NVIDIA GPU Computing SDK 3.2\C\common\lib;C:\ProgramData\NVIDIA Corporation\NVIDIA GPU Computing SDK 3.2\shared\lib
cudart.lib cutil32D.lib shrUtils32D.lib
有衝突時使用(cpp or c):
C/C++ Code Generation: Runtime Library (/MTD)
3.2以前的版本就把在路徑裡面的" 3.2"移除就可以了~
PS: VS2010好像還是不太好設定一些CUDA的參數路徑....還是先用VS2008吧~
http://developer.nvidia.com/object/cuda_3_2_downloads.html
關於詳細的更新內容,就上網查看囉~
不過這次SDK資料夾有點改變...害我之前好多程式都不能跑@@這邊附上今天改寫好的路徑,這樣下次就不會忘了~
3.2版:
$(CUDA_INC_PATH);C:\ProgramData\NVIDIA Corporation\NVIDIA GPU Computing SDK 3.2\C\common\inc;C:\ProgramData\NVIDIA Corporation\NVIDIA GPU Computing SDK 3.2\shared\inc
$(CUDA_LIB_PATH);C:\ProgramData\NVIDIA Corporation\NVIDIA GPU Computing SDK 3.2\C\common\lib;C:\ProgramData\NVIDIA Corporation\NVIDIA GPU Computing SDK 3.2\shared\lib
cudart.lib cutil32D.lib shrUtils32D.lib
有衝突時使用(cpp or c):
C/C++ Code Generation: Runtime Library (/MTD)
3.2以前的版本就把在路徑裡面的" 3.2"移除就可以了~
PS: VS2010好像還是不太好設定一些CUDA的參數路徑....還是先用VS2008吧~
2010年11月18日 星期四
C語言紀錄程式執行時間的方法
最近一直在比程式的執行速度,測的方法又五花八門@@
這邊就記一個用time.h中的函式來計算所花時間的辦法:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main() {
clock_t start, end;
// Start Record the time
start = clock();
// Your program....
// Record the end time
end = clock();
double diff = end - start; // ms
printf(" %f ms" , diff);
printf(" %f sec", diff / CLOCKS_PER_SEC );
return 0;
}
這邊就記一個用time.h中的函式來計算所花時間的辦法:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main() {
clock_t start, end;
// Start Record the time
start = clock();
// Your program....
// Record the end time
end = clock();
double diff = end - start; // ms
printf(" %f ms" , diff);
printf(" %f sec", diff / CLOCKS_PER_SEC );
return 0;
}
訂閱:
文章 (Atom)