inducer / inducer/pyopencl

Image not initialized on GPU

Open
#288 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
1.2k
Forks
247
Avg merge
7h 2m
Merged PRs (30d)
6

Description

It seems sometimes image is not correctly initialized on NVIDA GPU on windows.
```
import numpy as np
import pyopencl as cl
from pyopencl import cltypes

platform = cl.get_platforms()[0]
print(platform, platform.version)

device = platform.get_devices()[0]
print(
device,
"image support: {}".format(device.get_info(cl.device_info.IMAGE_SUPPORT)),
)

ctx = cl.Context([device])
print(ctx)

cmd_queue = cl.CommandQueue(ctx)

image_data = np.arange(0.0, 10.0)

image_device = cl.Image(
ctx,
cl.mem_flags.READ_ONLY | cl.mem_flags.COPY_HOST_PTR,
cl.ImageFormat(cl.channel_order.RG, cl.channel_type.FLOAT),
hostbuf=np.stack((image_data, image_data), axis=1).astype(cltypes.float),
)

output_array = np.empty((10,), dtype=cltypes.float)
output_device = cl.Buffer(
ctx, cl.mem_flags.READ_WRITE, 10 * np.dtype(cltypes.float).itemsize
)

kernel_string = """
__kernel void test(__read_only image1d_t img, __global float * output){
sampler_t img_sampler = CLK_NORMALIZED_COORDS_FALSE |
CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_LINEAR;
int i = get_global_id(0);
float x = 0.5f + i;
output[i] = read_imagef(img, img_sampler, x).x;
}
"""
program = cl.Program(ctx, kernel_string).build(
"-cl-single-precision-constant -I."
)
program.test(cmd_queue, (10,), None, image_device, output_device)
cl.enqueue_copy(cmd_queue, output_array, output_device)
print(output_array)
```

Output:
```
OpenCL 1.2 CUDA 10.2.120
image support: 1
>
[0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
```

However, if I choose Intel platform and CPU as device, the output is correct:
```
OpenCL 2.1
image support: 1
>
C:\Users\nanqin\Miniconda3\envs\opencl\lib\site-packages\pyopencl\__init__.py:235: CompilerWarning: Non-empty compiler output encountered. Set the environment variable PYOPENCL_COMPILER_OUTPUT=1 to see more.
"to see more.", CompilerWarning)
[0. 1. 2. 3. 4. 5. 6. 7. 8. 9.]
```

OS: windows10

I tested with AMD GPU on Mac and the output is correct
```
OpenCL 1.2 (Feb 22 2019 20:16:07)
image support: 1
>
[0. 1. 2. 3. 4. 5. 6. 7. 8. 9.]
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.