1. 静态变量#include "error.cuh"#include __device__ int d_x = 1;__device__ int d_y[2];void __global__ my_kernel(void){d_y[0] += d_x;d_y[1] += d_x;printf("d_x = %d, d_y[0] = %d, d_y[1] = %d.\n", d_x, d_y[0], d_y[1]);}int main(void){int h_y[2] = {10, 20};CHECK(cudaMemcpyToSymbol(d_y, h_y, sizeof(int) * 2));my_kernel>>;CHECK(cudaDeviceSynchronize);CHECK(cudaMemcpyFromSymbol(h_y, d_y, sizeof(int) * 2));printf("h_y[0] = %d, h_y[1] = %d.\n", h_y[0], h_y[1]);return 0;}test@DELL-LGI597F5H5:~/cuda_test/CH5$ ./a.outd_x = 1, d_y[0] = 11, d_y[1] = 21.h_y[0] = 11, h_y[1] = 21.摘要:静态变量#include "error.cuh"#include __device__ int d_x = 1;__device__ int d_y[2];void __global__ my_kernel(void){d_y[0] +=
2. query.cu
#include "error.cuh"#include int main(int argc, char *argv){int device_id = 0;if (argc > 1) device_id = atoi(argv[1]);CHECK(cudaSetDevice(device_id));cudaDeviceProp prop;CHECK(cudaGetDeviceProperties(&prop, device_id));printf("Device id: %d\n",device_id);printf("Device name: %s\n",prop.name);printf("Compute capability: %d.%d\n",prop.major, prop.minor);printf("Amount of global memory: %g GB\n",prop.totalGlobalMem / (1024.0 * 1024 * 1024));printf("Amount of constant memory: %g KB\n",prop.totalConstMem / 1024.0);printf("Maximum grid size: %d %d %d\n",prop.maxGridSize[0], prop.maxGridSize[1], prop.maxGridSize[2]);printf("Maximum block size: %d %d %d\n",prop.maxThreadsDim[0], prop.maxThreadsDim[1], prop.maxThreadsDim[2]);printf("number of SMs: %d\n",prop.multiProcessorCount);printf("Maximum amount of shared memory per block: %g KB\n",prop.sharedMemPerBlock / 1024.0);printf("Maximum amount of shared memory per SM: %g KB\n",prop.sharedMemPerMultiprocessor / 1024.0);printf("Maximum number of registers per block: %d K\n",prop.regsPerBlock / 1024);printf("Maximum number of registers per SM: %d K\n",prop.regsPerMultiprocessor / 1024);printf("Maximum number of threads per block: %d\n",prop.maxThreadsPerBlock);printf("Maximum number of threads per SM: %d\n",prop.maxThreadsPerMultiProcessor);return 0;}test@DELL-LGI597F5H5:~/cuda_test/CH5$ nvcc -O3 query.cutest@DELL-LGI597F5H5:~/cuda_test/CH5$ ./a.outDevice id: 0Device name: NVIDIA RTX 500 Ada Generation Laptop GPUCompute capability: 8.9Amount of global memory: 3.99762 GBAmount of constant memory: 64 KBMaximum grid size: 2147483647 65535 65535Maximum block size: 1024 1024 64Number of SMs: 16Maximum amount of shared memory per block: 48 KBMaximum amount of shared memory per SM: 100 KBMaximum number of registers per block: 64 KMaximum number of registers per SM: 64 KMaximum number of threads per block: 1024Maximum number of threads per SM: 1536来源:未来探秘者
免责声明:本站系转载,并不代表本网赞同其观点和对其真实性负责。如涉及作品内容、版权和其它问题,请在30日内与本站联系,我们将在第一时间删除内容!