Exemplo n.º 1
0
        public CudaError LaunchKernelWithStreamBinding(
            CudaStream stream,
            CudaKernel kernel,
            RuntimeKernelConfig config,
            IntPtr args,
            IntPtr kernelArgs)
        {
            var binding = stream.BindScoped();

            var result = LaunchKernel(
                kernel.FunctionPtr,
                config.GridDim.X,
                config.GridDim.Y,
                config.GridDim.Z,
                config.GroupDim.X,
                config.GroupDim.Y,
                config.GroupDim.Z,
                config.SharedMemoryConfig.DynamicArraySize,
                stream.StreamPtr,
                args,
                kernelArgs);

            binding.Recover();
            return(result);
        }
Exemplo n.º 2
0
        public CudaError LaunchKernelWithStruct <T>(
            CudaStream stream,
            CudaKernel kernel,
            RuntimeKernelConfig config,
            ref T args,
            int argsSizeInBytes)
            where T : unmanaged
        {
            // Setup object size
            var size = new IntPtr(argsSizeInBytes);

            Debug.Assert(
                argsSizeInBytes <= Interop.SizeOf <T>(),
                "Invalid argument size");

            // Pin object buffer in memory
            fixed(T *pArgs = &args)
            {
                // Setup unmanaged launch configuration for the driver
                var launchConfig = stackalloc void *[5];

                launchConfig[0] = (void *)1; // CU_LAUNCH_PARAM_BUFFER_POINTER
                launchConfig[1] = pArgs;
                launchConfig[2] = (void *)2; // CU_LAUNCH_PARAM_BUFFER_SIZE
                launchConfig[3] = &size;
                launchConfig[4] = (void *)0; // CU_LAUNCH_PARAM_END

                // Use existing launch configuration
                return(LaunchKernelWithStreamBinding(
                           stream,
                           kernel,
                           config,
                           IntPtr.Zero,
                           new IntPtr(launchConfig)));
            }
        }