Skip to content

Instantly share code, notes, and snippets.

@gaebor
Created April 30, 2019 12:26
Show Gist options
  • Save gaebor/f0e94901bf53f0730623c53f441a7c42 to your computer and use it in GitHub Desktop.
Save gaebor/f0e94901bf53f0730623c53f441a7c42 to your computer and use it in GitHub Desktop.
just a small OpenCL test
from __future__ import print_function
from ctypes import*
import sys
dllname = "opencl"
if len(sys.argv) >= 2:
dllname = sys.argv[1]
opencl = cdll.LoadLibrary(dllname)
pointerarray_type = c_void_p * 10
platforms = pointerarray_type()
devices = pointerarray_type()
out_num = c_uint()
error = opencl.clGetPlatformIDs(10, platforms, pointer(out_num))
name = (c_char * 256)()
if error == 0:
for i in range(out_num.value):
error = opencl.clGetPlatformInfo(c_void_p(platforms[i]), 0x0902, c_size_t(256), pointer(name), 0)
if error == 0:
print("Platform {0}: {1}".format(i, name.value.decode()))
error = opencl.clGetDeviceIDs(c_void_p(platforms[i]), 0xFFFFFFFF, 10, devices, pointer(out_num))
if error == 0:
for j in range(out_num.value):
error = opencl.clGetDeviceInfo(c_void_p(devices[j]), 0x102B, c_size_t(256), pointer(name), 0)
if error == 0:
print("\tDevice {0}: {1}".format(j, name.value.decode()))
else:
print("Device {} has error {}".format(j, error), file=sys.stderr)
else:
print("Platform {} has error {}".format(i, error), file=sys.stderr)
else:
print("Platform {} has error {}".format(i, error), file=sys.stderr)
else:
print("Error in clGetPlatformIDs, error code:", error, file=sys.stderr)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment