Esempio 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);
            }
        }
Esempio n. 2
0
        private void initializeRandomData(int iterationCount, int nodeCount)
        {
            var random = GPGPURAND.Create(this._gpu);

            random.GenerateSeeds();

            // We need 2 random per contraction, we have nodeCount - 2 contraction per graph,
            // and we do that for each iteration
            // Just, to ease index calculation, we compute nodeCount pairs instead of nodeCount - 2
            this._random_dev = this._gpu.Allocate <uint>(nodeCount * iterationCount * 2);
            random.Generate(this._random_dev, 1);
        }
Esempio n. 3
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();
        }
Esempio n. 4
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();
        }