コード例 #1
1
ファイル: ComputeContext.cs プロジェクト: PtrMan/ai2
        public void initialize()
        {
            ErrorCode errorCode;

            // http://www.codeproject.com/Articles/502829/GPGPU-image-processing-basics-using-OpenCL-NET
            // license  The Code Project Open License (CPOL)
            // snip ===

            OpenCL.Net.Platform[] platforms = Cl.GetPlatformIDs(out errorCode);
            if (errorCode != ErrorCode.Success)
            {
                throw new OpenClError();
            }

            List<OpenCL.Net.Device> devicesList = new List<OpenCL.Net.Device>();

            foreach (OpenCL.Net.Platform platform in platforms)
            {
                string platformName = Cl.GetPlatformInfo(platform, OpenCL.Net.PlatformInfo.Name, out errorCode).ToString();
                if (errorCode != ErrorCode.Success)
                {
                    throw new OpenClError();
                }

                Console.WriteLine("Platform: " + platformName);

                //We will be looking only for GPU devices
                foreach (OpenCL.Net.Device device in Cl.GetDeviceIDs(platform, OpenCL.Net.DeviceType.Gpu, out errorCode))
                {
                    if (errorCode != ErrorCode.Success)
                    {
                        throw new OpenClError();
                    }

                    Console.WriteLine("Device: " + device.ToString());
                    devicesList.Add(device);
                }
            }

            if (devicesList.Count <= 0)
            {
                Console.WriteLine("No devices found.");
                throw new OpenClError();
            }

            chosenDevice = devicesList[1];
            // end snip ===

            context = Cl.CreateContext(null, 1, new Device[] { chosenDevice }, null, IntPtr.Zero, out errorCode);
            if (errorCode != ErrorCode.Success)
            {
                throw new OpenClError();
            }

            commandQueue = Cl.CreateCommandQueue(context, chosenDevice, CommandQueueProperties.OutOfOrderExecModeEnable, out errorCode);
            if (errorCode != ErrorCode.Success)
            {
                throw new OpenClError();
            }
        }
コード例 #2
0
ファイル: OpenCL.cs プロジェクト: fsps60312/AutoStitch
        private static void Setup()
        {
            if (!setuped)
            {
                setuped = true;
                CL.ErrorCode     error;
                CL.Platform[]    platforms   = CL.Cl.GetPlatformIDs(out error);
                List <CL.Device> devicesList = new List <CL.Device>();

                CheckErr(error, "Cl.GetPlatformIDs");

                foreach (CL.Platform platform in platforms)
                {
                    string platformName = CL.Cl.GetPlatformInfo(platform, CL.PlatformInfo.Name, out error).ToString();
                    Console.WriteLine("Platform: " + platformName);
                    CheckErr(error, "Cl.GetPlatformInfo");
                    //We will be looking only for GPU devices
                    foreach (CL.Device device in CL.Cl.GetDeviceIDs(platform, CL.DeviceType.Gpu, out error))
                    {
                        CheckErr(error, "Cl.GetDeviceIDs");
                        Console.WriteLine("Device: " + device.ToString());
                        devicesList.Add(device);
                    }
                }

                if (devicesList.Count <= 0)
                {
                    Console.WriteLine("No devices found.");
                    return;
                }
                Console.WriteLine($"found {devicesList.Count} device(s)");
                foreach (var device in devicesList)
                {
                    var buffer = CL.Cl.GetDeviceInfo(device, CL.DeviceInfo.Name, out error);
                    CheckErr(error, "Cl.GetDeviceInfo");
                    Console.WriteLine($"\t{buffer}");
                }

                _device = devicesList[0];

                if (CL.Cl.GetDeviceInfo(_device, CL.DeviceInfo.ImageSupport,
                                        out error).CastTo <CL.Bool>() == CL.Bool.False)
                {
                    Console.WriteLine("No image support.");
                    return;
                }
                _context = CL.Cl.CreateContext(null, 1, new[] { _device }, ContextNotify, IntPtr.Zero, out error);    //Second parameter is amount of devices
                CheckErr(error, "Cl.CreateContext");
            }
        }
コード例 #3
0
        public CommandQueue(ComputeProvider provider, ClNet.Device device, bool outOfOrderExecution = false)
        {
            ClNet.ErrorCode error;
            _queue = Cl.CreateCommandQueue
                         (provider.Context
                         , device
                         , outOfOrderExecution
                    ? ClNet.CommandQueueProperties.OutOfOrderExecModeEnable
                    : ClNet.CommandQueueProperties.None, out error);

            if (error != ClNet.ErrorCode.Success)
            {
                throw new Cl.Exception(error);
            }
        }
