CUDA编程练习(一) 环境创建

1.1 安装nvcc4jupyter
建议找GitHub官方教程,更新太快了

!pip install nvcc4jupyter
%load_ext nvcc4jupyter

1.2 示例程序

%%cuda
#include <iostream>
int main(){
    std::cout << "Hello cuda!\n";
    return 0;
}

1.3 显卡使用情况

!nvidia-smi

1.4 显卡的各个参数

%%cuda
#include "cuda_runtime.h"
#include "device_launch_parameters.h"
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
    int deviceCount;
    cudaGetDeviceCount(&deviceCount);
    int dev;
    for (dev = 0; dev < deviceCount; dev++)  // 就一张显卡
    {
        cudaDeviceProp deviceProp;
        cudaGetDeviceProperties(&deviceProp, dev);
        if (dev == 0)
        {
            if (/*deviceProp.major==9999 && */deviceProp.minor = 9999&&deviceProp.major==9999)
                printf("\n");

        }
        printf("\nDevice%d:\"%s\"\n", dev, deviceProp.name);
        printf("Total amount of global memory                   %u bytes\n", deviceProp.totalGlobalMem);
        printf("Number of multiprocessors                        %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 thread per block:            %d\n", deviceProp.maxThreadsPerBlock);
        printf("Maximum sizes 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("\nTest PASSED\n");
    getchar();
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值