potential bug in pycuda.gpuarray.vec
- Dominant language
- Python
- Stars
- 2.1k
- Forks
- 298
- Avg merge
- 4m
- Merged PRs (30d)
- 1
Description
Thank you very much for this library. I have been playing around with it for a while and just found the following oddity. The following example produces the expected outcome.
```python
import numpy
import pycuda.autoinit
import pycuda.driver
import pycuda.compiler
import pycuda.gpuarray
multiply_them = pycuda.compiler.SourceModule("""
__global__ void multiply_them(float *dest, float *a, float *b, const float3 test) {
dest[threadIdx.x] = a[threadIdx.x] * b[threadIdx.x] + test.x;
}
""").get_function("multiply_them")
a = numpy.random.randn(10).astype(numpy.float32)
b = numpy.random.randn(10).astype(numpy.float32)
dest = numpy.zeros(10).astype(numpy.float32)
multiply_them(
pycuda.driver.Out(dest),
pycuda.driver.In(a),
pycuda.driver.In(b),
pycuda.gpuarray.vec.make_float3(1.0, 2.0, 3.0),
block=(10, 1, 1), grid=(1, 1, 1)
)
print dest - a*b # [ 1. 1. 1. 1. 1. 1. 1. 1. 1. 1.]
```
However, if a `float4` is used instead of the `float3`, the output is different.
```python
import numpy
import pycuda.autoinit
import pycuda.driver
import pycuda.compiler
import pycuda.gpuarray
multiply_them = pycuda.compiler.SourceModule("""
__global__ void multiply_them(float *dest, float *a, float *b, const float4 test) {
dest[threadIdx.x] = a[threadIdx.x] * b[threadIdx.x] + test.x;
}
""").get_function("multiply_them")
a = numpy.random.randn(10).astype(numpy.float32)
b = numpy.random.randn(10).astype(numpy.float32)
dest = numpy.zeros(10).astype(numpy.float32)
multiply_them(
pycuda.driver.Out(dest),
pycuda.driver.In(a),
pycuda.driver.In(b),
pycuda.gpuarray.vec.make_float4(1.0, 2.0, 3.0, 4.0),
block=(10, 1, 1), grid=(1, 1, 1)
)
print dest - a*b # [ 3. 3. 3. 3. 3. 3. 3. 3. 3. 3.]
```
The only difference between those example is in the following lines.
```
- __global__ void multiply_them(float *dest, float *a, float *b, const float3 test) {
+ __global__ void multiply_them(float *dest, float *a, float *b, const float4 test) {
- pycuda.gpuarray.vec.make_float3(1.0, 2.0, 3.0),
+ pycuda.gpuarray.vec.make_float4(1.0, 2.0, 3.0, 4.0),
```
Is my understanding wrong? Shouldn't the outcome be equal regardless of whether it is `float3`or `float4`?
Once again, thank you!
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.