Exemplo n.º 1
0
        private static bool IsInUseForVideoRendering(GPGPUProperties device)
        {
            var name1 = device.Name.Trim();
            var name2 = Renderer.Dx9GpuInfo.Details.Description.Trim();

            return(name1.Contains(name2) || name2.Contains(name1));
        }
Exemplo n.º 2
0
        public void GetCUDACaps(GPGPUProperties prop, TextArea tbGPUCaps)
        {
            int i = 0;

            tbGPUCaps.Text         = "";
            tbGPUCaps.Text        += ((string.Format("   --- General Information for device {0} ---", i) + "\r\n"));
            tbGPUCaps.Text        += ((string.Format("Name:  {0}", prop.Name) + "\r\n"));
            tbGPUCaps.Text        += ((string.Format("Device Id:  {0}", prop.DeviceId) + "\r\n"));
            tbGPUCaps.Text        += ((string.Format("Compute capability:  {0}.{1}", prop.Capability.Major, prop.Capability.Minor) + "\r\n"));
            tbGPUCaps.Text        += ((string.Format("Clock rate: {0}", prop.ClockRate) + "\r\n"));
            tbGPUCaps.Text        += ((string.Format("Simulated: {0}", prop.IsSimulated) + "\r\n"));
            tbGPUCaps.Text        += ((string.Format("   --- Memory Information for device {0} ---", i) + "\r\n"));
            tbGPUCaps.Text        += ((string.Format("Total global mem:  {0}", prop.TotalMemory) + "\r\n"));
            tbGPUCaps.Text        += ((string.Format("Total constant Mem:  {0}", prop.TotalConstantMemory) + "\r\n"));
            tbGPUCaps.Text        += ((string.Format("Max mem pitch:  {0}", prop.MemoryPitch) + "\r\n"));
            tbGPUCaps.Text        += ((string.Format("Texture Alignment:  {0}", prop.TextureAlignment) + "\r\n"));
            tbGPUCaps.Text        += ((string.Format("   --- MP Information for device {0} ---", i) + "\r\n"));
            tbGPUCaps.Text        += ((string.Format("Shared mem per mp: {0}", prop.SharedMemoryPerBlock) + "\r\n"));
            tbGPUCaps.Text        += ((string.Format("Registers per mp:  {0}", prop.RegistersPerBlock) + "\r\n"));
            tbGPUCaps.Text        += ((string.Format("Threads in warp:  {0}", prop.WarpSize) + "\r\n"));
            tbGPUCaps.Text        += ((string.Format("Max threads per block:  {0}", prop.MaxThreadsPerBlock) + "\r\n"));
            tbGPUCaps.Text        += ((string.Format("Max thread dimensions:  ({0}, {1}, {2})", prop.MaxThreadsSize.x, prop.MaxThreadsSize.y, prop.MaxThreadsSize.z) + "\r\n"));
            tbGPUCaps.Text        += ((string.Format("Max grid dimensions:  ({0}, {1}, {2})", prop.MaxGridSize.x, prop.MaxGridSize.y, prop.MaxGridSize.z) + "\r\n"));
            tbGPUCaps.CaretIndex   = 0;
            tbGPUCaps.SelectedText = "";
        }
Exemplo n.º 3
0
        private void initializeGpu()
        {
            var module = CudafyTranslator.Cudafy(ePlatform.x64);

            this._gpu = CudafyHost.GetDevice(eGPUType.Cuda);

            this._gpu.LoadModule(module);
            this._properties = this._gpu.GetDeviceProperties();
        }
Exemplo n.º 4
0
 public static GPGPUProperties getProperties()
 {
     foreach (GPGPUProperties prop in CudafyHost.GetDeviceProperties(CudafyModes.Target))
     {
         gpgpuProperties = prop;
         return(prop);
     }
     return(null);
 }
