为什么z在CUDA内核中总是为零 [英] Why is z always zero in CUDA kernel

查看:161
本文介绍了为什么z在CUDA内核中总是为零的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Cudafy在NVIDIA GPU上进行一些计算. (如果需要的话,Quadro K1100M功能3.0)

I am using Cudafy to do some calculations on a NVIDIA GPU. (Quadro K1100M capability 3.0, if it matters)

我的问题是,当我使用以下内容

My question is, when I use the following

cudaGpu.Launch(new dim3(44,8,num), new dim(8, 8)).MyKernel...

为什么我在内核中使用GThread实例的z索引总是为零?

why are my z indexes from the GThread instance always zero when I use this in my kernel?

int z = thread.blockIdx.z * thread.blockDim.z + thread.threadIdx.z;

此外,如果我必须做类似的事情

Furthermore, if I have to do something like

cudaGpu.Launch(new dim3(44,8,num), new dim(8, 8, num)).MyKernel...

z确实提供了不同的索引,但是num不能很大,因为每个块的线程数受到限制.有关如何解决此问题的任何热忱?

z does give different indexes as it should, but num can't be very large because of the restrictions on number of threads per block. Any surgestion on how to work around this?

修改

另一种表达方式.当块大小仅为2D时,是否可以在内核中使用thread.z(有用的内容)?

Another way to phrase it. Can I use thread.z in my kernel (for anything useful) when block size is only 2D?

推荐答案

在当前支持的所有硬件上,CUDA允许同时使用三维网格和三维块.在计算能力1.x设备(不再受支持)上,网格被限制为二维.

On all currently supported hardware, CUDA allows the use of both three dimensional grids and three dimensional blocks. On compute capability 1.x devices (which are no longer supported), grids were restricted to two dimensions.

但是,CUDAfy当前使用已弃用的运行时API函数来启动内核,并且静默地仅使用gridDim.x和gridDim.y,而不考虑gridDim.z:

However, CUDAfy currently uses a deprecated runtime API function to launch kernels, and silently uses only gridDim.x and gridDim.y, not taking gridDim.z in account :

_cuda.Launch(function, gridSize.x, gridSize.y);

如在CudaGPU.cs中的函数DoLaunch() .

因此,尽管您可以在CUDAfy中指定三维网格,但在内核启动过程中将忽略第三维.感谢弗洛伦特指出这一点!

So while you can specify a three dimensional grid in CUDAfy, the third dimension is ignored during the kernel launch. Thanks to Florent for pointing this out !

这篇关于为什么z在CUDA内核中总是为零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