Skip to content

Commit

Permalink
ctype_buffer to a helper since it can be shared with others
Browse files Browse the repository at this point in the history
  • Loading branch information
Qazalin committed Nov 26, 2023
1 parent dcb7075 commit 141dd63
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 2 additions & 0 deletions test/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,5 @@ def cuda_compile(prg, options, f, check):
status = f.compile(prog, len(options), to_char_p_p(options))
if status != 0: raise RuntimeError(f"compile failed: {get_bytes(prog, f.getLogSize, f.getLog, check)}")
return get_bytes(prog, f.getCodeSize, f.getCode, check)

def ctype_buffer(dtype, sz: int, data): return (dtype * sz)(*data)
8 changes: 4 additions & 4 deletions test/test_opencl.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import Optional
import ctypes
import unittest
from helpers import to_char_p_p
from helpers import ctype_buffer, to_char_p_p
import gpuctypes.opencl as cl

def check(status, info:Optional[str]=None):
Expand Down Expand Up @@ -80,9 +80,9 @@ def test_run_program(self):
check(status.value)
assert kernel is not None

A = (ctypes.c_int32 * 5)()
B = (ctypes.c_int32 * 5)(1, 2, 3, 4, 5)
C = (ctypes.c_int32 * 5)(5, 4, 3, 2, 1)
A = ctype_buffer(ctypes.c_int32, 5, ())
B = ctype_buffer(ctypes.c_int32, 5, (1,2,3,4,5))
C = ctype_buffer(ctypes.c_int32, 5, (5,4,3,2,1))

bufA = cl.clCreateBuffer(self.context, cl.CL_MEM_WRITE_ONLY, ctypes.sizeof(A), None, ctypes.byref(status))
bufB = cl.clCreateBuffer(self.context, cl.CL_MEM_READ_ONLY | cl.CL_MEM_COPY_HOST_PTR, ctypes.sizeof(B), ctypes.byref(B), ctypes.byref(status))
Expand Down

0 comments on commit 141dd63

Please sign in to comment.