Exemplo n.º 5
0
        public ProteinDigest(double[] potentialPrecursors, int maxPeptideLength, int minPeptideLength)
        {
            //Init Gpu access
            CudafyModule km = CudafyTranslator.Cudafy();

            gpu = CudafyHost.GetDevice(CudafyModes.Target, CudafyModes.DeviceId);
            gpu.LoadModule(km);
            dev_prec = gpu.CopyToDevice(potentialPrecursors);

            // allocate the memory on the GPU
            GPGPUProperties properties = gpu.GetDeviceProperties();

            this.maxGridSize      = properties.MaxGridSize.x;
            this.maxPeptideSize   = maxPeptideLength;
            this.peptideArraySize = maxPeptideLength - minPeptideLength + 1;
            this.minPeptideSize   = minPeptideLength;
            this.outputStart      = new int[maxGridSize * peptideArraySize];

            //Allocate vector that will store the results
            dev_outputStart = gpu.Allocate <int>(maxGridSize * peptideArraySize);
        }
Exemplo n.º 6
0
        public static String getPropertiesString()
        {
            GPGPUProperties prop = getProperties();

            if (prop == null)
            {
                return("N/A");
            }

            StringBuilder sb = new StringBuilder();

            sb.AppendFormat("   --- General Information for device {0} ---\n", 0);
            sb.AppendFormat("Name:  {0}\n", prop.Name);
            sb.AppendFormat("Platform Name:  {0}\n", prop.PlatformName);
            sb.AppendFormat("Device Id:  {0}\n", prop.DeviceId);
            sb.AppendFormat("Compute capability:  {0}.{1}\n", prop.Capability.Major, prop.Capability.Minor);
            sb.AppendFormat("Clock rate: {0}\n", prop.ClockRate);
            sb.AppendFormat("Simulated: {0}\n", prop.IsSimulated);
            sb.AppendFormat("\n");

            sb.AppendFormat("   --- Memory Information for device {0} ---\n", 0);
            sb.AppendFormat("Total global mem:  {0}\n", prop.TotalMemory);
            sb.AppendFormat("Total constant Mem:  {0}\n", prop.TotalConstantMemory);
            sb.AppendFormat("Max mem pitch:  {0}\n", prop.MemoryPitch);
            sb.AppendFormat("Texture Alignment:  {0}\n", prop.TextureAlignment);
            sb.AppendFormat("\n");

            sb.AppendFormat("   --- MP Information for device {0} ---", 0);
            sb.AppendFormat("Shared mem per mp: {0}\n", prop.SharedMemoryPerBlock);
            sb.AppendFormat("Registers per mp:  {0}\n", prop.RegistersPerBlock);
            sb.AppendFormat("Threads in warp:  {0}\n", prop.WarpSize);
            sb.AppendFormat("Max threads per block:  {0}\n", prop.MaxThreadsPerBlock);
            sb.AppendFormat("Max thread dimensions:  ({0}, {1}, {2})", prop.MaxThreadsSize.x,
                            prop.MaxThreadsSize.y, prop.MaxThreadsSize.z);
            sb.AppendFormat("Max grid dimensions:  ({0}, {1}, {2})", prop.MaxGridSize.x, prop.MaxGridSize.y,
                            prop.MaxGridSize.z);

            return(sb.ToString());
        }
