前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >DAY46:阅读Surface Reference API

DAY46:阅读Surface Reference API

作者头像
GPUS Lady
发布2018-08-01 14:51:30
9830
发布2018-08-01 14:51:30
举报
文章被收录于专栏:GPUS开发者GPUS开发者
我们正带领大家开始阅读英文的《CUDA C Programming Guide》,今天是第46天,我们正在讲解CUDA C语法,希望在接下来的54天里,您可以学习到原汁原味的CUDA,同时能养成英文阅读的习惯。

B.9.2. Surface Reference API

B.9.2.1. surf1Dread()

reads the CUDA array bound to the one-dimensional surface reference surfRef using coordinate x.

B.9.2.2. surf1Dwrite

writes value data to the CUDA array bound to the one-dimensional surface reference surfRef at coordinate x.

B.9.2.3. surf2Dread()

reads the CUDA array bound to the two-dimensional surface reference surfRef using coordinates x and y.

B.9.2.4. surf2Dwrite()

writes value data to the CUDA array bound to the two-dimensional surface reference surfRef at coordinate x and y.

B.9.2.5. surf3Dread()

reads the CUDA array bound to the three-dimensional surface reference surfRef using coordinates x, y, and z.

B.9.2.6. surf3Dwrite()

writes value data to the CUDA array bound to the three-dimensional surface reference surfRef at coordinate x, y, and z.

B.9.2.7. surf1DLayeredread()

reads the CUDA array bound to the one-dimensional layered surface reference surfRef using coordinate x and index layer.

B.9.2.8. surf1DLayeredwrite()

writes value data to the CUDA array bound to the two-dimensional layered surface reference surfRef at coordinate x and index layer.

B.9.2.9. surf2DLayeredread()

reads the CUDA array bound to the two-dimensional layered surface reference surfRef using coordinate x and y, and index layer.

B.9.2.10. surf2DLayeredwrite()

writes value data to the CUDA array bound to the one-dimensional layered surface reference surfRef at coordinate x and y, and index layer.

B.9.2.11. surfCubemapread()

reads the CUDA array bound to the cubemap surface reference surfRef using coordinate x and y, and face index face.

B.9.2.12. surfCubemapwrite()

writes value data to the CUDA array bound to the cubemap reference surfRef at coordinate x and y, and face index face.

B.9.2.13. surfCubemapLayeredread()

reads the CUDA array bound to the cubemap layered surface reference surfRef using coordinate x and y, and index layerFace.

B.9.2.14. surfCubemapLayeredwrite()

writes value data to the CUDA array bound to the cubemap layered reference surfRef at coordinate x and y, and index layerFace.

本文备注/经验分享:

surface也像texture那样, 分为surface reference和object(DAY45:阅读Surface Object API), 但是surface不同的是, surface reference出现的晚, 是在2.0时期才出来的,也就是Fermi(还记得它么) ,跟随当时的CUDA 3.2这个版本一样.这个版本的CUDA引入了v2版本的api, 很多函数发生了变化.相当大致今天的CUDA 9的样子. 而CUDA 3.2之前, CUDA 3.2 - 9.0, cuda9+,基本上可以看成3段会引发程序兼容性问题的3个大阶段. 主要注意一下.中间的很久是基本上很平稳的过渡(3.2到9.0), 但是很快surface reference出来后不久, 到了3.0的Kepler时代, 就开始有了Surface Object了。两者主要是使用方便性上的变化对用户来说. 基本一样的. 和texture对比, Surface主要贡献了两点作用: (1) surface的后备存储的cuda array, 是可以写入的, 这解决了长期以来, 使用cuda array做为后备存储, 需要更新内容时候带来的, 必须走host进行cudaMemcpy*的繁琐.现在kernel直接通过surface在device上进行细粒度的内容改写了. (2) 做为一个简化版本的texture使用,很多人需要使用texture的cache性能(例如在配合cuda array的时候, 利用内部特殊的元素排列取得的空间上的效果), 而不需要复杂的采样器功能(例如线性插值之类的),此时可以直接使用surface.所以本章节你看到了很多函数的有很多细微的和texture的不同.例如边界模式上, 可以直接在调用的时候做为最后一个参数指定.例如这里的越界读取返回0的模式.请注意这里因为是surface, 还可以写入,所以还多了对此模式的越界写入的时候将被自动忽略的说明(texture不能写入)。 虽然本章节很长, 但大部分的内容都和texture类似.阅读的人看到函数说明后, 应当毫无压力的理解.但有几个地方需要说明: (1)surface的坐标采用字节单位, 而texture使用元素单位.精确的说, 只有第一个坐标(x坐标这样),用户往往需要进行元素和字节上的单位变换, 往往可以直接通过sizeof(元素)这个系数的乘法. 基本上surface没啥可说的. 一样的.注意单位(x方向)是字节, 特别要改写使用常规坐标(非归一化坐标)的texture代码的时候. 其他好像没啥可说了. (2)更新了Surface后, 如果还要有读取(包括surface或者使用了同一后备的cuda array的texture), 必须下个kernel生效.直接在本kernel内部读取将导致未定义的结果. (3)这同样对使用了普通线性内存(显存)的texture有用.没有surface之前, 很多人选择使用普通后备存储的texture, 然后用普通指针进行写入改写.此时也依然需要下次启动kernel生效.因为下次kernel启动的时候,将自动进行清理texture cache, L1 cache之类的操作.能确保安全.

有不明白的地方,请在本文后留言

或者在我们的技术论坛bbs.gpuworld.cn上发帖

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2018-07-11,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 GPUS开发者 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • B.9.2. Surface Reference API
  • B.9.2.1. surf1Dread()
  • B.9.2.2. surf1Dwrite
  • B.9.2.3. surf2Dread()
  • B.9.2.4. surf2Dwrite()
  • B.9.2.5. surf3Dread()
  • B.9.2.6. surf3Dwrite()
  • B.9.2.7. surf1DLayeredread()
  • B.9.2.8. surf1DLayeredwrite()
  • B.9.2.9. surf2DLayeredread()
  • B.9.2.10. surf2DLayeredwrite()
  • B.9.2.11. surfCubemapread()
  • B.9.2.12. surfCubemapwrite()
  • B.9.2.13. surfCubemapLayeredread()
  • B.9.2.14. surfCubemapLayeredwrite()
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档