Installation
- Install cuda toolkit
- Instal visual studio C++ development environment
- Create CUDA Runtime project
Compiler Error
If you get an error with default code, probably your device compute capability is incompatible with current selected one.
Hello CUDA
#include "cuda_runtime.h"
//#include "device_launch_parameters.h"
#include <stdio.h>
__global__ void helloKernel(){
printf("Hello CUDA\n");
}
int main(){
helloKernel << <16, 1 >> > ();
}
Query Device Properties
#include "cuda_runtime.h"
#include "device_launch_parameters.h"
#include <stdio.h>
int main() {
int nDevices;
cudaGetDeviceCount(&nDevices);
for (int i = 0; i < nDevices; i++) {
cudaDeviceProp prop;
cudaGetDeviceProperties(&prop, i);
printf("Device Number: %d\n", i);
printf(" Device name: %s\n", prop.name);
printf(" Memory Clock Rate (KHz): %d\n",
prop.memoryClockRate);
printf(" Memory Bus Width (bits): %d\n",
prop.memoryBusWidth);
printf(" Peak Memory Bandwidth (GB/s): %f\n\n",
2.0 * prop.memoryClockRate * (prop.memoryBusWidth / 8) / 1.0e6);
}
}
Device Number: 0
Device name: NVIDIA GeForce GTX 950M
Memory Clock Rate (KHz): 1001000
Memory Bus Width (bits): 128
Peak Memory Bandwidth (GB/s): 32.032000
https://developer.nvidia.com/blog/how-query-device-properties-and-handle-errors-cuda-cc/
Leave a Reply