Ejemplo n.º 1
0
        /// <summary>
        /// Invokes the specified kernels.
        /// </summary>
        /// <param name="kernels">The kernels.</param>
        /// <param name="context">The context.</param>
        /// <param name="cudaContext">The cuda context.</param>
        /// <param name="result">The result.</param>
        /// <param name="src">The source.</param>
        public static void Invoke(FillCopyKernels kernels, TSCudaContext context, CudaContext cudaContext, NDArray result, NDArray src)
        {
            var ptx          = kernels.GetPtx(context.Compiler);
            var elementCount = result.ElementCount();

            ApplyOpInvoke.Invoke(context, cudaContext, ptx, "copy", result, src, elementCount);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Invokes the specified kernels.
        /// </summary>
        /// <param name="kernels">The kernels.</param>
        /// <param name="result">The result.</param>
        /// <param name="value">The value.</param>
        public static void Invoke(FillCopyKernels kernels, NDArray result, float value)
        {
            var context      = CudaHelpers.TSContextForTensor(result);
            var cudaContext  = context.CudaContextForTensor(result);
            var ptx          = kernels.GetPtx(context.Compiler);
            var elementCount = result.ElementCount();

            ApplyOpInvoke.Invoke(context, cudaContext, ptx, "fill", result, value, elementCount);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Invokes the specified kernels.
        /// </summary>
        /// <param name="kernels">The kernels.</param>
        /// <param name="result">The result.</param>
        /// <param name="srcA">The source a.</param>
        /// <param name="srcB">The source b.</param>
        /// <param name="weight">The weight.</param>
        /// <returns>Tensor.</returns>
        public static NDArray Invoke(ElementwiseKernels kernels, NDArray result, NDArray srcA, NDArray srcB, float weight)
        {
            var context     = CudaHelpers.TSContextForTensor(srcA);
            var cudaContext = context.CudaContextForTensor(srcA);

            var writeTarget  = TensorResultBuilder.GetWriteTarget(result, srcA, false, srcA.Shape);
            var elementCount = writeTarget.ElementCount();

            var ptx = kernels.GetPtx(context.Compiler);

            ApplyOpInvoke.Invoke(context, cudaContext, ptx, "lerp", writeTarget, srcA, srcB, weight, elementCount);

            return(writeTarget);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Invokes the specified kernels.
        /// </summary>
        /// <param name="kernels">The kernels.</param>
        /// <param name="funcName">Name of the function.</param>
        /// <param name="result">The result.</param>
        /// <param name="lhs">The LHS.</param>
        /// <param name="rhs">The RHS.</param>
        /// <returns>Tensor.</returns>
        public static NDArray Invoke(ElementwiseKernels kernels, string funcName, NDArray result, NDArray lhs, NDArray rhs)
        {
            var context     = CudaHelpers.TSContextForTensor(lhs);
            var cudaContext = context.CudaContextForTensor(lhs);

            var writeTarget  = TensorResultBuilder.GetWriteTarget(result, lhs, false, lhs.Shape);
            var elementCount = writeTarget.ElementCount();

            var ptx = kernels.GetPtx(context.Compiler);

            if (result == lhs)
            {
                ApplyOpInvoke.Invoke(context, cudaContext, ptx, "t1_" + funcName, writeTarget, rhs, elementCount);
            }
            else
            {
                ApplyOpInvoke.Invoke(context, cudaContext, ptx, "t2_" + funcName, writeTarget, lhs, rhs, elementCount);
            }

            return(writeTarget);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Invokes the specified kernels.
        /// </summary>
        /// <param name="kernels">The kernels.</param>
        /// <param name="result">The result.</param>
        /// <param name="src">The source.</param>
        /// <param name="min">The minimum.</param>
        /// <param name="max">The maximum.</param>
        /// <returns>Tensor.</returns>
        public static NDArray Invoke(ElementwiseKernels kernels, NDArray result, NDArray src, float min, float max)
        {
            var funcName    = "clamp";
            var context     = CudaHelpers.TSContextForTensor(src);
            var cudaContext = context.CudaContextForTensor(src);

            var writeTarget  = TensorResultBuilder.GetWriteTarget(result, src, false, src.Shape);
            var elementCount = writeTarget.ElementCount();

            var ptx = kernels.GetPtx(context.Compiler);

            if (result == src)
            {
                ApplyOpInvoke.Invoke(context, cudaContext, ptx, "t1_" + funcName, writeTarget, min, max, elementCount);
            }
            else
            {
                ApplyOpInvoke.Invoke(context, cudaContext, ptx, "t2_" + funcName, writeTarget, src, min, max, elementCount);
            }

            return(writeTarget);
        }