コード例 #1
0
        public ClRuntimeInterface(ClDeviceIndex targetDeviceIndex, string programText)
        {
            status = Status.NotInitialized;

            SetupDevice(targetDeviceIndex);
            SetupContext();
            SetupCommandQueue();
            SetupKernel(programText);
            IsErrorOccurred();
        }
コード例 #2
0
        public Form1()
        {
            InitializeComponent();
            FormClosed += Form1_FormClosed;

            //Set ComboBox
            foreach (MaskingFormat f in (MaskingFormat[])Enum.GetValues(typeof(MaskingFormat)))
            {
                comboBox_maskFormat.Items.Add(f.ToString());
            }

            foreach (SpacingCharacter c in (SpacingCharacter[])Enum.GetValues(typeof(SpacingCharacter)))
            {
                comboBox_spacingChar.Items.Add(c.ToString());
            }


            Initialize();
            //Load config
            ClDeviceIndex targetDeviceIndex = ConfigManager.LoadConfig(CONFIG_FILENAME);

            if (targetDeviceIndex.Platform == -1 || targetDeviceIndex.Device == -1)
            {
                //Reset config if config is missing
                ConfigManager.RemoveConfig(CONFIG_FILENAME);
                targetDeviceIndex = ConfigManager.LoadConfig(CONFIG_FILENAME);
            }

            //Validate device
            if (!ClDeviceManager.ValidateDevice(targetDeviceIndex))
            {
                //Reset config if config is not valid
                ConfigManager.RemoveConfig(CONFIG_FILENAME);
                targetDeviceIndex = ConfigManager.LoadConfig(CONFIG_FILENAME);

                //If device is not valide, force close.
                if (!ClDeviceManager.ValidateDevice(targetDeviceIndex))
                {
                    MessageBox.Show("Target device is not valid."
                                    + Environment.NewLine + "Check config.cfg and try other options.");
                    this.Load += (s, e) => Close();
                }
            }

            //Setup OpenCL device
            imageProcessor = new ImageProcessor(targetDeviceIndex, LoadProgramText());

            if (!imageProcessor.IsReady)
            {
                this.Load += (s, e) => Close();
            }
        }
コード例 #3
0
        //Device validation
        public static bool ValidateDevice(ClDeviceIndex targetDeviceIndex)
        {
            int platformIndex = targetDeviceIndex.Platform;
            int deviceIndex   = targetDeviceIndex.Device;

            //Default platform
            if (platformIndex == 0)
            {
                platformIndex = 1;
            }

            //PlatformIndex out of range
            Platform[] platformList = GetPlatform(out ErrorCode error);
            if (platformList.Length < platformIndex)
            {
                return(false);
            }


            Device targetDevice;

            if (deviceIndex == 0)
            {
                //Default device
                targetDevice = GetDefaultDevice(platformList[platformIndex - 1], out error);
            }
            else
            {
                //DeviceIndex out of range
                Device[] deviceList = GetDevice(platformList[platformIndex - 1], out error);
                if (deviceList.Length < deviceIndex)
                {
                    return(false);
                }

                targetDevice = deviceList[deviceIndex - 1];
            }

            //Check DeviceInfo
            bool deviceIsAvailable = CheckAvailable(targetDevice, out error) &&
                                     CheckComplilerAvailable(targetDevice, out error) &&
                                     CheckImageSupport(targetDevice, out error);

            //Check error
            return((error == ErrorCode.Success) && deviceIsAvailable);
        }
コード例 #4
0
        private void SetupDevice(ClDeviceIndex targetDeviceIndex)
        {
            int platformIndex = targetDeviceIndex.Platform;
            int deviceIndex   = targetDeviceIndex.Device;

            //Get platform
            Platform targetPlatform;

            if (platformIndex == 0)
            {
                targetPlatform = ClDeviceManager.GetPlatform(out error)[0];
            }
            else
            {
                targetPlatform = ClDeviceManager.GetPlatform(out error)[platformIndex - 1];
            }

            //Check error
            if (IsErrorOccurred())
            {
                return;
            }

            //Get device
            if (deviceIndex == 0)
            {
                device = ClDeviceManager.GetDefaultDevice(targetPlatform, out error);
            }
            else
            {
                device = ClDeviceManager.GetDevice(targetPlatform, out error)[deviceIndex - 1];
            }

            //Device is ready
            if (!IsErrorOccurred())
            {
                status ^= Status.DeviceNotReady;
            }
        }
コード例 #5
0
 public ImageProcessor(ClDeviceIndex targetDeviceIndex, string programText)
     : base(targetDeviceIndex, programText)
 {
 }