zoukankan      html  css  js  c++  java
  • 0_Simple__simplePrintf

    在设备代码中使用函数 printf(),没有新的认识。

    ▶ 源代码

     1 #include <stdio.h>
     2 #include <cuda_runtime.h>
     3 #include "device_launch_parameters.h"
     4 #include <helper_functions.h>
     5 #include <helper_cuda.h>
     6 
     7 __global__ void testKernel(int val)
     8 {
     9     printf("[%d, %d]:		Value is:%d
    ", blockIdx.y*gridDim.x + blockIdx.x, threadIdx.z*blockDim.x*blockDim.y + threadIdx.y*blockDim.x + threadIdx.x, val);
    10 }
    11 
    12 int main(int argc, char **argv)
    13 {
    14     int devID;
    15     cudaDeviceProp props;
    16     devID = findCudaDevice(argc, (const char **)argv);
    17     cudaGetDevice(&devID);
    18     cudaGetDeviceProperties(&props, devID);
    19     printf("Device %d: "%s" with Compute %d.%d capability
    ",devID, props.name, props.major, props.minor);
    20 
    21     dim3 dimGrid(2, 2);
    22     dim3 dimBlock(2, 2, 2);
    23     testKernel<<<dimGrid, dimBlock>>>(10);
    24     cudaDeviceSynchronize();
    25 
    26     getchar();
    27     return 0;
    28 }

    ▶ 输出结果

    GPU Device 0: "GeForce GTX 1070" with compute capability 6.1
    
    Device 0 : "GeForce GTX 1070" with Compute 6.1 capability
    [2, 0] : Value is : 10
    [2, 1] : Value is : 10
    [2, 2] : Value is : 10
    [2, 3] : Value is : 10
    [2, 4] : Value is : 10
    [2, 5] : Value is : 10
    [2, 6] : Value is : 10
    [2, 7] : Value is : 10
    [3, 0] : Value is : 10
    [3, 1] : Value is : 10
    [3, 2] : Value is : 10
    [3, 3] : Value is : 10
    [3, 4] : Value is : 10
    [3, 5] : Value is : 10
    [3, 6] : Value is : 10
    [3, 7] : Value is : 10
    [1, 0] : Value is : 10
    [1, 1] : Value is : 10
    [1, 2] : Value is : 10
    [1, 3] : Value is : 10
    [1, 4] : Value is : 10
    [1, 5] : Value is : 10
    [1, 6] : Value is : 10
    [1, 7] : Value is : 10
    [0, 0] : Value is : 10
    [0, 1] : Value is : 10
    [0, 2] : Value is : 10
    [0, 3] : Value is : 10
    [0, 4] : Value is : 10
    [0, 5] : Value is : 10
    [0, 6] : Value is : 10
    [0, 7] : Value is : 10
  • 相关阅读:
    MySQL锁
    mysql服务性能优化—my.cnf配置说明详解
    springmvc请求参数获取的几种方法
    Linux mysql 添加远程连接
    Linux 操作 mysql
    Linux 安装 mysql 转 http://www.cnblogs.com/fnlingnzb-learner/p/5830622.html
    linux 下 安装nginx
    dubbo 实战总结
    分布式事务的几种方式
    精巧好用的DelayQueue 转
  • 原文地址:https://www.cnblogs.com/cuancuancuanhao/p/7895340.html
Copyright © 2011-2022 走看看