[PyCUDA] pycuda works only from the terminal

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[PyCUDA] pycuda works only from the terminal

Artur Makhmutov
Hello,

I am not sure if this is the right place to ask for a tech support, please ignore the message if it is not.

My problem is described as follows: I am trying to run one of the example scripts (I use ubuntu, pycharm with venv python virtual environment):

import pycuda.autoinit
from pycuda.compiler import SourceModule
import numpy

a = numpy.random.randn(4,4)

a = a.astype(numpy.float32)

a_gpu = cuda.mem_alloc(a.size * a.dtype.itemsize)

cuda.memcpy_htod(a_gpu, a)

mod = SourceModule("""
    __global__ void doublify(float *a)
    {
      int idx = threadIdx.x + threadIdx.y*4;
      a[idx] *= 2;
    }
    """)

func = mod.get_function("doublify")
func(a_gpu, block=(4,4,1))

a_doubled = numpy.empty_like(a)
cuda.memcpy_dtoh(a_doubled, a_gpu)
print ("original array:")
print (a)
print ("doubled with kernel:")
print (a_doubled)
And I get the following error:

/home/art/.pyenv/versions/test380/bin/python /home/art/PycharmProjects/pycuda/test.py
Traceback (most recent call last):
  File "/home/art/.pyenv/versions/test380/lib/python3.8/site-packages/pytools/__init__.py", line 536, in _deco
    return func._memoize_dic[args]  # pylint: disable=protected-access
AttributeError: 'function' object has no attribute '_memoize_dic'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/art/.pyenv/versions/test380/lib/python3.8/site-packages/pytools/prefork.py", line 49, in call_capture_output
    popen = Popen(cmdline, cwd=cwd, stdin=PIPE, stdout=PIPE,
  File "/home/art/.pyenv/versions/3.8.0/lib/python3.8/subprocess.py", line 854, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/home/art/.pyenv/versions/3.8.0/lib/python3.8/subprocess.py", line 1702, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'nvcc'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/art/PycharmProjects/pycuda/test.py", line 16, in <module>
    mod = SourceModule("""
  File "/home/art/.pyenv/versions/test380/lib/python3.8/site-packages/pycuda/compiler.py", line 290, in __init__
    cubin = compile(source, nvcc, options, keep, no_extern_c,
  File "/home/art/.pyenv/versions/test380/lib/python3.8/site-packages/pycuda/compiler.py", line 254, in compile
    return compile_plain(source, options, keep, nvcc, cache_dir, target)
  File "/home/art/.pyenv/versions/test380/lib/python3.8/site-packages/pycuda/compiler.py", line 84, in compile_plain
    checksum.update(get_nvcc_version(nvcc).encode("utf-8"))
  File "</home/art/.pyenv/versions/test380/lib/python3.8/site-packages/decorator.py:decorator-gen-3>", line 2, in get_nvcc_version
  File "/home/art/.pyenv/versions/test380/lib/python3.8/site-packages/pytools/__init__.py", line 539, in _deco
    result = func(*args)
  File "/home/art/.pyenv/versions/test380/lib/python3.8/site-packages/pycuda/compiler.py", line 16, in get_nvcc_version
    result, stdout, stderr = call_capture_output(cmdline)
  File "/home/art/.pyenv/versions/test380/lib/python3.8/site-packages/pytools/prefork.py", line 227, in call_capture_output
    return forker.call_capture_output(cmdline, cwd, error_on_nonzero)
  File "/home/art/.pyenv/versions/test380/lib/python3.8/site-packages/pytools/prefork.py", line 60, in call_capture_output
    raise ExecError("error invoking '%s': %s"
pytools.prefork.ExecError: error invoking 'nvcc --version': [Errno 2] No such file or directory: 'nvcc'

Process finished with exit code 1
But if I run it with the 'python test.py' from the terminal itself, thenĀ  it executes just fine:

(test380) art@HP:~/PycharmProjects/pycuda$ python test.py
original array:
[[ 0.63286567 -0.5732655   0.0824481   0.17147891]
 [-0.24867015 -2.4119377  -0.41027954 -0.67181575]
 [-1.2339077  -1.23354     1.0630324   0.3807849 ]
 [-1.5976559  -1.5595584  -0.03161036 -0.50650793]]
doubled with kernel:
[[ 1.2657313  -1.146531    0.1648962   0.34295782]
 [-0.4973403  -4.8238754  -0.8205591  -1.3436315 ]
 [-2.4678154  -2.46708     2.1260648   0.7615698 ]
 [-3.1953118  -3.1191168  -0.06322072 -1.0130159 ]]
I wonder if it supposed to work like that or am I missing something? I have checked the .bashrc file, nvcc --version, gcc --version and other hints from the manual, everything seems to be correct. Would much appreciate your help.


Kind Regards,


Artur



_______________________________________________
PyCUDA mailing list -- [hidden email]
To unsubscribe send an email to [hidden email]
Reply | Threaded
Open this post in threaded view
|

[PyCUDA] Re: pycuda works only from the terminal

Andreas Kloeckner
Artur,

Artur Makhmutov <[hidden email]> writes:

> I am not sure if this is the right place to ask for a tech support,
> please ignore the message if it is not.
>
> My problem is described as follows: I am trying to run one of the
> example scripts (I use ubuntu, pycharm with venv python virtual
> environment):
>
>> |import pycuda.autoinit from pycuda.compiler import SourceModule
>> import numpy a = numpy.random.randn(4,4) a = a.astype(numpy.float32)
>> a_gpu = cuda.mem_alloc(a.size * a.dtype.itemsize)
>> cuda.memcpy_htod(a_gpu, a) mod = SourceModule(""" __global__ void
>> doublify(float *a) { int idx = threadIdx.x + threadIdx.y*4; a[idx] *=
>> 2; } """) func = mod.get_function("doublify") func(a_gpu,
>> block=(4,4,1)) a_doubled = numpy.empty_like(a)
>> cuda.memcpy_dtoh(a_doubled, a_gpu) print ("original array:") print (a)
>> print ("doubled with kernel:") print (a_doubled)|
> And I get the following error:
>
> (snip)
> But if I run it with the 'python test.py' from the terminal itself,
> thenĀ  it executes just fine:
>
>> |(test380) art@HP:~/PycharmProjects/pycuda$ python test.py original
>> array: [[ 0.63286567 -0.5732655 0.0824481 0.17147891] [-0.24867015
>> -2.4119377 -0.41027954 -0.67181575] [-1.2339077 -1.23354 1.0630324
>> 0.3807849 ] [-1.5976559 -1.5595584 -0.03161036 -0.50650793]] doubled
>> with kernel: [[ 1.2657313 -1.146531 0.1648962 0.34295782] [-0.4973403
>> -4.8238754 -0.8205591 -1.3436315 ] [-2.4678154 -2.46708 2.1260648
>> 0.7615698 ] [-3.1953118 -3.1191168 -0.06322072 -1.0130159 ]] |
> I wonder if it supposed to work like that or am I missing something? I
> have checked the .bashrc file, nvcc --version, gcc --version and other
> hints from the manual, everything seems to be correct. Would much
> appreciate your help.
See if you can run

os.system("nvcc --help")

from within PyCharm. (I suspect not.) If not, then PyCharm is changing
your $PATH so that nvcc is no longer visible. If so, then you should ask
the PyCharm folks how to fix that.

HTH,
Andreas

_______________________________________________
PyCUDA mailing list -- [hidden email]
To unsubscribe send an email to [hidden email]

signature.asc (847 bytes) Download Attachment