public OpenCLMiner(OpenCLManager OCLMan, Vendor vendor, int deviceIndex, bool shouldUseVectors)
        {
            this.vendor = vendor;
            this.deviceIndex = deviceIndex;

            this.OCLMan = OCLMan;
            Device device = OCLMan.Context.Devices[deviceIndex];
            Name = device.Vendor + ":" + device.Name + " (" + deviceIndex + ")";

            OCLMan.Defines += "\r\n#define OUTPUT_SIZE 256";
            OCLMan.Defines += "\r\n#define OUTPUT_MASK 255";
            if (device.Extensions.Contains("cl_amd_media_ops"))
            {
                OCLMan.Defines += "\r\n#define BITALIGN 1";
                // note: defining BFI_INT resulted in invalid calculations on my Barts (8760)
                //if (Array.IndexOf(AMD_Devices, device.Name) != -1)
                //    OCLMan.Defines += "\r\n#define BFI_INT 1";
            }

            if (shouldUseVectors)
                OCLMan.Defines += "\r\n#define VECTORS 1";
            _shouldUseVectors = shouldUseVectors;

            searchKernel = OCLMan.CompileFile("General.cl").CreateKernel("search");

            unsafe
            {
                IntPtr size = (IntPtr)8;
                long[] values = new long[1];
                long[] sizeTest = new long[1];

                fixed (long* valuep = &values[0])
                {
                    IntPtr sizeOuts;

                    OpenCL.GetKernelWorkGroupInfo(searchKernel.KernelID, device.DeviceID, KernelWorkGroupInfo.WORK_GROUP_SIZE, size, (void*)valuep, out sizeOuts);
                    workGroupSize = (uint)values[0];
                }
            }

            unit = workGroupSize * 256u;
            globalThreads = (uint)(unit * 10);
            Initialized = true;
        }
Exemplo n.º 2
0
        private void InitializeOpenCL()
        {
            if (OpenCL.NumberOfPlatforms == 0)
            {
                MessageBox.Show("OpenCL не поддерживается вашей системой!");
                Application.Exit();
            }

            manager = new OpenCLManager();
            manager.AttemptUseBinaries = true;
            manager.AttemptUseSource = true;
            manager.RequireImageSupport = false;
            manager.BuildOptions = "";

            manager.CreateDefaultContext(0, DeviceType.ALL);

            // Компиляция OpenCL кода
            program = manager.CompileSource(Properties.Resources.DVR);
            kernel = program.CreateKernel("DVR");
        }
Exemplo n.º 3
0
 /* Создает новый объем размера size*size*size */
 public VoxelVolume(int size, OpenCLManager openClManager)
 {
     data         = new short[size * size * size];
     size_this    = size;
     manager_this = openClManager;
 }
