1
votes

I am currently trying to use PyCUDA on Debian 9. I already manage to make cuda work, and if I run:

nvcc -ccbin clang-3.8 file.cu

I compile the file correctly and I am able to run it.

However, after I intalled pycuda using

apt-get install python-pycuda

And run a simple example from their website:

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

But I receive the following error:

CompileError                              Traceback (most recent call last)
<ipython-input-1-8e16128de7f2> in <module>()
     10   dest[i] = a[i] * b[i];
     11 }
---> 12 """)
     13 
     14 multiply_them = mod.get_function("multiply_them")

/usr/lib/python2.7/dist-packages/pycuda/compiler.pyc in __init__(self, source, nvcc, options, keep, no_extern_c, arch, code, cache_dir, include_dirs)
    263 
    264         cubin = compile(source, nvcc, options, keep, no_extern_c,
--> 265                 arch, code, cache_dir, include_dirs)
    266 
    267         from pycuda.driver import module_from_buffer

/usr/lib/python2.7/dist-packages/pycuda/compiler.pyc in compile(source, nvcc, options, keep, no_extern_c, arch, code, cache_dir, include_dirs, target)
    253         options.append("-I"+i)
    254 
--> 255     return compile_plain(source, options, keep, nvcc, cache_dir, target)
    256 
    257 

/usr/lib/python2.7/dist-packages/pycuda/compiler.pyc in compile_plain(source, options, keep, nvcc, cache_dir, target)
    135         raise CompileError("nvcc compilation of %s failed" % cu_file_path,
    136                 cmdline, stdout=stdout.decode("utf-8", "replace"),
--> 137                 stderr=stderr.decode("utf-8", "replace"))
    138 
    139     if stdout or stderr:

CompileError: nvcc compilation of /tmp/tmpVgfyrm/kernel.cu failed
[command: nvcc --cubin -arch sm_61 -I/usr/local/lib/python2.7/dist-packages/pycuda-2017.1.1-py2.7-linux-x86_64.egg/pycuda/cuda kernel.cu]
[stderr:
ERROR: No supported gcc/g++ host compiler found, but clang-3.8 is available.
       Use 'nvcc -ccbin clang-3.8' to use that instead.
]

Anyone knows how I can add -ccbin clang-3.8 to pycuda??

2

2 Answers

1
votes

For everyone with the problem, the solution is the one given b talonmies, using the options argument. The code I used was the following:

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];
}
""", options=["-ccbin","clang-3.8"])

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

or using:

pycuda.compiler.DEFAULT_NVCC_FLAG = ["-ccbin","clang-3.8"]
1
votes

As per the documentation, you can specify compiler options to nvcc in two ways

  1. Set the default compiler options via the PYCUDA_DEFAULT_NVCC_FLAGS environment variable.
  2. Set the compiler options for a given SourceModule via a list passed using the options= keyword