Пример #1
0
        /// <summary>
        /// The Cuda (PTX) implementation.
        /// </summary>
        /// <remarks>
        /// Note that this function signature corresponds to the PTX-backend specific
        /// delegate type <see cref="PTXIntrinsic.Handler"/>.
        /// </remarks>
        static void GeneratePTXCode(
            PTXBackend backend,
            PTXCodeGenerator codeGenerator,
            Value value)
        {
            // The passed value will be the call node in this case
            // Load X parameter register (first argument)
            var xRegister = codeGenerator.LoadPrimitive(value[0]);

            // Allocate target register to write our result to
            var target = codeGenerator.AllocateHardware(value);

            // Emit our desired instructions
            using (var command = codeGenerator.BeginCommand(
                       PTXInstructions.GetArithmeticOperation(
                           BinaryArithmeticKind.Mul,
                           ArithmeticBasicValueType.Int32,
                           backend.Capabilities,
                           false)))
            {
                command.AppendArgument(target);
                command.AppendArgument(xRegister);
                command.AppendConstant(2);
            }
        }
Пример #2
0
 public void Emit(
     PTXCodeGenerator codeGenerator,
     string command,
     PrimitiveRegister primitiveRegister,
     int offset)
 {
     using var commandEmitter = codeGenerator.BeginCommand(command);
     commandEmitter.AppendSuffix(primitiveRegister.BasicValueType);
     commandEmitter.AppendRawValue(ParamName, offset);
     commandEmitter.AppendArgument(primitiveRegister);
 }
Пример #3
0
                private static CommandEmitter BeginEmitLoad(
                    PTXCodeGenerator codeGenerator,
                    string command,
                    PrimitiveRegister sourceRegister)
                {
                    var commandEmitter = codeGenerator.BeginCommand(command);

                    commandEmitter.AppendSuffix(
                        ResolveParameterBasicValueType(
                            sourceRegister.BasicValueType));
                    commandEmitter.AppendArgument(sourceRegister);
                    return(commandEmitter);
                }
Пример #4
0
        /// <summary>
        /// Generates intrinsic math instructions for the following kinds:
        /// Rcp, Sqrt, Sin, Cos, Exp2, Log2, IsInf, IsNaN
        /// </summary>
        /// <param name="backend">The current backend.</param>
        /// <param name="codeGenerator">The code generator.</param>
        /// <param name="value">The value to generate code for.</param>
        public static void GenerateMathIntrinsic(
            PTXBackend backend,
            PTXCodeGenerator codeGenerator,
            Value value)
        {
            var arithmeticValue = value as UnaryArithmeticValue;
            var instruction     = PTXInstructions.GetArithmeticOperation(
                arithmeticValue.Kind,
                arithmeticValue.ArithmeticBasicValueType,
                codeGenerator.FastMath);

            var argument       = codeGenerator.LoadPrimitive(arithmeticValue.Value);
            var targetRegister = codeGenerator.AllocateHardware(arithmeticValue);

            using var command = codeGenerator.BeginCommand(instruction);
            command.AppendArgument(targetRegister);
            command.AppendArgument(argument);
        }