0
pyopencl 모듈을 사용하여 Python으로 OpenCl을 살펴 보았습니다.OpenCl Global ID를 커널의 정수로 사용하십시오.
저는 입력이없는 물건을 생성하고 예를 들어 사인파의 샘플을 생성하는 데 관심이 있습니다.
이렇게하려면 글로벌 ID를 사용하여 계산을해야했지만 글로벌 ID 결과를 반환하는 것이 좋습니다. 나는 아래의 코드를 사용합니다
import numpy as np
import pyopencl as cl
Size = Width*Height
# Get platforms, both CPU and GPU
plat = cl.get_platforms()
GPU = plat[0].get_devices()
#Create context for GPU
ctx = cl.Context(GPU)
# Create queue for each kernel execution
queue = cl.CommandQueue(ctx)
mf = cl.mem_flags
# Kernel function
src = '''
__kernel void shader(__global float *result, __global int *width){
int w = *width;
size_t gid = get_global_id(0);
result[gid] = gid;
}
'''
#Kernel function instantiation
prg = cl.Program(ctx, src).build()
#Allocate memory for variables on the device
width_g = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=np.int32(Width))
result_g = cl.Buffer(ctx, mf.WRITE_ONLY, Size*8)
# Call Kernel. Automatically takes care of block/grid distribution
prg.shader(queue, (Size,), None , result_g, width_g)
result = np.empty((Size,))
cl.enqueue_copy(queue, result, result_g)
Image = result
내가 할 모든 가을 result_d 버퍼 오브젝트에 글로벌 ID를 복사입니다,하지만 난 결과을 검사 할 때, 난 정수하지 않은 몇 가지 숫자를 얻을. float 대신 정수로 버퍼를 설정하려고했지만 결과는 여전히 동일합니다.
내가 뭘 잘못하고 있니?