Discussion:
[PyCUDA] Problem with pow
elodw
2014-07-11 11:27:25 UTC
Permalink
Hello Andreas and all the World,

with

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

from pycuda.tools import mark_cuda_test
from pycuda.characterize import has_double_support

from pycuda.compiler import SourceModule
.....
....
zzz=gpuarray.sum(pow(yyy-xxx,2)) -------Error statement
....
....

i get the following error message:

Traceback (most recent call last):
File "/home/brust/PyCUDA/matmul17.py", line 36, in <module>
zzz=gpuarray.sum(pow(yyy-xxx,2))
File "/usr/lib/python2.7/dist-packages/pycuda/gpuarray.py", line 623,
in __pow__
func = elementwise.get_pow_kernel(self.dtype)
File "<string>", line 2, in get_pow_kernel
File "/usr/lib/python2.7/dist-packages/pycuda/tools.py", line 404, in
context_dependent_memoize
result = func(*args)
File "/usr/lib/python2.7/dist-packages/pycuda/elementwise.py", line
549, in get_pow_kernel
"pow_method")
File "/usr/lib/python2.7/dist-packages/pycuda/elementwise.py", line
165, in get_elwise_kernel
arguments, operation, name, keep, options, **kwargs)
File "/usr/lib/python2.7/dist-packages/pycuda/elementwise.py", line
151, in get_elwise_kernel_and_types
keep, options, **kwargs)
File "/usr/lib/python2.7/dist-packages/pycuda/elementwise.py", line
75, in get_elwise_module
options=options, keep=keep)
File "/usr/lib/python2.7/dist-packages/pycuda/compiler.py", line 262,
in __init__
arch, code, cache_dir, include_dirs)
File "/usr/lib/python2.7/dist-packages/pycuda/compiler.py", line 252,
in compile
return compile_plain(source, options, keep, nvcc, cache_dir)
File "/usr/lib/python2.7/dist-packages/pycuda/compiler.py", line 134,
in compile_plain
cmdline, stdout=stdout.decode("utf-8"), stderr=stderr.decode("utf-8"))
pycuda.driver.CompileError: nvcc compilation of /tmp/tmpKjK3Px/kernel.cu
failed
[command: nvcc --cubin -arch sm_20
-I/usr/lib/python2.7/dist-packages/pycuda/cuda kernel.cu]
[stderr:
/usr/lib/python2.7/dist-packages/pycuda/cuda/pycuda-complex.hpp(553):
warning: a __host__ function("pycuda::complex<float>::complex")
redeclared with __device__, hence treated as a __host__ __device__ function

kernel.cu(19): error: calling a __host__ function("std::pow<long, long>
") from a __global__ function("pow_method") is not allowed

1 error detected in the compilation of
"/tmp/tmpxft_00000c21_00000000-6_kernel.cpp1.ii".
]



zzz=gpuarray.sum((yyy-xxx)*(yyy-xxx))

works well.

And another question:

Is there a sqrt-Function?


Thanks in advance

Ernst
Andreas Kloeckner
2014-07-11 20:14:39 UTC
Permalink
Post by elodw
with
import pycuda.gpuarray as gpuarray
import pycuda.driver as drv
import pycuda.autoinit
import numpy
import sys
from pycuda.tools import mark_cuda_test
from pycuda.characterize import has_double_support
from pycuda.compiler import SourceModule
.....
....
zzz=gpuarray.sum(pow(yyy-xxx,2)) -------Error statement
....
....
File "/home/brust/PyCUDA/matmul17.py", line 36, in <module>
zzz=gpuarray.sum(pow(yyy-xxx,2))
File "/usr/lib/python2.7/dist-packages/pycuda/gpuarray.py", line 623,
in __pow__
func = elementwise.get_pow_kernel(self.dtype)
File "<string>", line 2, in get_pow_kernel
File "/usr/lib/python2.7/dist-packages/pycuda/tools.py", line 404, in
context_dependent_memoize
result = func(*args)
File "/usr/lib/python2.7/dist-packages/pycuda/elementwise.py", line
549, in get_pow_kernel
"pow_method")
File "/usr/lib/python2.7/dist-packages/pycuda/elementwise.py", line
165, in get_elwise_kernel
arguments, operation, name, keep, options, **kwargs)
File "/usr/lib/python2.7/dist-packages/pycuda/elementwise.py", line
151, in get_elwise_kernel_and_types
keep, options, **kwargs)
File "/usr/lib/python2.7/dist-packages/pycuda/elementwise.py", line
75, in get_elwise_module
options=options, keep=keep)
File "/usr/lib/python2.7/dist-packages/pycuda/compiler.py", line 262,
in __init__
arch, code, cache_dir, include_dirs)
File "/usr/lib/python2.7/dist-packages/pycuda/compiler.py", line 252,
in compile
return compile_plain(source, options, keep, nvcc, cache_dir)
File "/usr/lib/python2.7/dist-packages/pycuda/compiler.py", line 134,
in compile_plain
cmdline, stdout=stdout.decode("utf-8"), stderr=stderr.decode("utf-8"))
pycuda.driver.CompileError: nvcc compilation of /tmp/tmpKjK3Px/kernel.cu
failed
[command: nvcc --cubin -arch sm_20
-I/usr/lib/python2.7/dist-packages/pycuda/cuda kernel.cu]
warning: a __host__ function("pycuda::complex<float>::complex")
redeclared with __device__, hence treated as a __host__ __device__ function
kernel.cu(19): error: calling a __host__ function("std::pow<long, long>
") from a __global__ function("pow_method") is not allowed
1 error detected in the compilation of
"/tmp/tmpxft_00000c21_00000000-6_kernel.cpp1.ii".
]
zzz=gpuarray.sum((yyy-xxx)*(yyy-xxx))
works well.
The issue is that you're passing integers. Cast to floating point before
you call the function.
Post by elodw
Is there a sqrt-Function?
http://documen.tician.de/pycuda/array.html#pycuda.cumath.sqrt

