Exemplo n.º 1
0
        public void InitGPU()
        {
            // Work around for bug in Cudafy trying to find the path..
            var os64Bit = Environment.Is64BitOperatingSystem;

            if (os64Bit)
            {
                var dir = Environment.GetEnvironmentVariable("ProgramFiles");
                Environment.SetEnvironmentVariable("ProgramFiles", "C:\\Program Files\\");
                dir = Environment.GetEnvironmentVariable("ProgramFiles");
            }

            if (Gpu == null)
            {
                Gpu = CudafyHost.GetDevice(_gpuType, 0);
                //Blas = GPGPUBLAS.Create(Gpu);
                if (_gpuType == eGPUType.Cuda)
                {
                    Blas = new SharpBLAS(Gpu);
                    Rand = GPGPURAND.Create(Gpu, curandRngType.CURAND_RNG_PSEUDO_DEFAULT);
                    Rand.SetPseudoRandomGeneratorSeed((ulong)RandomHelpers.Next(9999));
                }

                CudafyTranslator.GenerateDebug = true;
                Debug.WriteLine("CUDA workdir = " + CudafyTranslator.WorkingDirectory);
                Console.WriteLine("Recompile module");
                CudafyTranslator.Language = eLanguage.Cuda;
                var km = CudafyTranslator.Cudafy(eArchitecture.sm_30);
                km = CudafyTranslator.Cudafy();
                km.Serialize();
                Gpu.LoadModule(km);
            }
        }
Exemplo n.º 2
0
        public void Test_CURAND_Host_Reference_Example()
        {
            int n = 100;

            float[] hostData = new float[n];

            GPGPURAND gen = GPGPURAND.Create(_gpu, curandRngType.CURAND_RNG_PSEUDO_DEFAULT, true);

            gen.SetPseudoRandomGeneratorSeed(1234);
            gen.GenerateUniform(hostData);

            for (int i = 0; i < n; i++)
            {
                Console.WriteLine(hostData[i]);
            }

            gen.Dispose();
        }
Exemplo n.º 3
0
        public void Test_CURAND_Device_Reference_Example()
        {
            int n = 100;

            float[] devData  = _gpu.Allocate <float>(n);
            float[] hostData = new float[n];

            GPGPURAND gen = GPGPURAND.Create(_gpu, curandRngType.CURAND_RNG_PSEUDO_DEFAULT);

            gen.SetPseudoRandomGeneratorSeed(1234);
            gen.GenerateUniform(devData);

            _gpu.CopyFromDevice(devData, hostData);

            for (int i = 0; i < n; i++)
            {
                Console.WriteLine(hostData[i]);
            }

            gen.Dispose();
        }