Exemple #1
0
        internal ManagedCuda.NVRTC.nvrtcResult LoadKernel(out string log)
        {
            string path = "MyKernels.c";

            ManagedCuda.NVRTC.nvrtcResult result;
            using (var rtc = new ManagedCuda.NVRTC.CudaRuntimeCompiler(File.ReadAllText(path), Path.GetFileName(path)))
            {
                try
                {
                    rtc.Compile(new string[0]); // see http://docs.nvidia.com/cuda/nvrtc/index.html for usage and options
                    result = ManagedCuda.NVRTC.nvrtcResult.Success;
                } catch (ManagedCuda.NVRTC.NVRTCException ex)
                {
                    result = ex.NVRTCError;
                }
                log = rtc.GetLogAsString();

                if (result == ManagedCuda.NVRTC.nvrtcResult.Success)
                {
                    byte[] ptx = rtc.GetPTX();
                    multiply = ctx.LoadKernelFatBin(ptx, "Multiply"); // hard-coded method name from the CUDA kernel
                }
            }
            return(result);
        }
        private byte[] DoCompile(string fullSource)
        {
            var rtc = new ManagedCuda.NVRTC.CudaRuntimeCompiler(fullSource, null);

            try
            {
                rtc.Compile(new string[0]);
            }
            catch
            {
                throw new ApplicationException("Error compiling CUDA code: " + rtc.GetLogAsString());
            }

            return(rtc.GetPTX());
        }
Exemple #3
0
        private byte[] DoCompile(string fullSource)
        {
            ManagedCuda.NVRTC.CudaRuntimeCompiler rtc = new ManagedCuda.NVRTC.CudaRuntimeCompiler(fullSource, null);

            try
            {
                if (m_options == null || m_options.Length == 0)
                {
                    rtc.Compile(new string[] { });
                }
                else
                {
                    Logger.WriteLine($"Compiler Options: {string.Join(" ", m_options)}");
                    rtc.Compile(m_options);
                    //rtc.Compile(new string[] { "--use_fast_math", "--gpu-architecture=compute_60" });
                }
            }
            catch
            {
                throw new ApplicationException("Error compiling CUDA code: " + rtc.GetLogAsString());
            }

            return(rtc.GetPTX());
        }