1 // DerelictCL - a Derelict based dynamic binding for OpenCL 2 // written in the D programming language 3 // 4 // Copyright: MeinMein 2013-2014. 5 // License: Boost License 1.0 6 // (See accompanying file LICENSE_1_0.txt or copy at 7 // http://www.boost.org/LICENSE_1_0.txt) 8 // Authors: Gerbrand Kamphuis (meinmein.com), 9 // Marvin Meeng (meinmein.com). 10 module derelict.opencl.cl_ext; 11 12 import derelict.opencl.loader; 13 import derelict.opencl.types; 14 15 extern (System) 16 { 17 // OpenCL 1.0 18 alias nothrow cl_int function(cl_mem, void function(cl_mem, void*), void*) da_clSetMemObjectDestructorAPPLE; 19 alias nothrow void function(const(char*), const(void*), size_t, void*) da_clLogMessagesToSystemLogAPPLE; 20 alias nothrow void function(const(char*), const(void*), size_t, void*) da_clLogMessagesToStdoutAPPLE; 21 alias nothrow void function(const(char*), const(void*), size_t, void*) da_clLogMessagesToStderrAPPLE; 22 alias nothrow cl_int function(cl_uint, cl_platform_id*, cl_uint*) da_clIcdGetPlatformIDsKHR; 23 // OpenCL 1.1 24 alias nothrow cl_int function(cl_device_id) da_clReleaseDeviceEXT; 25 alias nothrow cl_int function(cl_device_id) da_clRetainDeviceEXT; 26 alias nothrow cl_int function(cl_device_id, const(cl_device_partition_property_ext*), cl_uint, cl_device_id*, cl_uint*) da_clCreateSubDevicesEXT; 27 // OpenCL 1.2 28 alias nothrow cl_int function(cl_context) da_clTerminateContextKHR; 29 } 30 31 __gshared 32 { 33 // OpenCL 1.0 34 da_clSetMemObjectDestructorAPPLE clSetMemObjectDestructorAPPLE; 35 da_clLogMessagesToSystemLogAPPLE clLogMessagesToSystemLogAPPLE; 36 da_clLogMessagesToStdoutAPPLE clLogMessagesToStdoutAPPLE; 37 da_clLogMessagesToStderrAPPLE clLogMessagesToStderrAPPLE; 38 da_clIcdGetPlatformIDsKHR clIcdGetPlatformIDsKHR; 39 // OpenCL 1.1 40 da_clReleaseDeviceEXT clReleaseDeviceEXT; 41 da_clRetainDeviceEXT clRetainDeviceEXT; 42 da_clCreateSubDevicesEXT clCreateSubDevicesEXT; 43 // OpenCL 1.2 44 da_clTerminateContextKHR clTerminateContextKHR; 45 } 46 47 package 48 { 49 void loadSymbols(void delegate(void**, string, bool doThrow) bindFunc) 50 { 51 52 } 53 54 CLVersion reload(void delegate(void**, string, bool doThrow) bindFunc, CLVersion clVer) 55 { 56 return clVer; 57 } 58 59 private __gshared bool _EXT_cl_APPLE_SetMemObjectDestructor; 60 public bool EXT_cl_APPLE_SetMemObjectDestructor() @property { return _EXT_cl_APPLE_SetMemObjectDestructor; } 61 private void load_cl_APPLE_SetMemObjectDestructor(CLVersion clVer, cl_platform_id platform) 62 { 63 try 64 { 65 loadExtensionFunction(cast(void**)&clSetMemObjectDestructorAPPLE, "clSetMemObjectDestructorAPPLE", clVer, platform); 66 67 _EXT_cl_APPLE_SetMemObjectDestructor = clSetMemObjectDestructorAPPLE !is null; 68 } 69 catch(Exception e) 70 { 71 _EXT_cl_APPLE_SetMemObjectDestructor = false; 72 } 73 } 74 75 private __gshared bool _EXT_cl_APPLE_ContextLoggingFunctions; 76 public bool EXT_cl_APPLE_ContextLoggingFunctions() @property { return _EXT_cl_APPLE_ContextLoggingFunctions; } 77 private void load_cl_APPLE_ContextLoggingFunctions(CLVersion clVer, cl_platform_id platform) 78 { 79 try 80 { 81 loadExtensionFunction(cast(void**)&clLogMessagesToSystemLogAPPLE, "clLogMessagesToSystemLogAPPLE", clVer, platform); 82 loadExtensionFunction(cast(void**)&clLogMessagesToStdoutAPPLE, "clLogMessagesToStdoutAPPLE", clVer, platform); 83 loadExtensionFunction(cast(void**)&clLogMessagesToStderrAPPLE, "clLogMessagesToStderrAPPLE", clVer, platform); 84 85 _EXT_cl_APPLE_ContextLoggingFunctions = clLogMessagesToSystemLogAPPLE !is null && 86 clLogMessagesToStdoutAPPLE !is null && 87 clLogMessagesToStderrAPPLE !is null; 88 } 89 catch(Exception e) 90 { 91 _EXT_cl_APPLE_ContextLoggingFunctions = false; 92 } 93 } 94 95 private __gshared bool _EXT_cl_khr_icd; 96 public bool EXT_cl_khr_icd() @property { return _EXT_cl_khr_icd; } 97 private void load_cl_khr_icd(CLVersion clVer, cl_platform_id platform) 98 { 99 try 100 { 101 loadExtensionFunction(cast(void**)&clIcdGetPlatformIDsKHR, "clIcdGetPlatformIDsKHR", clVer, platform); 102 103 _EXT_cl_khr_icd = clIcdGetPlatformIDsKHR !is null; 104 } 105 catch(Exception e) 106 { 107 _EXT_cl_khr_icd = false; 108 } 109 } 110 111 private __gshared bool _EXT_cl_ext_device_fission; 112 public bool EXT_cl_ext_device_fission() @property { return _EXT_cl_ext_device_fission; } 113 private void load_cl_ext_device_fission(CLVersion clVer, cl_platform_id platform) 114 { 115 try 116 { 117 loadExtensionFunction(cast(void**)&clReleaseDeviceEXT, "clReleaseDeviceEXT", clVer, platform); 118 loadExtensionFunction(cast(void**)&clRetainDeviceEXT, "clRetainDeviceEXT", clVer, platform); 119 loadExtensionFunction(cast(void**)&clCreateSubDevicesEXT, "clCreateSubDevicesEXT", clVer, platform); 120 121 _EXT_cl_ext_device_fission = clReleaseDeviceEXT !is null && 122 clRetainDeviceEXT !is null && 123 clCreateSubDevicesEXT !is null; 124 } 125 catch(Exception e) 126 { 127 _EXT_cl_ext_device_fission = false; 128 } 129 } 130 131 private __gshared bool _EXT_cl_khr_terminate_context; 132 public bool EXT_cl_khr_terminate_context() @property { return _EXT_cl_khr_terminate_context; } 133 private void load_cl_khr_terminate_context(CLVersion clVer, cl_platform_id platform) 134 { 135 try 136 { 137 loadExtensionFunction(cast(void**)&clTerminateContextKHR, "clTerminateContextKHR", clVer, platform); 138 139 _EXT_cl_khr_terminate_context = clTerminateContextKHR !is null; 140 } 141 catch(Exception e) 142 { 143 _EXT_cl_khr_terminate_context = false; 144 } 145 } 146 147 148 void loadEXT(CLVersion clVer, cl_platform_id platform) 149 { 150 if(clVer >= CLVersion.CL10) 151 { 152 // OpenCL 1.0 153 load_cl_APPLE_SetMemObjectDestructor(clVer, platform); 154 load_cl_APPLE_ContextLoggingFunctions(clVer, platform); 155 load_cl_khr_icd(clVer, platform); 156 } 157 158 if(clVer >= CLVersion.CL11) 159 { 160 // OpenCL 1.1 161 load_cl_ext_device_fission(clVer, platform); 162 } 163 164 if(clVer >= CLVersion.CL12) 165 { 166 // OpenCL 1.2 167 load_cl_khr_terminate_context(clVer, platform); 168 } 169 } 170 }