Hetergeneous Parallel Programming编程作业之MP0: Initial Lab Tour with Device Query

8 篇文章 0 订阅
4 篇文章 0 订阅

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


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值