Exemplo n.º 4
0
		public unsafe void InitTasks()
		{
			bool doMidside = channels == 2 && eparams.do_midside;
			int channelCount = doMidside ? 2 * channels : channels;

			if (!inited)
			{
				if (OpenCL.NumberOfPlatforms < 1)
					throw new Exception("no opencl platforms found");

				int groupSize = _settings.DeviceType == OpenCLDeviceType.CPU ? 1 : _settings.GroupSize;
				OCLMan = new OpenCLManager();
				// Attempt to save binaries after compilation, as well as load precompiled binaries
				// to avoid compilation. Usually you'll want this to be true. 
				OCLMan.AttemptUseBinaries = true; // true;
				// Attempt to compile sources. This should probably be true for almost all projects.
				// Setting it to false means that when you attempt to compile "mysource.cl", it will
				// only scan the precompiled binary directory for a binary corresponding to a source
				// with that name. There's a further restriction that the compiled binary also has to
				// use the same Defines and BuildOptions
				OCLMan.AttemptUseSource = true;
				// Binary and source paths
				// This is where we store our sources and where compiled binaries are placed
				//OCLMan.BinaryPath = @"OpenCL\bin";
				//OCLMan.SourcePath = @"OpenCL\src";
				// If true, RequireImageSupport will filter out any devices without image support
				// In this project we don't need image support though, so we set it to false
				OCLMan.RequireImageSupport = false;
				// The BuildOptions string is passed directly to clBuild and can be used to do debug builds etc
				OCLMan.BuildOptions = "";
				OCLMan.SourcePath = System.IO.Path.GetDirectoryName(GetType().Assembly.Location);
				OCLMan.BinaryPath = System.IO.Path.Combine(System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "CUE Tools"), "OpenCL");
				int platformId = 0;
				if (_settings.Platform != null)
				{
					platformId = -1;
					string platforms = "";
					for (int i = 0; i < OpenCL.NumberOfPlatforms; i++)
					{
						var platform = OpenCL.GetPlatform(i);
						platforms += " \"" + platform.Name + "\"";
						if (platform.Name.Equals(_settings.Platform, StringComparison.InvariantCultureIgnoreCase))
						{
							platformId = i;
							break;
						}
					}
					if (platformId < 0)
						throw new Exception("unknown platform \"" + _settings.Platform + "\". Platforms available:" + platforms);
				}
				OCLMan.CreateDefaultContext(platformId, (DeviceType)_settings.DeviceType);

				this.framesPerTask = (int)OCLMan.Context.Devices[0].MaxComputeUnits * Math.Max(1, _settings.TaskSize / channels);

				bool UseGPUOnly = _settings.GPUOnly && OCLMan.Context.Devices[0].Extensions.Contains("cl_khr_local_int32_extended_atomics");
				bool UseGPURice = UseGPUOnly && _settings.DoRice;

				if (_blocksize == 0)
				{
					if (eparams.block_size == 0)
						eparams.block_size = select_blocksize(sample_rate, eparams.block_time_ms);
					_blocksize = eparams.block_size;
				}
				else
					eparams.block_size = _blocksize;

				int maxBS = 1 << (BitReader.log2i(eparams.block_size - 1) + 1);

				// The Defines string gets prepended to any and all sources that are compiled
				// and serve as a convenient way to pass configuration information to the compilation process
				OCLMan.Defines =
					"#define MAX_ORDER " + eparams.max_prediction_order.ToString() + "\n" +
					"#define GROUP_SIZE " + groupSize.ToString() + "\n" +
					"#define FLACCL_VERSION \"" + vendor_string + "\"\n" +
					(UseGPUOnly ? "#define DO_PARTITIONS\n" : "") +
					(UseGPURice ? "#define DO_RICE\n" : "") +
					"#define BITS_PER_SAMPLE " + PCM.BitsPerSample + "\n" +
					"#define MAX_BLOCKSIZE " + maxBS + "\n" +
					"#define MAX_CHANNELS " + PCM.ChannelCount + "\n" +
#if DEBUG
					"#define DEBUG\n" +
#endif
					(_settings.DeviceType == OpenCLDeviceType.CPU ? "#define FLACCL_CPU\n" : "") +
					_settings.Defines + "\n";

				var exts = new string[] { "cl_khr_local_int32_base_atomics", "cl_khr_local_int32_extended_atomics", "cl_khr_fp64", "cl_amd_fp64" };
				foreach (string extension in exts)
					if (OCLMan.Context.Devices[0].Extensions.Contains(extension))
					{
						OCLMan.Defines += "#pragma OPENCL EXTENSION " + extension + ": enable\n";
						OCLMan.Defines += "#define HAVE_" + extension + "\n";
					}

				try
				{
					openCLProgram = OCLMan.CompileFile("flac.cl");
				}
				catch (OpenCLBuildException ex)
				{
					string buildLog = ex.BuildLogs[0];
					throw ex;
				}
				//using (Stream kernel = GetType().Assembly.GetManifestResourceStream(GetType(), "flac.cl"))
				//using (StreamReader sr = new StreamReader(kernel))
				//{
				//    try
				//    {
				//        openCLProgram = OCLMan.CompileSource(sr.ReadToEnd()); ;
				//    }
				//    catch (OpenCLBuildException ex)
				//    {
				//        string buildLog = ex.BuildLogs[0];
				//        throw ex;
				//    }
				//}
#if TTTTKJHSKJH
				var openCLPlatform = OpenCL.GetPlatform(0);
				openCLContext = openCLPlatform.CreateDefaultContext();
				using (Stream kernel = GetType().Assembly.GetManifestResourceStream(GetType(), "flac.cl"))
				using (StreamReader sr = new StreamReader(kernel))
					openCLProgram = openCLContext.CreateProgramWithSource(sr.ReadToEnd());
				try
				{
					openCLProgram.Build();
				}
				catch (OpenCLException)
				{
					string buildLog = openCLProgram.GetBuildLog(openCLProgram.Devices[0]);
					throw;
				}
#endif

				if (_IO == null)
					_IO = new FileStream(_path, FileMode.Create, FileAccess.Write, FileShare.Read);
				int header_size = flake_encode_init();
				_IO.Write(header, 0, header_size);
				_totalSize += header_size;
				if (_IO.CanSeek)
					first_frame_offset = _IO.Position;

				task1 = new FLACCLTask(openCLProgram, channelCount, channels, bits_per_sample, max_frame_size, this, groupSize, UseGPUOnly, UseGPURice);
				task2 = new FLACCLTask(openCLProgram, channelCount, channels, bits_per_sample, max_frame_size, this, groupSize, UseGPUOnly, UseGPURice);
				if (_settings.CPUThreads > 0)
				{
					cpu_tasks = new FLACCLTask[_settings.CPUThreads];
					for (int i = 0; i < cpu_tasks.Length; i++)
						cpu_tasks[i] = new FLACCLTask(openCLProgram, channelCount, channels, bits_per_sample, max_frame_size, this, groupSize, UseGPUOnly, UseGPURice);
				}
				inited = true;
			}
		}
