以下のコードがget_info関数の実装例となります。
上級者のためにfrom_int_ptr関数についての参考例も掲載していますが、これはOpenCLオブジェクトへのCポインタを取得する関数であり、pyopenclのモジュールを開発する用途でもなければ使うことはないでしょう。
PlatformTest.py.
import pyopencl as cl
platforms = cl.get_platforms()
device = platforms[0].get_devices(cl.device_type.ALL)
platform = platforms[0]
extensions = platform.get_info(cl.platform_info.EXTENSIONS)
print("platform extensions: "+str(extensions))
name = platform.get_info(cl.platform_info.NAME)
print("name: " + str(name))
vendor = platform.get_info(cl.platform_info.VENDOR)
print("vendor: " + str(vendor))
version = platform.get_info(cl.platform_info.VERSION)
print("version: " + str(version))
# For pyopencl module developer
# Retrieve the c-pointer to opencl object
# This would allow other python API to interact with the opencl object
platref = platform.from_int_ptr(platform.int_ptr)
if platref == platform and type(platref) is type(platform):
print("pointer identity is confirmed.")
if platref != device:
print("pass: another identity test")
出力.
/Library/Frameworks/Python.framework/Versions/3.5/bin/python3.5 /Users/komatsu/PycharmProjects/MyPythonProject/PlatformTest.py platform extensions: cl_APPLE_SetMemObjectDestructor cl_APPLE_ContextLoggingFunctions cl_APPLE_clut cl_APPLE_query_kernel_names cl_APPLE_gl_sharing cl_khr_gl_event name: Apple vendor: Apple version: OpenCL 1.2 (Apr 26 2016 00:05:53) pointer identity is confirmed. pass: another identity test
Copyright 2018-2019, by Masaki Komatsu