Пример #1
0
        public static Context ShareWithCGL(IntPtr cglShareGroup)
        {
            IntPtr[] properties =
            {
                new IntPtr(0x10000000), // CL_CONTEXT_PROPERTY_USE_CGL_SHAREGROUP_APPLE
                cglShareGroup,
                new IntPtr(0)
            };

            CLError error = CLError.None;

            // TODO: Add parameter pfn_notify (logging function)
            CLContext openclContext = OpenCLDriver.clCreateContext(properties, 0, null, null, IntPtr.Zero, ref error);

            OpenCLError.Validate(error);

            SizeT devicesSize = SizeT.Zero;

            OpenCLError.Validate(OpenCLDriver.clGetContextInfo(openclContext, CLContextInfo.Devices, SizeT.Zero, IntPtr.Zero, ref devicesSize));

            CLDeviceID[] devices = new CLDeviceID[((Int64)(devicesSize)) / IntPtr.Size];

            GCHandle devicesHandle = GCHandle.Alloc(devices, GCHandleType.Pinned);

            try
            {
                OpenCLError.Validate(OpenCLDriver.clGetContextInfo(openclContext, CLContextInfo.Devices, devicesSize, devicesHandle.AddrOfPinnedObject(), ref devicesSize));

                Dictionary<CLPlatformID, CLPlatformID> platformsDictionary = new Dictionary<CLPlatformID, CLPlatformID>();

                CLPlatformID[] platforms = null;

                foreach (CLDeviceID device in devices)
                {
                    SizeT platformsSize = SizeT.Zero;

                    OpenCLError.Validate(OpenCLDriver.clGetDeviceInfo(device, CLDeviceInfo.Platform, SizeT.Zero, platforms, ref platformsSize));

                    platforms = new CLPlatformID[((Int64)(platformsSize)) / IntPtr.Size];

                    OpenCLError.Validate(OpenCLDriver.clGetDeviceInfo(device, CLDeviceInfo.Platform, platformsSize, platforms, ref platformsSize));

                    foreach (CLPlatformID platform in platforms)
                    {
                        if (!platformsDictionary.ContainsKey(platform))
                        {
                            platformsDictionary.Add(platform, platform);
                        }
                    }
                }

                platforms = new CLPlatformID[platformsDictionary.Count];

                Int32 index = 0;

                foreach (var platform in platformsDictionary.Keys)
                {
                    platforms[index++] = platform;
                }

                return new Context(openclContext, new Platforms(platforms), new Devices(devices));
            }
            finally
            {
                devicesHandle.Free();
            }
        }
Пример #2
0
 internal static extern CLError clGetProgramBuildInfo(CLProgram program, CLDeviceID device, CLProgramBuildInfo param_name, SizeT param_value_size, IntPtr param_value, ref SizeT param_value_size_ret);
Пример #3
0
 internal static extern CLCommandQueue clCreateCommandQueue(CLContext context, CLDeviceID device, CLCommandQueueProperties properties, ref CLError errcode_ret);
Пример #4
0
 internal static extern CLError clGetDeviceInfo(CLDeviceID device, CLDeviceInfo param_name, SizeT param_value_size, [Out] byte[] param_value, ref SizeT param_value_size_ret);
Пример #5
0
 internal static extern CLError clGetKernelWorkGroupInfo(CLKernel kernel, CLDeviceID device, CLKernelWorkGroupInfo param_name, SizeT param_value_size, IntPtr param_value, ref SizeT param_value_size_ret);
Пример #6
0
 internal static extern CLCommandQueue clCreateCommandQueue(CLContext context, CLDeviceID device, CLCommandQueueProperties properties, ref CLError errcode_ret);
Пример #7
0
 internal static extern CLError clGetProgramBuildInfo(CLProgram program, CLDeviceID device, CLProgramBuildInfo param_name, SizeT param_value_size, IntPtr param_value, ref SizeT param_value_size_ret);
Пример #8
0
 internal static extern CLError clGetKernelWorkGroupInfo(CLKernel kernel, CLDeviceID device, CLKernelWorkGroupInfo param_name, SizeT param_value_size, IntPtr param_value, ref SizeT param_value_size_ret);
Пример #9
0
 internal static extern CLError clGetDeviceInfo(CLDeviceID device, CLDeviceInfo param_name, SizeT param_value_size, [Out] byte[] param_value, ref SizeT param_value_size_ret);
Пример #10
0
        public static Context Share(IntPtr openclContext)
        {
            SizeT devicesSize = SizeT.Zero;

            CLContext clContext = new CLContext { Value = openclContext };

            OpenCLError.Validate(OpenCLDriver.clGetContextInfo(clContext, CLContextInfo.Devices, SizeT.Zero, IntPtr.Zero, ref devicesSize));

            CLDeviceID[] devices = new CLDeviceID[((Int64)(devicesSize)) / IntPtr.Size];

            GCHandle devicesHandle = GCHandle.Alloc(devices, GCHandleType.Pinned);

            try
            {
                OpenCLError.Validate(OpenCLDriver.clGetContextInfo(clContext, CLContextInfo.Devices, devicesSize, devicesHandle.AddrOfPinnedObject(), ref devicesSize));

                Dictionary<CLPlatformID, CLPlatformID> platformsDictionary = new Dictionary<CLPlatformID, CLPlatformID>();

                CLPlatformID[] platforms = null;

                foreach (CLDeviceID device in devices)
                {
                    SizeT platformsSize = SizeT.Zero;

                    OpenCLError.Validate(OpenCLDriver.clGetDeviceInfo(device, CLDeviceInfo.Platform, SizeT.Zero, platforms, ref platformsSize));

                    platforms = new CLPlatformID[((Int64)(platformsSize)) / IntPtr.Size];

                    OpenCLError.Validate(OpenCLDriver.clGetDeviceInfo(device, CLDeviceInfo.Platform, platformsSize, platforms, ref platformsSize));

                    foreach (CLPlatformID platform in platforms)
                    {
                        if (!platformsDictionary.ContainsKey(platform))
                        {
                            platformsDictionary.Add(platform, platform);
                        }
                    }
                }

                platforms = new CLPlatformID[platformsDictionary.Count];

                Int32 index = 0;

                foreach (var platform in platformsDictionary.Keys)
                {
                    platforms[index++] = platform;
                }

                return new Context(clContext, new Platforms(platforms), new Devices(devices));
            }
            finally
            {
                devicesHandle.Free();
            }
        }