コード例 #1
0
        /// <summary>
        /// Cudafies the specified types. Working directory will be as per CudafyTranslator.WorkingDirectory.
        /// </summary>
        /// <param name="platform">The platform.</param>
        /// <param name="arch">The CUDA or OpenCL architecture.</param>
        /// <param name="cudaVersion">The CUDA version. Specify null to automatically use the highest installed version.</param>
        /// <param name="compile">if set to <c>true</c> compile to PTX.</param>
        /// <param name="types">The types.</param>
        /// <returns>A CudafyModule.</returns>
        public static CudafyModule Cudafy(ePlatform platform, eArchitecture arch, Version cudaVersion, bool compile, params Type[] types)
        {
            var cp = CompilerHelper.Create(ePlatform.Auto, arch, eCudafyCompileMode.Default, WorkingDirectory, GenerateDebug);

            if (!compile)
            {
                cp.CompileMode = eCudafyCompileMode.TranslateOnly;
            }
            return(Cudafy(cp, types));
        }
コード例 #2
0
        public void SetUp()
        {
            //var x = CompilerHelper.Create(ePlatform.x64, eArchitecture.OpenCL, eCudafyCompileMode.Default);
            var y = CompilerHelper.Create(ePlatform.x64, CudafyModes.Architecture, eCudafyCompileMode.DynamicParallelism);

            _cm = CudafyTranslator.Cudafy(new CompileProperties[] { y }, this.GetType());
            Console.WriteLine(_cm.CompilerOutput);
            _cm.Serialize();
            _gpu = CudafyHost.GetDevice(y.Architecture, CudafyModes.DeviceId);
            _gpu.LoadModule(_cm);
        }
コード例 #3
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
            }
        }