コード例 #1
0
        public unsafe void do_output_frames(int strideCount)
        {
            task1.strideCount = strideCount;
            if (!task1.UseMappedMemory)
            {
                task1.openCLCQ.EnqueueWriteBuffer(task1.clSamplesBytes, false, 0, sizeof(int) * stride * strideCount, task1.clSamplesBytesPtr);
            }
            //task.openCLCQ.EnqueueUnmapMemObject(task.clSamplesBytes, task.clSamplesBytes.HostPtr);
            //task.openCLCQ.EnqueueMapBuffer(task.clSamplesBytes, true, MapFlags.WRITE, 0, task.samplesBufferLen / 2);
            task1.EnqueueKernels();
            if (task2.strideCount > 0)
            {
                task2.openCLCQ.Finish();
            }
            int bs = stride * strideCount;

            samplesInBuffer -= bs;
            if (samplesInBuffer > 0)
            {
                AudioSamples.MemCpy(
                    ((byte *)task2.clSamplesBytesPtr),
                    ((byte *)task1.clSamplesBytesPtr) + bs * _pcm.BlockAlign,
                    samplesInBuffer * _pcm.BlockAlign);
            }
            CLParityTask tmp = task1;

            task1             = task2;
            task2             = tmp;
            task1.strideCount = 0;
        }
コード例 #2
0
        public unsafe void InitTasks()
        {
            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.stridesPerTask = (int)OCLMan.Context.Devices[0].MaxComputeUnits * npar * 8;

                // 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 GROUP_SIZE " + groupSize.ToString() + "\n" +
                    "#define CLPARITY_VERSION \"" + vendor_string + "\"\n" +
#if DEBUG
                    "#define DEBUG\n" +
#endif
                    (_settings.DeviceType == OpenCLDeviceType.CPU ? "#define CLPARITY_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("parity.cl");
                }
                catch (OpenCLBuildException ex)
                {
                    string buildLog = ex.BuildLogs[0];
                    throw ex;
                }
                //using (Stream kernel = GetType().Assembly.GetManifestResourceStream(GetType(), "parity.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(), "parity.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

                task1  = new CLParityTask(openCLProgram, this, groupSize, this.npar, this.stride, this.stridesPerTask);
                task2  = new CLParityTask(openCLProgram, this, groupSize, this.npar, this.stride, this.stridesPerTask);
                inited = true;
            }
        }