Exemplo n.º 7
0
        private void InitializeGPUs()
        {
            eGPUType[]  gpuTypes  = new eGPUType[] { eGPUType.Cuda, eGPUType.OpenCL, eGPUType.Emulator };
            eLanguage[] languages = new eLanguage[] { eLanguage.Cuda, eLanguage.OpenCL };

            foreach (eGPUType gpuType in gpuTypes)
            {
                try
                {
                    int numberOfAvailableDevices = CudafyHost.GetDeviceCount(gpuType);

                    for (int deviceNumber = 0; deviceNumber < numberOfAvailableDevices; deviceNumber++)
                    {
                        GPGPU           gpgpu           = CudafyHost.GetDevice(gpuType, deviceNumber);
                        GPGPUProperties gpgpuProperties = gpgpu.GetDeviceProperties(true);
                        CudafyModes.Target = gpuType;

                        foreach (eLanguage language in languages)
                        {
                            string cudaRandomFilename = Path.GetRandomFileName();

                            try
                            {
                                CudafyTranslator.Language = language;

                                CompileProperties compileProperties = CompilerHelper.Create(ePlatform.Auto, eArchitecture.Unknown, eCudafyCompileMode.Default, CudafyTranslator.WorkingDirectory, CudafyTranslator.GenerateDebug);

                                // Use a random filename to prevent conflict on default temp file when multithreading (unit tests)
                                compileProperties.InputFile = cudaRandomFilename;

                                // If this line fails with NCrunch/Unit tests, there probably is a new version of Cudafy.NET
                                // and it needs to be registered in the GAC like this: gacutil -i Cudafy.NET.dll
                                CudafyModule cudafyModule = CudafyTranslator.Cudafy(compileProperties, typeof(Primitives));

                                if (!gpgpu.IsModuleLoaded(cudafyModule.Name))
                                {
                                    gpgpu.LoadModule(cudafyModule);
                                }

                                gpgpu.EnableMultithreading();

                                string gpuName = gpgpuProperties.Name.Trim() + " - " + gpuType.ToString() + " - " + language.ToString();

                                ////this.gpgpus.Add(gpuName, gpgpu);
                                ////this.gpgpuProperties.Add(gpuName, gpgpuProperties);
                                ////this.gpuTypes.Add(gpuName, gpuType);
                            }
                            catch (CudafyCompileException)
                            {
                                // Language not supported
                            }
                            finally
                            {
                                File.Delete(cudaRandomFilename);

                                // ncrunch: no coverage start
                            }
                        }
                    }
                }
                catch (DllNotFoundException)
                {
                }
                catch (InvalidOperationException)
                {
                    // Language not supported
                }
                catch (Cloo.ComputeException)
                {
                    // Language not supported
                } // ncrunch: no coverage end
            }
        }
        public static int Execute()
        {
            CudafyModule km = CudafyTranslator.Cudafy();

            GPGPU gpu = CudafyHost.GetDevice(CudafyModes.Target, CudafyModes.DeviceId);

            if (gpu is CudaGPU && gpu.GetDeviceProperties().Capability < new Version(1, 2))
            {
                Console.WriteLine("Compute capability 1.2 or higher required for atomics.");
                return(-1);
            }
            gpu.LoadModule(km);

            byte[] buffer = big_random_block(SIZE);

            // cudart.dll must be accessible!
            GPGPUProperties prop = null;

            try
            {
                prop = gpu.GetDeviceProperties(true);
            }
            catch (DllNotFoundException)
            {
                prop = gpu.GetDeviceProperties(false);
            }

            // capture the start time
            // starting the timer here so that we include the cost of
            // all of the operations on the GPU.  if the data were
            // already on the GPU and we just timed the kernel
            // the timing would drop from 74 ms to 15 ms.  Very fast.
            gpu.StartTimer();

            // allocate memory on the GPU for the file's data
            byte[] dev_buffer = gpu.CopyToDevice(buffer);
            uint[] dev_histo  = gpu.Allocate <uint>(256);
            gpu.Set(dev_histo);

            // kernel launch - 2x the number of mps gave best timing
            int blocks = prop.MultiProcessorCount;

            if (blocks == 0)
            {
                blocks = 16;
            }
            Console.WriteLine("Processors: {0}", blocks);
            gpu.Launch(blocks * 2, 256).histo_kernel(dev_buffer, SIZE, dev_histo);

            uint[] histo = new uint[256];
            gpu.CopyFromDevice(dev_histo, histo);

            // get stop time, and display the timing results
            float elapsedTime = gpu.StopTimer();

            Console.WriteLine("Time to generate: {0} ms", elapsedTime);

            long histoCount = 0;

            for (int i = 0; i < 256; i++)
            {
                histoCount += histo[i];
            }
            Console.WriteLine("Histogram Sum:  {0}", histoCount);

            // verify that we have the same counts via CPU
            for (int i = 0; i < SIZE; i++)
            {
                histo[buffer[i]]--;
            }
            for (int i = 0; i < 256; i++)
            {
                if (histo[i] != 0)
                {
                    Console.WriteLine("Failure at {0}!", i);
                }
            }

            gpu.FreeAll();

            return(0);
        }
