VS2019+CUDA编程(流程)

本贴介绍一下CUDA编程的流程
1、打开VS,新建项目(空项目即可)
2、右键项目,生成依赖项,自定义
在这里插入图片描述

3、勾选CUDA

在这里插入图片描述

4、源文件中新建.cu文件,右键.cu文件,属性没常规,项类型,选中CUDA C/C++

在这里插入图片描述

5、添加属性表

在这里插入图片描述

其中,属性表由之前配置,保存,以后项目直接添加现有属性表即可。
属性表中内容为: 

 在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

此处内容,请参考其他博文内容,添加cuda的相关库文件,.lib文件等等。 

例程:

#include "cuda_runtime.h"

#include "device_launch_parameters.h"

#include <stdio.h>
#include <stdlib.h>


void main() {

    int deviceCount;

    cudaGetDeviceCount(&deviceCount);



    int dev;

    for (dev = 0; dev < deviceCount; dev++)

    {

        int driver_version(0), runtime_version(0);

        cudaDeviceProp deviceProp;

        cudaGetDeviceProperties(&deviceProp, dev);

        if (dev == 0)

            if (deviceProp.minor = 9999 && deviceProp.major == 9999)

                printf("\n");

        printf("\nDevice%d:\"%s\"\n", dev, deviceProp.name);

        cudaDriverGetVersion(&driver_version);

        printf("CUDA驱动版本:                                   %d.%d\n", driver_version / 1000, (driver_version % 1000) / 10);

        cudaRuntimeGetVersion(&runtime_version);

        printf("CUDA运行时版本:                                 %d.%d\n", runtime_version / 1000, (runtime_version % 1000) / 10);

        printf("设备计算能力:                                   %d.%d\n", deviceProp.major, deviceProp.minor);

        printf("Total amount of Global Memory:                  %u bytes\n", deviceProp.totalGlobalMem);

        printf("Number of SMs:                                  %d\n", deviceProp.multiProcessorCount);

        printf("Total amount of Constant Memory:                %u bytes\n", deviceProp.totalConstMem);

        printf("Total amount of Shared Memory per block:        %u bytes\n", deviceProp.sharedMemPerBlock);

        printf("Total number of registers available per block:  %d\n", deviceProp.regsPerBlock);

        printf("Warp size:                                      %d\n", deviceProp.warpSize);

        printf("Maximum number of threads per SM:               %d\n", deviceProp.maxThreadsPerMultiProcessor);

        printf("Maximum number of threads per block:            %d\n", deviceProp.maxThreadsPerBlock);

        printf("Maximum size of each dimension of a block:      %d x %d x %d\n", deviceProp.maxThreadsDim[0],

            deviceProp.maxThreadsDim[1],

            deviceProp.maxThreadsDim[2]);

        printf("Maximum size of each dimension of a grid:       %d x %d x %d\n", deviceProp.maxGridSize[0], deviceProp.maxGridSize[1], deviceProp.maxGridSize[2]);

        printf("Maximum memory pitch:                           %u bytes\n", deviceProp.memPitch);

        printf("Texture alignmemt:                              %u bytes\n", deviceProp.texturePitchAlignment);

        printf("Clock rate:                                     %.2f GHz\n", deviceProp.clockRate * 1e-6f);

        printf("Memory Clock rate:                              %.0f MHz\n", deviceProp.memoryClockRate * 1e-3f);

        printf("Memory Bus Width:                               %d-bit\n", deviceProp.memoryBusWidth);

    }
    system("pause");
    //return 0;

}

 在这里插入图片描述

VS2019+CUDA编程(流程)_vs2019 cuda_一叶孤舟渡的博客-CSDN博客

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值