Exemplo n.º 5
0
 /* Создает новый объем размера size*size*size */
 public VoxelVolume(int size, OpenCLManager openClManager)
 {
     data = new short[size * size * size];
     size_this = size;
     manager_this = openClManager;
 }
Exemplo n.º 6
0
 private void InitializeOpenCL()
 {
     if (OpenCL.NumberOfPlatforms == 0){
         MessageBox.Show("OpenCL is not supported on your system!");
         Application.Exit();
     }
     manager = new OpenCLManager();
     manager.AttemptUseBinaries = true;
     manager.AttemptUseSource = true;
     manager.RequireImageSupport = false;
     manager.BuildOptions = "";
     manager.CreateDefaultContext(0, DeviceType.ALL);
     // Compiling OpenCL code
     program = manager.CompileSource(Properties.Resources.DVR);
     kernel = program.CreateKernel("DVR");
 }
        public static List<Miner> GetAvailableMiners()
        {
            List<Miner> available = new List<Miner>();

            DeviceType[] types = { DeviceType.GPU }; // DeviceType.CPU prevents GPU from working to full potential... and it makes your CPU hot and a waste of energy
            foreach (DeviceType type in types)
            {

                for (int pf = 0; pf < OpenCL.NumberOfPlatforms; pf++)
                {
                    try
                    {
                        int i = 0;

                        OpenCLManager OCLMan;
                        do
                        {
                            OCLMan = new OpenCLManager();
                            // Attempt to save binaries after compilation, as well as load precompiled binaries
                            // to avoid compilation. Usually you'll want this to be true.
                            OCLMan.AttemptUseBinaries = true;
                            // Attempt to compile sources. This should probably be true for almost all projects.
                            // Setting it to false means that when you attempt to compile "mysource.cl", it will
                            // only scan the precompiled binary directory for a binary corresponding to a source
                            // with that name. There's a further restriction that the compiled binary also has to
                            // use the same Defines and BuildOptions
                            OCLMan.AttemptUseSource = true;
                            // Binary and source paths
                            // This is where we store our sources and where compiled binaries are placed
                            OCLMan.BinaryPath = @"BitcoinMiner\bin";
                            OCLMan.SourcePath = @"BitcoinMiner\src";
                            // If true, RequireImageSupport will filter out any devices without image support
                            // In this project we don't need image support though, so we set it to false
                            OCLMan.RequireImageSupport = false;
                            // The Defines string gets prepended to any and all sources that are compiled
                            // and serve as a convenient way to pass configuration information to the compilation process
                            OCLMan.Defines = "";
                            // The BuildOptions string is passed directly to clBuild and can be used to do debug builds etc
                            OCLMan.BuildOptions = "";

                            OCLMan.CreateDefaultContext(pf, type);

                            string svendor = OCLMan.Context.Devices[i].Vendor;
                            Vendor vendor = Vendor.Unknown;

                            if (svendor == "NVIDIA Corporation")
                                vendor = Vendor.NVidia;
                            else if (svendor == "GenuineIntel")
                                vendor = Vendor.Intel;
                            else if (svendor == "Intel(R) Corporation")
                            {
                                i++;
                                continue;// Dean Gores: for some reason this device causes the thread to get stuck on my computer
                            }
                            else if (svendor == "Advanced Micro Devices, Inc.")
                                vendor = Vendor.AMD;
                            try
                            {
                                available.Add(new OpenCLMiner(OCLMan, vendor, i, false));
                            }
                            catch (Exception e)
                            {
                                //Util.LogException(e, "Miner");
                            }
                            i++;
                        }
                        while (i < OCLMan.Context.Devices.Length);
                    }
                    catch (Exception e)
                    {
                        //Util.LogException(e, "Miner");
                    }
                }
            }
            return available;
        }
