Beispiel #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
                    findFirst   = ctx.LoadKernelFatBin(ptx, "FindFirst");   // MY method name from the CUDA kernel
                    parallelFor = ctx.LoadKernelFatBin(ptx, "ParallelFor"); // MY 2nd method name from the CUDA kernel
                }
            }
            return(result);
        }
        internal nvrtcResult LoadKernel(out string log)
        {
            nvrtcResult result;

            using (var rtc = new CudaRuntimeCompiler(File.ReadAllText(path), Path.GetFileName(path)))
            {
                try
                {
                    rtc.Compile(Array.Empty <string>());
                    result = nvrtcResult.Success;
                }
                catch (NVRTCException ex)
                {
                    result = ex.NVRTCError;
                }
                log = rtc.GetLogAsString();

                if (result == nvrtcResult.Success)
                {
                    byte[] ptx = rtc.GetPTX();
                    multiply = ctx.LoadKernelFatBin(ptx, methodName);
                }
            }
            return(result);
        }
Beispiel #3
0
        internal void LoadKernel()
        {
            ctx = new CudaContext(0, true);
            nvrtcResult result;

            using var rtc = new CudaRuntimeCompiler(File.ReadAllText(path), Path.GetFileName(path));
            rtc.Compile(Array.Empty <string>());
            result = nvrtcResult.Success;
            if (result == nvrtcResult.Success)
            {
                byte[] ptx = rtc.GetPTX();
                kernel = ctx.LoadKernelFatBin(ptx, methodName);
            }
        }