PYCUDA设置NVCC参数

时间:2018-03-08 14:53:21

标签: python pycuda

如果我有任何小的pycuda代码,如下面的那个,我如何访问nvcc编译器的选项?例如,如果我想设置-maxrregcount 20(或任何其他参数),我将如何实现>

import pycuda.autoinit
import pycuda.driver as drv
import numpy

from pycuda.compiler import SourceModule
mod = SourceModule("""
__global__ void multiply_them(float *dest, float *a, float *b)
{
  const int i = threadIdx.x;
  dest[i] = a[i] * b[i];
}
""")

multiply_them = mod.get_function("multiply_them")

a = numpy.random.randn(400).astype(numpy.float32)
b = numpy.random.randn(400).astype(numpy.float32)

dest = numpy.zeros_like(a)
multiply_them(
        drv.Out(dest), drv.In(a), drv.In(b),
        block=(400,1,1), grid=(1,1))

print dest-a*b

1 个答案:

答案 0 :(得分:1)

我发现答案很简单我们需要做的就是添加下面的代码..

mod = SourceModule("""
__global__ void multiply_them(float *dest, float *a, float *b)
{
  const int i = threadIdx.x;
  dest[i] = a[i] * b[i];
}
""",options=['--maxrregcount=20'])