Example #1
0
        // note. cannot use TimeSpan here because it ain't work with fractions of milliseconds
        public static ElapsedTime Benchmark(Action action)
        {
            CudaDriver.Ensure();

            var before = CUevent.Null;
            var after  = CUevent.Null;

            try
            {
                before = nvcuda.cuEventCreate(CUevent_flags.Default);
                after  = nvcuda.cuEventCreate(CUevent_flags.Default);

                nvcuda.cuEventRecord(before);
                action();
                nvcuda.cuEventRecord(after);

                nvcuda.cuEventSynchronize(after);
                return(nvcuda.cuEventElapsedTime(before, after));
            }
            finally
            {
                // todo. there's a slight possibility of resource leak here
                if (before.IsNotNull)
                {
                    nvcuda.cuEventDestroy(before);
                }
                if (after.IsNotNull)
                {
                    nvcuda.cuEventDestroy(after);
                }
            }
        }
Example #2
0
        public static Object Invoke(this JittedKernel kernel, dim3 gridDim, dim3 blockDim, IEnumerable <KernelArgument> args)
        {
            kernel.AssertNotNull();
            args = args ?? Seq.Empty <KernelArgument>().ToArray();
            CudaDriver.Ensure();

            return(kernel.Function.Invoke(gridDim, blockDim, args));
        }
Example #3
0
        public static Object Invoke(this JittedFunction function, dim3 gridDim, dim3 blockDim, params KernelArgument[] args)
        {
            function.AssertNotNull();
            args = args ?? Seq.Empty <KernelArgument>().ToArray();
            CudaDriver.Ensure();

            return(function.Invoke(gridDim, blockDim, (IEnumerable <KernelArgument>)args));
        }
Example #4
0
        public static KernelResult Run(this CUfunction function, dim3 gridDim, dim3 blockDim, IEnumerable <KernelArgument> args)
        {
            function.IsNotNull.AssertTrue();
            args = args ?? Seq.Empty <KernelArgument>().ToArray();
            CudaDriver.Ensure();

            return(new JittedFunction(function).Run(gridDim, blockDim, args));
        }
Example #5
0
        public static KernelResult Run(this JittedKernel kernel, dim3 gridDim, dim3 blockDim, params KernelArgument[] args)
        {
            kernel.AssertNotNull();
            args = args ?? Seq.Empty <KernelArgument>().ToArray();
            CudaDriver.Ensure();

            return(kernel.Function.Run(gridDim, blockDim, args));
        }
Example #6
0
        public static Object Invoke(this CUfunction function, dim3 gridDim, dim3 blockDim, params KernelArgument[] args)
        {
            function.IsNotNull.AssertTrue();
            args = args ?? Seq.Empty <KernelArgument>().ToArray();
            CudaDriver.Ensure();

            return(new JittedFunction(function).Invoke(gridDim, blockDim, args));
        }
Example #7
0
        public static KernelResult Run(this JittedFunction function, dim3 gridDim, dim3 blockDim, IEnumerable <KernelArgument> args)
        {
            function.AssertNotNull();
            args = args ?? Seq.Empty <KernelArgument>().ToArray();
            CudaDriver.Ensure();

            var invocation = new KernelInvocation(function, args);

            return(invocation.Launch(gridDim, blockDim));
        }
Example #8
0
        public static JittedKernel JitKernel(this String ptx, dim3 reqntid, HardwareIsa target)
        {
            ptx.AssertNotNull();
            CudaDriver.Ensure();

            var tuning = new JitTuning {
                Reqntid = reqntid
            };

            return(ptx.JitKernel(tuning, target));
        }
Example #9
0
        public static Object Invoke(this JittedFunction function, dim3 gridDim, dim3 blockDim, IEnumerable <KernelArgument> args)
        {
            function.AssertNotNull();
            args = args ?? Seq.Empty <KernelArgument>().ToArray();
            CudaDriver.Ensure();

            var invocation        = new KernelInvocation(function, args);
            var invocation_result = invocation.Launch(gridDim, blockDim);
            var result            = invocation_result.Result;

            args.ForEach(arg => arg.Dispose());
            return(result);
        }
Example #10
0
        public static JittedKernel JitKernel(this String ptx, JitTuning tuning, HardwareIsa target)
        {
            ptx.AssertNotNull();
            CudaDriver.Ensure();

            var compiler = new JitCompiler();

            compiler.Target = target;
            compiler.Tuning = tuning;

            var result = compiler.Compile(ptx);

            return(new JittedKernel(result));
        }
Example #11
0
        public static JittedKernel JitKernel(this String ptx, JitTuning tuning)
        {
            ptx.AssertNotNull();
            CudaDriver.Ensure();

            var compiler = new JitCompiler();

            compiler.TargetFromContext = true;
            compiler.Tuning            = tuning;

            var result = compiler.Compile(ptx);

            return(new JittedKernel(result));
        }