Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
 internal void PassInto(KernelInvocation invocation, int offset)
 {
     if (_type.IsCudaPrimitive())
     {
         if (_type.IsInteger())
         {
             (_type == typeof(int) || _type == typeof(uint)).AssertTrue();
             (Direction == ParameterDirection.In).AssertTrue();
             var value = _value.AssertCoerce <uint>();
             nvcuda.cuParamSeti(invocation.Function.Handle, offset, value);
         }
         else if (_type.IsFloatingPoint())
         {
             (_type == typeof(float)).AssertTrue();
             (Direction == ParameterDirection.In).AssertTrue();
             var value = _value.AssertCoerce <float>();
             nvcuda.cuParamSetf(invocation.Function.Handle, offset, value);
         }
         else
         {
             throw AssertionHelper.Fail();
         }
     }
     else if (_type.IsCudaVector())
     {
         (Direction == ParameterDirection.In).AssertTrue();
         nvcuda.cuParamSetv(invocation.Function.Handle, offset, _value);
     }
     else
     {
         if (_type.IsValueType)
         {
             (Direction == ParameterDirection.In).AssertTrue();
             nvcuda.cuParamSetv(invocation.Function.Handle, offset, _value);
         }
         else if (_type.IsClass)
         {
             if (_value.IsArray())
             {
                 nvcuda.cuParamSeti(invocation.Function.Handle, offset, _devicePtr);
             }
             else
             {
                 throw AssertionHelper.Fail();
             }
         }
     }
 }
Ejemplo n.º 3
0
 internal void PassInto(KernelInvocation invocation, int offset)
 {
     if (_type.IsCudaPrimitive())
     {
         if (_type.IsInteger())
         {
             (_type == typeof(int) || _type == typeof(uint)).AssertTrue();
             (Direction == ParameterDirection.In).AssertTrue();
             var value = _value.AssertCoerce<uint>();
             nvcuda.cuParamSeti(invocation.Function.Handle, offset, value);
         }
         else if (_type.IsFloatingPoint())
         {
             (_type == typeof(float)).AssertTrue();
             (Direction == ParameterDirection.In).AssertTrue();
             var value = _value.AssertCoerce<float>();
             nvcuda.cuParamSetf(invocation.Function.Handle, offset, value);
         }
         else
         {
             throw AssertionHelper.Fail();
         }
     }
     else if (_type.IsCudaVector())
     {
         (Direction == ParameterDirection.In).AssertTrue();
         nvcuda.cuParamSetv(invocation.Function.Handle, offset, _value);
     }
     else
     {
         if (_type.IsValueType)
         {
             (Direction == ParameterDirection.In).AssertTrue();
             nvcuda.cuParamSetv(invocation.Function.Handle, offset, _value);
         }
         else if (_type.IsClass)
         {
             if (_value.IsArray())
             {
                 nvcuda.cuParamSeti(invocation.Function.Handle, offset, _devicePtr);
             }
             else
             {
                 throw AssertionHelper.Fail();
             }
         }
     }
 }
Ejemplo n.º 4
0
 internal KernelResult(KernelInvocation invocation, ElapsedTime wallTime)
 {
     _invocation = invocation;
     WallTime    = wallTime;
 }
Ejemplo n.º 5
0
 internal KernelResult(KernelInvocation invocation)
 {
     _invocation = invocation;
 }
Ejemplo n.º 6
0
 public KernelResult Run(dim3 gridDim, dim3 blockDim, IEnumerable<KernelArgument> args)
 {
     var invocation = new KernelInvocation(this, args);
     return invocation.Launch(gridDim, blockDim);
 }
Ejemplo n.º 7
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;
        }