/// <summary> /// Executes full logic for getting CL Context on Windows platforms. /// </summary> /// <returns>The get CL shared context.</returns> public static Context WindowsGetCLSharedContext(Platform p) { ErrorCode error; var wglContext = WindowsGetCurrentWGLContext(); if ((wglContext as IHandleData).Handle.ToInt32() == 0) { throw new UnityCLException("wgl context was null."); } var wglDeviceContext = WindowsGetCurrentWGLDeviceContext(); if ((wglDeviceContext as IHandleData).Handle.ToInt32() == 0) { throw new UnityCLException("wgl device context was null."); } uint[] properties = new uint[] { (uint)cl_gl_ContextProperties.CL_GL_CONTEXT_KHR, (uint)(wglContext as IHandleData).Handle.ToInt32(), (uint)cl_gl_ContextProperties.CL_WGL_HDC_KHR, (uint)(wglDeviceContext as IHandleData).Handle.ToInt32(), (uint)ContextProperties.Platform, (uint)(p as IHandleData).Handle.ToInt32(), 0 }; var context = new Context(clCreateContextFromType(properties, DeviceType.All, null, IntPtr.Zero, out error)); if (UnityCL.IsError(error)) { throw new UnityCLException(error); } if ((context as IHandleData).Handle.ToInt32() == 0) { throw new UnityCLException("OpenCL context was null."); } return(context); }
public static string Name(this Device self) { ErrorCode error; var info = Cl.GetDeviceInfo(self, DeviceInfo.Name, out error); if (UnityCL.IsError(error)) { throw new UnityCLException(error); } return(info.ToString()); }
public static DeviceType DeviceType(this Device self) { ErrorCode error; var inf = Cl.GetDeviceInfo(self, DeviceInfo.Type, out error); if (UnityCL.IsError(error)) { throw new UnityCLException(error); } return(inf.CastTo <DeviceType>()); }
public static string Name(this Platform self) { ErrorCode error; var inf = Cl.GetPlatformInfo(self, PlatformInfo.Name, out error); if (UnityCL.IsError(error)) { throw new UnityCLException(error); } return(inf.ToString()); }
public static string GetBuildError(this Program self) { var devices = self.GetDevices(); OpenCL.Net.ErrorCode logerror; var log = OpenCL.Net.Cl.GetProgramBuildInfo(self, devices[0], OpenCL.Net.ProgramBuildInfo.Log, out logerror); if (UnityCL.IsError(logerror)) { throw new UnityCLException(logerror); } return(log.ToString()); }
public static Device[] GetDevices(this Context self) { OpenCL.Net.ErrorCode error; var numDevicesInfo = OpenCL.Net.Cl.GetContextInfo(self, ContextInfo.DeviceCount, out error); if (UnityCL.IsError(error)) { throw new UnityCLException(error); } var numDevices = numDevicesInfo.CastTo <int>(); var devicesInfo = OpenCL.Net.Cl.GetContextInfo(self, ContextInfo.Devices, out error); if (UnityCL.IsError(error)) { throw new UnityCLException(error); } var devices = devicesInfo.CastToArray <Device>(numDevices); return(devices); }
/// <summary> /// Executes full logic for getting CL Context on Linux platforms. /// Untested. May need updating to work like windows version. /// </summary> /// <returns>The get CL shared context.</returns> public static Context LinuxGetCLSharedContext(Platform p) { ErrorCode error; var glxContext = LinuxGetCurrentGLXContext(); var glxDisplay = LinuxGetCurrentGLXDisplay(); uint[] properties = new uint[] { (uint)cl_gl_ContextProperties.CL_GL_CONTEXT_KHR, (uint)(glxContext as IHandleData).Handle.ToInt32(), (uint)cl_gl_ContextProperties.CL_GLX_DISPLAY_KHR, (uint)(glxDisplay as IHandleData).Handle.ToInt32(), (uint)ContextProperties.Platform, (uint)(p as IHandleData).Handle.ToInt32(), 0 }; Device[] devices; uint retSize; error = clGetGLContextInfoKHR(properties, cl_gl_ContextInfo.CL_DEVICES_FOR_GL_CONTEXT_KHR, 32, out devices, out retSize); if (UnityCL.IsError(error)) { throw new UnityCLException(error); } var context = new Context(clCreateContext(properties, (uint)devices.Length, devices, null, IntPtr.Zero, out error)); if (UnityCL.IsError(error)) { throw new UnityCLException(error); } return(context); }