Exemplo n.º 9
0
        // PFAC Algorithm Engine
        public Engine(int GPUid, int coreCount, byte[][] target, byte[][] targetEnd, int[][] lookup, uint size)
        {
            this.GPUid = GPUid;
            gpu        = CudafyHost.GetDevice(CudafyModes.Target, GPUid);
            gpu.SetCurrentContext();
            gpu.FreeAll();
            LoadModule();

            gpu.EnableMultithreading();
            for (int i = 0; i < gpuCoreCount; i++)
            {
                gpu.CreateStream(i);
            }

            gpuThreadLock = new object[coreCount];
            for (int i = 0; i < gpuThreadLock.Length; i++)
            {
                gpuThreadLock[i] = new Object();
            }

            prop         = gpu.GetDeviceProperties();
            gpuCoreCount = coreCount;
            chunkSize    = size;
            // Find out maximum GPU Blocks and Supported Threads for each Block
            gpuBlocks         = prop.WarpSize;
            gpuOperatingCores = gpuBlocks;
            blockThreads      = prop.MaxThreadsPerBlock;
            blockSize         = Math.Min(blockThreads, (int)Math.Ceiling(chunkSize / (float)blockThreads)); //Find the optimum size of the threads to handle the buffer

            //MessageBox.Show("GPU Blocks: " + gpuBlocks.ToString() + Environment.NewLine + "Block Threads: " + blockThreads.ToString() + Environment.NewLine + "Block Size: " + blockSize.ToString());

            int[,] newLookup = new int[lookup.Length, 256];
            for (int x = 0; x < lookup.Length; x++)
            {
                for (int y = 0; y < 256; y++)
                {
                    newLookup[x, y] = lookup[x][y];
                }
            }
            dev_lookup = new int[lookup.Length, 256];
            dev_lookup = gpu.CopyToDevice <int>(newLookup);

            int[] targetEndLength = new int[targetEnd.Length];
            for (int x = 0; x < targetEndLength.Length; x++)
            {
                if (targetEnd[x] != null)
                {
                    targetEndLength[x] = targetEnd[x].Length;
                }
            }
            dev_targetEndLength = new int[targetEnd.Length];
            dev_targetEndLength = gpu.CopyToDevice <int>(targetEndLength);

            initialState = target.Length + 1;
            bufferSize   = chunkSize;

            // Allocate the memory on the GPU for buffer and results
            dev_buffer      = new byte[gpuCoreCount][];
            dev_resultCount = new int[gpuCoreCount][];
            resultCount     = new int[gpuCoreCount][];

            dev_foundCount = new int[gpuCoreCount][];
            dev_foundID    = new byte[gpuCoreCount][];
            dev_foundLoc   = new int[gpuCoreCount][];
            foundID        = new byte[gpuCoreCount][];
            foundLoc       = new int[gpuCoreCount][];

            for (int i = 0; i < gpuCoreCount; i++)
            {
                dev_buffer[i]      = gpu.Allocate <byte>(new byte[chunkSize]);
                dev_resultCount[i] = gpu.Allocate <int>(new int[target.Length]);
                resultCount[i]     = new int[target.Length];

                dev_foundCount[i] = gpu.Allocate <int>(new int[1]);
                dev_foundID[i]    = gpu.Allocate <byte>(new byte[resultCache]);
                dev_foundLoc[i]   = gpu.Allocate <int>(new int[resultCache]);
                foundID[i]        = new byte[resultCache];
                foundLoc[i]       = new int[resultCache];
                FreeBuffers(i);
            }
        }