コード例 #4
0
        private void Setup()
        {
            Cl.Platform[]    platforms   = Cl.Cl.GetPlatformIDs(out _error);
            List <Cl.Device> devicesList = new List <Cl.Device>();

            CheckErr(_error, "Cl.GetPlatformIDs");

            foreach (Cl.Platform platform in platforms)
            {
                string platformName = Cl.Cl.GetPlatformInfo(platform, Cl.PlatformInfo.Name, out _error).ToString();
                Console.WriteLine("Platform: " + platformName);
                CheckErr(_error, "Cl.GetPlatformInfo");

                foreach (Cl.Device device in Cl.Cl.GetDeviceIDs(platform, Cl.DeviceType.All, out _error))
                {
                    CheckErr(_error, "Cl.GetDeviceIDs");
                    Console.WriteLine("Device: " + device.ToString());
                    devicesList.Add(device);
                }
            }

            if (devicesList.Count <= 0)
            {
                Console.WriteLine("No devices found.");
                return;
            }

            foreach (var device in devicesList)
            {
                var type = Cl.Cl.GetDeviceInfo(device, Cl.DeviceInfo.Type, out _error).CastTo <Cl.DeviceType>();
                CheckErr(_error, "Cl.GetDeviceIDs");

                //We will be looking only for GPU devices in Release mode
#if DEBUG
                if (type == Cl.DeviceType.Cpu)
#else
                if (type == Cl.DeviceType.Gpu)
#endif
                {
                    _device = device;
                    break;
                }
            }

            _context = Cl.Cl.CreateContext(null, 1, new[] { _device }, ContextNotify, IntPtr.Zero, out _error);    //Second parameter is amount of devices
            CheckErr(_error, "Cl.CreateContext");
        }
コード例 #5
0
        private void Setup()
        {
            Cl.ErrorCode     error;
            Cl.Platform[]    platforms   = Cl.Cl.GetPlatformIDs(out error);
            List <Cl.Device> devicesList = new List <Cl.Device>();

            CheckErr(error, "Cl.GetPlatformIDs");

            foreach (Cl.Platform platform in platforms)
            {
                string platformName = Cl.Cl.GetPlatformInfo(platform, Cl.PlatformInfo.Name, out error).ToString();
                Console.WriteLine("Platform: " + platformName);
                CheckErr(error, "Cl.GetPlatformInfo");

                //We will be looking only for GPU devices in Release mode
#if DEBUG
                foreach (Cl.Device device in Cl.Cl.GetDeviceIDs(platform, Cl.DeviceType.Cpu, out error))
#else
                foreach (Cl.Device device in Cl.Cl.GetDeviceIDs(platform, Cl.DeviceType.Gpu, out error))
#endif
                {
                    CheckErr(error, "Cl.GetDeviceIDs");
                    Console.WriteLine("Device: " + device.ToString());
                    devicesList.Add(device);
                }
            }

            if (devicesList.Count <= 0)
            {
                Console.WriteLine("No devices found.");
                return;
            }

            _device = devicesList[0];

            if (Cl.Cl.GetDeviceInfo(_device, Cl.DeviceInfo.ImageSupport,
                                    out error).CastTo <Cl.Bool>() == Cl.Bool.False)
            {
                Console.WriteLine("No image support.");
                return;
            }
            _context = Cl.Cl.CreateContext(null, 1, new[] { _device }, ContextNotify, IntPtr.Zero, out error);    //Second parameter is amount of devices
            CheckErr(error, "Cl.CreateContext");
        }
コード例 #6
0
        private void Setup()
        {
            Cl.ErrorCode error;
            Cl.Platform[] platforms = Cl.Cl.GetPlatformIDs(out error);
            List<Cl.Device> devicesList = new List<Cl.Device>();

            CheckErr(error, "Cl.GetPlatformIDs");

            foreach (Cl.Platform platform in platforms)
            {
                string platformName = Cl.Cl.GetPlatformInfo(platform, Cl.PlatformInfo.Name, out error).ToString();
                Console.WriteLine("Platform: " + platformName);
                CheckErr(error, "Cl.GetPlatformInfo");

                //We will be looking only for GPU devices in Release mode
            #if DEBUG
                foreach (Cl.Device device in Cl.Cl.GetDeviceIDs(platform, Cl.DeviceType.Cpu, out error))
            #else
                foreach (Cl.Device device in Cl.Cl.GetDeviceIDs(platform, Cl.DeviceType.Gpu, out error))
            #endif
                {
                    CheckErr(error, "Cl.GetDeviceIDs");
                    Console.WriteLine("Device: " + device.ToString());
                    devicesList.Add(device);
                }
            }

            if (devicesList.Count <= 0)
            {
                Console.WriteLine("No devices found.");
                return;
            }

            _device = devicesList[0];

            if (Cl.Cl.GetDeviceInfo(_device, Cl.DeviceInfo.ImageSupport,
                      out error).CastTo<Cl.Bool>() == Cl.Bool.False)
            {
                Console.WriteLine("No image support.");
                return;
            }
            _context = Cl.Cl.CreateContext(null, 1, new[] { _device }, ContextNotify, IntPtr.Zero, out error);    //Second parameter is amount of devices
            CheckErr(error, "Cl.CreateContext");
        }