如何学习cuda c?
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何学习cuda c?相关的知识,希望对你有一定的参考价值。
1、 CUDA C编写Windows Console Application
下面我们从一个简单的例子开始学习CUDA C。
打开VS,新建一个CUDAWinApp项目,项目名称为Vector,解决方案名称为CUDADemo。依次点击“确定”,“下一步”,选择Empty project。点击“Finished”。这样一个CUDA的项目就建成了。
右键点击Vector项目,依次选择“添加”、“新建项”、“代码”、“CUDA”。在名称中输入要添加的文件名。如Vector.cu。然后点击添加。
下面在Vector.cu文件里实现两个向量相加的程序。
//添加系统库
#include
#include
//添加CUDA支持
#include
__global__ void VecAdd(float *A, float *B, float *C);
__host__ void runVecAdd(int argc, char **argv);
int main(int argc, char **argv)
runVecAdd(argc,argv);
CUT_EXIT(argc,argv);
__host__ void runVecAdd(int argc,char **argv)
//初始化host端内存数据
const unsigned int N = 8;//向量维数
const unsigned int memSize = sizeof(float)*N;//需要空间的字节数
float *h_A = (float*)malloc(memSize);
float *h_B = (float*)malloc(memSize);
float *h_C = (float*)malloc(memSize);
for (unsigned int i = 0; i < N; i++)
h_A[i] = i;h_B[i] = i;
//设备端显存空间
float *d_A, *d_B, *d_C;
//初始化Device
CUT_DEVICE_INIT(argc,argv);
CUDA_SAFE_CALL(cudaMalloc((void**)&d_A, memSize));
CUDA_SAFE_CALL(cudaMalloc((void**)&d_B, memSize));
CUDA_SAFE_CALL(cudaMalloc((void**)&d_C, memSize));
CUDA_SAFE_CALL(cudaMemcpy(d_A, h_A, memSize, cudaMemcpyHostToDevice));
CUDA_SAFE_CALL(cudaMemcpy(d_B, h_B, memSize, cudaMemcpyHostToDevice));
VecAdd<<<1,N,memSize>>>(d_A, d_B, d_C);
CUT_CHECK_ERROR("Kernel execution failed");
CUDA_SAFE_CALL(cudaMemcpy(h_C, d_C, memSize, cudaMemcpyDeviceToHost));
for (unsigned int i = 0; i < N; i++)
printf("%.0f ",h_C[i]);
free(h_A);free(h_B);free(h_C);
CUDA_SAFE_CALL(cudaFree(d_A));
CUDA_SAFE_CALL(cudaFree(d_B));
CUDA_SAFE_CALL(cudaFree(d_C));
__global__ void VecAdd(float *A, float *B, float *C)
//分配shared memory
extern __shared__ float s_A[];
extern __shared__ float s_B[];
extern __shared__ float s_C[];
//从global memory拷贝到shared memory
const unsigned int i = threadIdx.x;
s_A[i] = A[i];
s_B[i] = B[i];
//计算
s_C[i] = s_A[i] + s_B[i];
//拷贝到global memory
C[i] = s_C[i];
由于这里不是讲CUDA编程的,关于它的编程模型已经超出了我要介绍的范围,您可以阅读《GPU高性能运算之CUDA》来获得CUDA编程模型的知识。
编译Vector项目,执行此项目后会得到图1如下输出:
图1 Vector项目执行结果
2、CUDA C编写DLL模块
更多情况下的您的软件可能只是使用CUDA来实现一段程序的加速,这种情况下我们可以使用CUDA C 编写DLL来提供接口。下面我们就将例1编译成DLL。
在刚才的CUDADemo解决方案目录下添加一个新的CUDA项目(当然您也可以重新建立一个解决方案)。项目名为VecAdd_dynamic。Application Type选为DLL,Additional Options选择Empty Project。
第一步,添加头文件,文件名最好与工程名同名,这样便于您的维护工作。这里我向项目中添加了VecAdd_dynamic.h,在此头文件中添加如下代码
#ifndef _VECADD_DYNAMIC_H_
#define _VECADD_DYNAMIC_H_
//并行计算N维向量的加法
__declspec(dllexport) void VecAdd(float* h_A, float* h_B, float* h_C, int N);
#endif
第二步,添加cpp文件,文件名为VecAdd_dynamic.cpp,在此文件中添加如下代码
#include
#include "VecAdd_dynamic.h"
#ifdef _MANAGED
#pragma managed(push, off)
#endif
BOOL APIENTRY DllMain(HMODULE hModule,DWORD ul_reason_for_call,LPVOID lpReserved)
return TRUE;
#ifdef _MANAGED
#pragma managed(pop)
#endif
第三步,添加def文件,此文件的功能就是确保其它厂商的编译器能够调用此DLL里的函数。这一点非常关键,因为您的程序可能用到多个厂家的编译器。文件名为VecAdd_dynamic.def。向该文件中添加:
EXPORTS
VecAdd
第四步,添加cu文件,文件名为VecAdd_dynamic.cu。注意此文件最好直接添加到项目目录下,不要添加到源文件选项卡或其它已有的选项卡下。
在cu文件里添加如下代码,实现要导出的函数。
#include
#include
#include
#if __DEVICE_EMULATION__
bool InitCUDA(void)
return true;
#else
bool InitCUDA(void)
int count = 0;
int i = 0;
cudaGetDeviceCount(&count);
if(count == 0)
fprintf(stderr, "There is no device./n");
return false;
for(i = 0; i < count; i++)
cudaDeviceProp prop;
if(cudaGetDeviceProperties(&prop, i) == cudaSuccess)
if(prop.major >= 1)
break;
if(i == count)
fprintf(stderr, "There is no device supporting CUDA./n");
return false;
cudaSetDevice(i);
printf("CUDA initialized./n");
return true;
#endif
__global__ void D_VecAdd(float *g_A, float *g_B, float *g_C, int N)
unsigned int i = threadIdx.x;
if (i < N)
g_C[i] = g_A[i] + g_B[i];
void VecAdd(float* h_A, float* h_B, float* h_C, int N)
if(!InitCUDA())
return;
float *g_A, *g_B, *g_C;
unsigned int size = N * sizeof(float);
CUDA_SAFE_CALL(cudaMalloc((void**)&g_A, size));
CUDA_SAFE_CALL(cudaMalloc((void**)&g_B, size));
CUDA_SAFE_CALL(cudaMalloc((void**)&g_C, size));
CUDA_SAFE_CALL(cudaMemcpy(g_A, h_A, size, cudaMemcpyHostToDevice));
CUDA_SAFE_CALL(cudaMemcpy(g_B, h_B, size, cudaMemcpyHostToDevice));
D_VecAdd<<<1,N>>>(g_A, g_B, g_C, N);
CUDA_SAFE_CALL(cudaMemcpy(h_C, g_C, size, cudaMemcpyDeviceToHost));
cudaFree(g_A);cudaFree(g_B);cudaFree(g_C);
第五步,如果您已经正确完成了以上四步,那么剩下的就只有编译,只要您用过VS,这一步就不需要我介绍了吧。成功之后,在您的解决方案文件目录下的Debug文件夹下会有一个VecAdd_dynamic.dll文件。
3、 在 .NET 中使用CUDA C编写的DLL
下面介绍在托管程序中如何使用VecAdd_dynamic.dll。
第一步,在上面的解决方案CUDADemo下添加一个C++/CLR的Windows窗体应用程序,工程名为NETDemo(当然您也可以重新建一个解决方案,工程名也是随意的)。
第二步,在窗体上添加一个按钮,名字随意,我将它的现实文本改为“调用CUDA_DLL”,给这个按钮添加click事件。我们的代码将在这个事件里添加调用VecAdd()的程序。在窗体上添加一个文本框用来显示调用输出的结果。
第三步,代码实现。为工程NETDemo添加一个头文件,我将它命名为Win32.h,这个文件中主要是实现VecAdd()函数的导入。在此文件中添加如下代码
#pragma once
namespace Win32
using namespace System::Runtime::InteropServices;
[DllImport("VecAdd_dynamic.dll",EntryPoint="VecAdd",CharSet=CharSet::Auto)]
extern "C" void VecAdd(float* h_A, float* h_B, float* h_C, int N);
在Form1.h中,#pragma once 之后 namespace NETDemo 之前添加以下代码。
#include "Win32.h"
#include
在button1_Click()中添加如下代码
int N = 8;
float* h_A = (float*)malloc(N*sizeof(float));
float* h_B = (float*)malloc(N*sizeof(float));
float* h_C = (float*)malloc(N*sizeof(float));
for (int i = 0; i < N; i++)
h_A[i] = i;h_B[i] = i;
Win32::VecAdd(h_A, h_B, h_C,N);
String ^reslut;
for (int i = 0; i < N; i++)
reslut += Convert::ToString(h_C[i]) + ", ";
this->textBox1->Text = Convert::ToString(reslut);
free(h_A);free(h_B);free(h_C);
第四步、执行NETDemo项目。点击“调用CUDA_DLL”,您会看到图3所示的结果
图3 NETDemo运行结果
到现在为止您已经完全可以正确使用CUDA了。
参考技术A 加班加点;努力就是了哦 参考技术B 推荐你看GPU高性能编程 CUDA实战,如果英文够好的话可以看cuda的官方文档 参考技术C 什么、、 是大法官法规的法规法规的风格十分广泛的施工方的高峰会感觉一天又突然飞哥哥和他还让他也挺CUDA C Programming Guide 在线教程学习笔记 Part 6
? 纹理内存读取函数
1 /****************************************************************/ 2 3 // Texture Object API 4 5 /****************************************************************/ 6 7 template<class T> 8 T tex1Dfetch(cudaTextureObject_t texObj, int x); 9 // 一维纹理,整数下标。只用于非正规化坐标,挤压模式或边界模式,不能滤波 10 11 template<class T> 12 T tex1D(cudaTextureObject_t texObj, float x); 13 // 一维纹理,浮点数下标 14 15 template<class T> 16 T tex1DLod(cudaTextureObject_t texObj, float x, float level); 17 // 一维纹理,基于 level-of-detail(层次细节)算法 18 19 template<class T> 20 T tex1DGrad(cudaTextureObject_t texObj, float x, float dx, float dy); 21 // 一维纹理,基于 gradients(梯度)算法 22 23 template<class T> 24 T tex2D(cudaTextureObject_t texObj, float x, float y); 25 // 二维纹理 26 27 template<class T> 28 tex2DLod(cudaTextureObject_t texObj, float x, float y, float level); 29 // 二维纹理,基于 level-of-detail(层次细节)算法 30 31 template<class T> 32 T tex2DGrad(cudaTextureObject_t texObj, float x, float y,float2 dx, float2 dy); 33 // 二维纹理,基于 gradients(梯度)算法 34 35 template<class T> 36 T tex3D(cudaTextureObject_t texObj, float x, float y, float z); 37 // 三维纹理 38 39 template<class T> 40 T tex3DLod(cudaTextureObject_t texObj, float x, float y, float z, float level); 41 // 三维纹理,基于 level-of-detail(层次细节)算法 42 43 template<class T> 44 T tex3DGrad(cudaTextureObject_t texObj, float x, float y, float z,float4 dx, float4 dy); 45 // 三维纹理,基于 gradients(梯度)算法 46 47 template<class T> 48 T tex1DLayered(cudaTextureObject_t texObj, float x, int layer); 49 // 一维分层纹理 50 51 template<class T> 52 T tex1DLayeredLod(cudaTextureObject_t texObj, float x, int layer, float level); 53 // 一维分层纹理,基于 level-of-detail(层次细节)算法 54 55 template<class T> 56 T tex1DLayeredGrad(cudaTextureObject_t texObj, float x, int layer, float dx, float dy); 57 // 一维分层纹理,基于 gradients(梯度)算法 58 59 template<class T> 60 T tex2DLayered(cudaTextureObject_t texObj, float x, float y, int layer); 61 // 二维分层纹理 62 63 template<class T> 64 T tex2DLayeredLod(cudaTextureObject_t texObj, float x, float y, int layer, float level); 65 // 二维分层纹理,基于 level-of-detail(层次细节)算法 66 67 template<class T> 68 T tex2DLayeredGrad(cudaTextureObject_t texObj, float x, float y, int layer, float2 dx, float2 dy); 69 // 二维分层纹理,基于 gradients(梯度)算法 70 71 template<class T> 72 T texCubemap(cudaTextureObject_t texObj, float x, float y, float z); 73 // 立方体贴图纹理 74 75 template<class T> 76 T texCubemapLod(cudaTextureObject_t texObj, float x, float, y, float z, float level); 77 // 立方体贴图纹理,基于 level-of-detail(层次细节)算法 78 79 template<class T> 80 T texCubemapLayered(cudaTextureObject_t texObj, float x, float y, float z, int layer); 81 // 立方体分层贴图纹理 82 83 template<class T> 84 T texCubemapLayeredLod(cudaTextureObject_t texObj, float x, float y, float z, int layer, float level); 85 // 立方分层体贴图纹理,基于 level-of-detail(层次细节)算法 86 87 template<class T> 88 T tex2Dgather(cudaTextureObject_t texObj, float x, float y, int comp = 0); 89 // ? 90 91 /****************************************************************/ 92 93 // Texture Object API 94 95 /****************************************************************/ 96 97 template<class DataType> 98 Type tex1Dfetch(texture<DataType, cudaTextureType1D, cudaReadModeElementType> texRef, int x); 99 100 float tex1Dfetch(texture<unsigned char, cudaTextureType1D, cudaReadModeNormalizedFloat> texRef, int x); 101 float tex1Dfetch(texture<signed char, cudaTextureType1D, cudaReadModeNormalizedFloat> texRef, int x); 102 float tex1Dfetch(texture<unsigned short, cudaTextureType1D, cudaReadModeNormalizedFloat> texRef, int x); 103 float tex1Dfetch(texture<signed short, cudaTextureType1D, cudaReadModeNormalizedFloat> texRef, int x); 104 // 一维纹理,整数下标。只用于非正规化坐标,挤压模式或边界模式,不能滤波 105 106 // 2元组,4元组也可以使用这种方法,例如: 107 float4 tex1Dfetch(texture<uchar2, cudaTextureType1D, cudaReadModeNormalizedFloat> texRef, int x); 108 float4 tex1Dfetch(texture<uchar4, cudaTextureType1D, cudaReadModeNormalizedFloat> texRef, int x); 109 110 // 其他函数名类似 Texture Object API 111 template<class DataType, enum cudaTextureReadMode readMode> 112 Type tex1D(texture<DataType, cudaTextureType1D, readMode> texRef, float x); 113 114 template<class DataType, enum cudaTextureReadMode readMode> 115 Type tex1DLod(texture<DataType, cudaTextureType1D, readMode> texRef, float x, float level); 116 117 template<class DataType, enum cudaTextureReadMode readMode> 118 Type tex1DGrad(texture<DataType, cudaTextureType1D, readMode> texRef, float x, float dx, float dy); 119 120 template<class DataType, enum cudaTextureReadMode readMode> 121 Type tex2D(texture<DataType, cudaTextureType2D, readMode> texRef,float x, float y); 122 123 template<class DataType, enum cudaTextureReadMode readMode> 124 Type tex2DLod(texture<DataType, cudaTextureType2D, readMode> texRef, float x, float y, float level); 125 126 template<class DataType, enum cudaTextureReadMode readMode> 127 Type tex2DGrad(texture<DataType, cudaTextureType2D, readMode> texRef, float x, float y, float2 dx, float2 dy); 128 129 template<class DataType, enum cudaTextureReadMode readMode> 130 Type tex3D(texture<DataType, cudaTextureType3D, readMode> texRef, float x, float y, float z); 131 132 template<class DataType, enum cudaTextureReadMode readMode> 133 Type tex3DLod(texture<DataType, cudaTextureType3D, readMode> texRef, float x, float y, float z, float level); 134 135 template<class DataType, enum cudaTextureReadMode readMode> 136 Type tex3DGrad(texture<DataType, cudaTextureType3D, readMode> texRef, float x, float y, float z, float4 dx, float4 dy); 137 138 template<class DataType, enum cudaTextureReadMode readMode> 139 Type tex1DLayered(texture<DataType, cudaTextureType1DLayered, readMode> texRef, float x, int layer); 140 141 template<class DataType, enum cudaTextureReadMode readMode> 142 Type tex1DLayeredLod(texture<DataType, cudaTextureType1D, readMode> texRef, float x, int layer, float level); 143 144 template<class DataType, enum cudaTextureReadMode readMode> 145 Type tex1DLayeredGrad(texture<DataType, cudaTextureType1D, readMode> texRef, float x, int layer, float dx, float dy); 146 147 template<class DataType, enum cudaTextureReadMode readMode> 148 Type tex2DLayered(texture<DataType, cudaTextureType2DLayered, readMode> texRef, float x, float y, int layer); 149 150 template<class DataType, enum cudaTextureReadMode readMode> 151 Type tex2DLayeredLod(texture<DataType, cudaTextureType2D, readMode> texRef, float x, float y, int layer, float level); 152 153 template<class DataType, enum cudaTextureReadMode readMode> 154 Type tex2DLayeredGrad(texture<DataType, cudaTextureType2D, readMode> texRef, float x, float y, int layer, float2 dx, float2 dy); 155 156 template<class DataType, enum cudaTextureReadMode readMode> 157 Type texCubemap(texture<DataType, cudaTextureTypeCubemap, readMode> texRef, float x, float y, float z); 158 159 template<class DataType, enum cudaTextureReadMode readMode> 160 Type texCubemapLod(texture<DataType, cudaTextureType3D, readMode> texRef, float x, float y, float z, float level); 161 162 template<class DataType, enum cudaTextureReadMode readMode> 163 Type texCubemapLayered(texture<DataType, cudaTextureTypeCubemapLayered, readMode> texRef, float x, float y, float z, int layer); 164 165 template<class DataType, enum cudaTextureReadMode readMode> 166 Type texCubemapLayeredLod(texture<DataType, cudaTextureType3D, readMode> texRef, float x, float y, float z, int layer, float level); 167 168 template<class DataType, enum cudaTextureReadMode readMode> 169 Type tex2Dgather(texture<DataType, cudaTextureType2D, readMode> texRef, float x, float y, int comp = 0);
? 表面内存读写函数
1 /****************************************************************/ 2 3 // Surface Object API 4 5 /****************************************************************/ 6 7 template<class T> 8 T surf1Dread(cudaSurfaceObject_t surfObj, int x, boundaryMode = cudaBoundaryModeTrap); 9 // 一维表面读取 10 11 template<class T> 12 void surf1Dwrite(T data, cudaSurfaceObject_t surfObj, int x, boundaryMode = cudaBoundaryModeTrap); 13 // 一维表面写入 14 15 template<class T> 16 T surf2Dread(cudaSurfaceObject_t surfObj, int x, int y, boundaryMode = cudaBoundaryModeTrap); 17 // 二维表面读取 18 template<class T> 19 void surf2Dread(T* data, cudaSurfaceObject_t surfObj, int x, int y, boundaryMode = cudaBoundaryModeTrap); 20 // 二维表面读取 21 22 template<class T> 23 void surf2Dwrite(T data, cudaSurfaceObject_t surfObj, int x, int y, boundaryMode = cudaBoundaryModeTrap); 24 // 二维表面写入 25 26 template<class T> 27 T surf3Dread(cudaSurfaceObject_t surfObj, int x, int y, int z, boundaryMode = cudaBoundaryModeTrap); 28 // 三维表面读取 29 30 template<class T> 31 void surf3Dread(T* data, cudaSurfaceObject_t surfObj, int x, int y, int z, boundaryMode = cudaBoundaryModeTrap); 32 // 三维表面读取 33 34 template<class T> 35 void surf3Dwrite(T data, cudaSurfaceObject_t surfObj, int x, int y, int z, boundaryMode = cudaBoundaryModeTrap); 36 // 三维表面写入 37 38 template<class T> 39 T surf1DLayeredread(cudaSurfaceObject_t surfObj, int x, int layer, boundaryMode = cudaBoundaryModeTrap); 40 // 一维分层表面读取 41 42 template<class T> 43 void surf1DLayeredread(T data, cudaSurfaceObject_t surfObj, int x, int layer, boundaryMode = cudaBoundaryModeTrap); 44 // 一维分层表面读取 45 46 template<class Type> 47 void surf1DLayeredwrite(T data, cudaSurfaceObject_t surfObj, int x, int layer, boundaryMode = cudaBoundaryModeTrap); 48 // 一维分层表面写入 49 50 template<class T> 51 T surf2DLayeredread(cudaSurfaceObject_t surfObj, int x, int y, int layer, boundaryMode = cudaBoundaryModeTrap); 52 // 二维分层表面读取 53 54 template<class T> 55 void surf2DLayeredread(T data, cudaSurfaceObject_t surfObj, int x, int y, int layer, boundaryMode = cudaBoundaryModeTrap); 56 // 二维分层表面读取 57 template<class T> 58 void surf2DLayeredwrite(T data, cudaSurfaceObject_t surfObj, int x, int y, int layer, boundaryMode = cudaBoundaryModeTrap); 59 // 二维分层表面写入 60 61 template<class T> 62 T surfCubemapread(cudaSurfaceObject_t surfObj, int x, int y, int face, boundaryMode = cudaBoundaryModeTrap); 63 // 立方体贴图表面读取 64 65 template<class T> 66 void surfCubemapread(T data, cudaSurfaceObject_t surfObj, int x, int y, int face, boundaryMode = cudaBoundaryModeTrap); 67 // 立方体贴图表面读取 68 69 template<class T> 70 void surfCubemapwrite(T data, cudaSurfaceObject_t surfObj, int x, int y, int face, boundaryMode = cudaBoundaryModeTrap); 71 // 立方体贴图表面写入 72 73 template<class T> 74 T surfCubemapLayeredread(cudaSurfaceObject_t surfObj, int x, int y, int layerFace, boundaryMode = cudaBoundaryModeTrap); 75 // 立方体分层贴图表面读取 76 77 template<class T> 78 void surfCubemapLayeredread(T data, cudaSurfaceObject_t surfObj, int x, int y, int layerFace, boundaryMode = cudaBoundaryModeTrap); 79 // 立方体分层贴图表面读取 80 81 template<class T> 82 void surfCubemapLayeredwrite(T data, cudaSurfaceObject_t surfObj, int x, int y, int layerFace, boundaryMode = cudaBoundaryModeTrap); 83 // 立方体分层贴图表面写入 84 85 /****************************************************************/ 86 87 // Surface Refernence API 88 89 /****************************************************************/ 90 91 // 函数名类似 Texture Object API 92 template<class Type> 93 Type surf1Dread(surface<void, cudaSurfaceType1D> surfRef, int x, boundaryMode = cudaBoundaryModeTrap); 94 95 template<class Type> 96 void surf1Dread(Type data, surface<void, cudaSurfaceType1D> surfRef, int x, boundaryMode = cudaBoundaryModeTrap); 97 98 template<class Type> 99 void surf1Dwrite(Type data, surface<void, cudaSurfaceType1D> surfRef, int x, boundaryMode = cudaBoundaryModeTrap); 100 101 template<class Type> 102 Type surf2Dread(surface<void, cudaSurfaceType2D> surfRef, int x, int y, boundaryMode = cudaBoundaryModeTrap); 103 104 template<class Type> 105 void surf2Dread(Type* data, surface<void, cudaSurfaceType2D> surfRef, int x, int y, boundaryMode = cudaBoundaryModeTrap); 106 107 template<class Type> 108 void surf3Dwrite(Type data, surface<void, cudaSurfaceType3D> surfRef, int x, int y, int z, boundaryMode = cudaBoundaryModeTrap); 109 110 template<class Type> 111 Type surf3Dread(surface<void, cudaSurfaceType3D> surfRef, int x, int y, int z, boundaryMode = cudaBoundaryModeTrap); 112 113 template<class Type> 114 void surf3Dread(Type* data, surface<void, cudaSurfaceType3D> surfRef, int x, int y, int z, boundaryMode = cudaBoundaryModeTrap); 115 116 template<class Type> 117 void surf3Dwrite(Type data, surface<void, cudaSurfaceType3D> surfRef, int x, int y, int z, boundaryMode = cudaBoundaryModeTrap); 118 119 template<class Type> 120 Type surf1DLayeredread(surface<void, cudaSurfaceType1DLayered> surfRef, int x, int layer, boundaryMode = cudaBoundaryModeTrap); 121 122 template<class Type> 123 void surf1DLayeredread(Type data, surface<void, cudaSurfaceType1DLayered> surfRef, int x, int layer, boundaryMode = cudaBoundaryModeTrap); 124 125 template<class Type> 126 void surf1DLayeredwrite(Type data, surface<void, cudaSurfaceType1DLayered> surfRef, int x, int layer, boundaryMode = cudaBoundaryModeTrap); 127 128 template<class Type> 129 Type surf2DLayeredread(surface<void, cudaSurfaceType2DLayered> surfRef, int x, int y, int layer, boundaryMode = cudaBoundaryModeTrap); 130 131 template<class Type> 132 void surf2DLayeredread(Type data, surface<void, cudaSurfaceType2DLayered> surfRef, int x, int y, int layer, boundaryMode = cudaBoundaryModeTrap); 133 134 template<class Type> 135 void surf2DLayeredwrite(Type data, surface<void, cudaSurfaceType2DLayered> surfRef, int x, int y, int layer, boundaryMode = cudaBoundaryModeTrap); 136 137 template<class Type> 138 Type surfCubemapread(surface<void, cudaSurfaceTypeCubemap> surfRef, int x, int y, int face, boundaryMode = cudaBoundaryModeTrap); 139 140 template<class Type> 141 void surfCubemapread(Type data, surface<void, cudaSurfaceTypeCubemap> surfRef, int x, int y, int face, boundaryMode = cudaBoundaryModeTrap); 142 143 template<class Type> 144 void surfCubemapwrite(Type data, surface<void, cudaSurfaceTypeCubemap> surfRef, int x, int y, int face, boundaryMode = cudaBoundaryModeTrap); 145 146 template<class Type> 147 Type surfCubemapLayeredread(surface<void, cudaSurfaceTypeCubemapLayered> surfRef, int x, int y, int layerFace, boundaryMode = cudaBoundaryModeTrap); 148 149 template<class Type> 150 void surfCubemapLayeredread(Type data, surface<void, cudaSurfaceTypeCubemapLayered> surfRef, int x, int y, int layerFace, boundaryMode = cudaBoundaryModeTrap); 151 152 template<class Type> 153 void surfCubemapLayeredwrite(Type data, surface<void, cudaSurfaceTypeCubemapLayered> surfRef, int x, int y, int layerFace, boundaryMode = cudaBoundaryModeTrap);
以上是关于如何学习cuda c?的主要内容,如果未能解决你的问题,请参考以下文章