MP0的目标:熟悉课程的提交系统及硬件使用
这个测试其实它已经给你代码了,你可以cp到本机测试等。
在这之前,可以到GitHub下载所需的源文件:https://github.com/ashwin/coursera-heterogeneous
解压后可以看下README,理解有讲具体的。
我使用的是Ubuntu12.04,linux-based system, 只需要将 src/wb.h cp到cuda-5.0/include下就行了.
$ cp src/wb.h /usr/local/cuda-5.0/include
然后,可以用命令行或Eclipse Nsight来运行程序,具体可以看我的另一篇博文《Eclipse Nsight编译CUDA项目》.
代码如下:
#include <wb.h>
//@@ The purpose of this code is to become familiar with the submission
//@@ process. Do not worry if you do not understand all the details of
//@@ the code.
int main(int argc, char ** argv) {
int deviceCount;
wbArg_read(argc, argv);
cudaGetDeviceCount(&deviceCount);
for (int dev = 0; dev < deviceCount; dev++) {
cudaDeviceProp deviceProp;
cudaGetDeviceProperties(&deviceProp, dev);
if (dev == 0) {
if (deviceProp.major == 9999 && deviceProp.minor == 9999) {
wbLog(TRACE, "No CUDA GPU has been detected");
return -1;
} else if (deviceCount == 1) {
//@@ WbLog is a provided logging API (similar to Log4J).
//@@ The logging function wbLog takes a level which is either
//@@ OFF, FATAL, ERROR, WARN, INFO, DEBUG, or TRACE and a
//@@ message to be printed.
wbLog(TRACE, "There is 1 device supporting CUDA");
} else {
wbLog(TRACE, "There are ", deviceCount, " devices supporting CUDA");
}
}
wbLog(TRACE, "Device ", dev, " name: ", deviceProp.name);
wbLog(TRACE, " Computational Capabilities: ", deviceProp.major, ".", deviceProp.minor);
wbLog(TRACE, " Maximum global memory size: ", deviceProp.totalGlobalMem);
wbLog(TRACE, " Maximum constant memory size: ", deviceProp.totalConstMem);
wbLog(TRACE, " Maximum shared memory size per block: ", deviceProp.sharedMemPerBlock);
wbLog(TRACE, " Maximum block dimensions: ", deviceProp.maxThreadsDim[0], " x ",
deviceProp.maxThreadsDim[1], " x ",
deviceProp.maxThreadsDim[2]);
wbLog(TRACE, " Maximum grid dimensions: ", deviceProp.maxGridSize[0], " x ",
deviceProp.maxGridSize[1], " x ",
deviceProp.maxGridSize[2]);
wbLog(TRACE, " Warp size: ", deviceProp.warpSize);
}
return 0;
}
测试结果:
Trace main::28 There is 1 device supporting CUDA
Trace main::34 Device 0 name: GeForce GT 555M
Trace main::35 Computational Capabilities: 2.1
Trace main::36 Maximum global memory size: 1073414144
Trace main::37 Maximum constant memory size: 65536
Trace main::38 Maximum shared memory size per block: 49152
Trace main::41 Maximum block dimensions: 1024 x 1024 x 64
Trace main::44 Maximum grid dimensions: 65535 x 65535 x 65535
Trace main::45 Warp size: 32