/// <summary> /// Emits a new parameter load operation that converts generic address- /// space pointers into a specialized address space. /// </summary> public readonly void Emit( PTXCodeGenerator codeGenerator, string command, PrimitiveRegister primitiveRegister, int offset) { // Load into the temporary register in the case of a pointer type if (primitiveRegister.Type is AddressSpaceType addressSpaceType && addressSpaceType.AddressSpace != MemoryAddressSpace.Generic) { primitiveRegister.AssertNotNull(TempRegister); using (var commandEmitter = BeginEmitLoad( codeGenerator, command, TempRegister)) { commandEmitter.AppendRawValue(ParamName, offset); } // Convert the source value into the specialized address space // using the previously allocated temp register codeGenerator.CreateAddressSpaceCast( TempRegister, primitiveRegister as HardwareRegister, MemoryAddressSpace.Generic, addressSpaceType.AddressSpace); }
/// <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); } }
public void Emit( PTXCodeGenerator codeGenerator, string command, PrimitiveRegister register, int offset) => codeGenerator.EmitIOStore( Emitter, command, register, offset);
public void Emit( PTXCodeGenerator codeGenerator, string command, PrimitiveRegister primitiveRegister, int offset) => codeGenerator.EmitIOLoad( Emitter, command, primitiveRegister as HardwareRegister, offset);
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); }
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); }
/// <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); }