Exemplo n.º 8
0
        /// <summary>
        /// Create a OpenCLManager, configure it, and then create a context using all devices in platform 0,
        /// Once the context is up and running we compile our source file "OpenCLFunctions.cl"
        /// The Helper automatically compiles and creates kernels.
        /// We can then extract named kernels using the GetKernel method.
        /// 
        /// For more advanced scenarios, one might use the functions in the Platform class
        /// to query devices, create contexts etc. Platforms can be enumerated using
        /// for( int i=0; i<OpenCL.NumberofPlatforms; i++ )
        ///     Platform p = OpenCL.GetPlatform(i);
        /// </summary>
        private void InitializeOpenCL()
        {
            if (OpenCL.NumberOfPlatforms == 0)
            {
                MessageBox.Show("OpenCL not available");
                Application.Exit();
            }

            OCLMan = new OpenCLManager();
            // Attempt to save binaries after compilation, as well as load precompiled binaries
            // to avoid compilation. Usually you'll want this to be true.
            OCLMan.AttemptUseBinaries = true;
            // Attempt to compile sources. This should probably be true for almost all projects.
            // Setting it to false means that when you attempt to compile "mysource.cl", it will
            // only scan the precompiled binary directory for a binary corresponding to a source
            // with that name. There's a further restriction that the compiled binary also has to
            // use the same Defines and BuildOptions
            OCLMan.AttemptUseSource = true;
            // Binary and source paths
            // This is where we store our sources and where compiled binaries are placed
            OCLMan.BinaryPath = @"OpenCL\bin";
            OCLMan.SourcePath = @"OpenCL\src";
            // If true, RequireImageSupport will filter out any devices without image support
            // In this project we don't need image support though, so we set it to false
            OCLMan.RequireImageSupport = false;
            // The Defines string gets prepended to any and all sources that are compiled
            // and serve as a convenient way to pass configuration information to the compilation process
            OCLMan.Defines = "#define MyCompany_MyProject_Define 1";
            // The BuildOptions string is passed directly to clBuild and can be used to do debug builds etc
            OCLMan.BuildOptions = "";

            OCLMan.CreateDefaultContext(0, DeviceType.ALL);

            OCLProgram = OCLMan.CompileFile("OpenCLFunctions.cl");

            for (int i = 0; i < OCLMan.Context.Devices.Length; i++)
                comboBoxDeviceSelector.Items.Add(OCLMan.Context.Devices[i].Vendor+":"+OCLMan.Context.Devices[i].Name);
            comboBoxDeviceSelector.SelectedIndex = 0;

            CrossFadeKernel = OCLProgram.CreateKernel("CrossFade");
        }