intmain(){//定义存储在主机上地变量和显卡上的变量int h_a[arraySize]={5,9,3,4,8};int h_b[arraySize];int* d_a,* d_b;//给变量分配显存cudaMalloc((void**)&d_b, arraySize *sizeof(int));cudaMalloc((void**)&d_a, arraySize *sizeof(int));//将变量值从主机复制到显卡// Copy input vector from host memory to GPU buffers.cudaMemcpy(d_a, h_a, arraySize *sizeof(int), cudaMemcpyHostToDevice);//核函数执行排序计算// Launch a kernel on the GPU with one thread for each element.
addKernel <<<arraySize / threadPerBlock, threadPerBlock >>>(d_a, d_b);//等待所有线程同步计算完成cudaDeviceSynchronize();//将变量值从显存复制到内存// Copy output vector from GPU buffer to host memory.cudaMemcpy(h_b, d_b, arraySize *sizeof(int), cudaMemcpyDeviceToHost);printf("The Enumeration sorted Array is: \n");for(int i =0; i < arraySize; i++){printf("%d\n", h_b[i]);}//释放显存cudaFree(d_a);cudaFree(d_b);return0;}
设置 DNS 访问 Git 需要修改电脑的 DNS 配置。下面是具体的操作流程:
第一步:打开命令提示符或终端窗口 在 Windows 系统中,可以按下 Win R 组合键,然后输入 “cmd”,按下 Enter 键打开命令提示符窗口。在 macOS 或 …