Andreas

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 810 bytes
Desc: not available
URL: <http://lists.tiker.net/pipermail/pycuda/attachments/20140711/9fa873d6/attachment.sig>
elodw
2014-07-13 06:56:58 UTC
Permalink
Post by Andreas Kloeckner
The issue is that you're passing integers. Cast to floating point
before you call the function.
Post by elodw
Is there a sqrt-Function?
http://documen.tician.de/pycuda/array.html#pycuda.cumath.sqrt
Andreas


Thank You very much, Andreas.

The next question I had, is

should I prefer an ElementwiseKernel
or a ReductionKernel for the following Problem:

tab[m,n]
for i in range(m-1):
for j in range(i+1,m):
calculate euclidean difference between tab[i] and tab[j]


Thanks in Advance
Ernst
Andreas Kloeckner
2014-07-14 18:49:00 UTC
Permalink
Post by elodw
Post by Andreas Kloeckner
The issue is that you're passing integers. Cast to floating point
before you call the function.
Post by elodw
Is there a sqrt-Function?
http://documen.tician.de/pycuda/array.html#pycuda.cumath.sqrt
Andreas
Thank You very much, Andreas.
The next question I had, is
should I prefer an ElementwiseKernel
tab[m,n]
calculate euclidean difference between tab[i] and tab[j]
Probably neither, since it's a two-index loop. I.e. you should probably
write that one from scratch to be able to map both i and j to CUDA axes.

Hope that helps,
Andreas
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 810 bytes
Desc: not available
URL: <http://lists.tiker.net/pipermail/pycuda/attachments/20140714/2a2ae1a4/attachment.sig>
elodw
2014-07-15 06:54:49 UTC
Permalink
Post by Andreas Kloeckner
Probably neither, since it's a two-index loop. I.e. you should probably
write that one from scratch to be able to map both i and j to CUDA axes.
Hope that helps,
Andreas
Thank You Andreas,

perhaps You know a Source in the Net ?

Thanks in advance
Ernst

Loading...