Class InstructionUtils
java.lang.Object
org.apache.sysds.runtime.instructions.InstructionUtils
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic intcheckNumFields(String[] parts, int expected) static intcheckNumFields(String[] parts, int... expected) static intcheckNumFields(String[] parts, int expected1, int expected2) static intcheckNumFields(String str, int expected) static intcheckNumFields(String str, int... expected) static intcheckNumFields(String str, int expected1, int expected2) static StringconcatOperandParts(String... inputs) Concat the input parts with the value type delimiter.static StringconcatOperands(String... inputs) Concat the inputs as operands to generate the instruction string.static StringconcatOperands(StringBuilder sb, String... inputs) static StringconcatStrings(String... inputs) static StringconstructBinaryInstString(String instString, String opcode, CPOperand op1, CPOperand op2, CPOperand out) static StringconstructTernaryString(String instString, CPOperand op1, CPOperand op2, CPOperand op3, CPOperand out) static StringconstructUnaryInstString(String instString, String opcode, CPOperand op1, CPOperand out) static StringcreateLiteralOperand(String val, Types.ValueType vt) static StringcreateOperand(CPOperand operand) static Types.CorrectionLocationTypestatic StringderiveAggregateOperatorOpcode(String opcode) static Types.DirectiongetAggDirection(String opcode) static Types.AggOpstatic InstructionTypestatic InstructionTypegetCPTypeByOpcode(String opcode) static Types.ExecTypegetExecType(String str) static InstructionTypegetFEDType(String str) getGPUType(String str) static String[]Given an instruction string, strip-off the execution type and return opcode and all input/output operands WITHOUT their data/value type.static String[]Given an instruction string, this function strips-off the execution type (CP or SPARK) and returns the remaining parts, which include the opcode as well as the input and output operands.static AggregateBinaryOperatorgetMatMultOperator(int k) static InstructionTypegetOOCType(String str) static Stringstatic InstructionTypestatic InstructionTypegetSPTypeByOpcode(String opcode) static StringBuilderstatic StringinstructionStringFEDPrepare(String inst, CPOperand varOldOut, long id, CPOperand[] varOldIn, long[] varNewIn, boolean rmFederatedOutput) Prepare instruction string for sending in a FederatedRequest as a CP instruction.static booleanisBuiltinFunction(String opcode) static booleanisDistQuaternaryOpcode(String opcode) static booleanisUnaryMetadata(String opcode) static AggregateOperatorparseAggregateOperator(String opcode, String corrLoc) static AggregateTernaryOperatorparseAggregateTernaryOperator(String opcode) static AggregateTernaryOperatorparseAggregateTernaryOperator(String opcode, int numThreads) static AggregateUnaryOperatorparseAggregateUnaryRowIndexOperator(String opcode, int numOutputs, int numThreads) static AggregateUnaryOperatorstatic AggregateUnaryOperatorparseBasicAggregateUnaryOperator(String opcode, int numThreads) Parse the given opcode into an aggregate unary operator.static AggregateUnaryOperatorstatic BinaryOperatorparseBinaryOperator(String opcode) static BinaryOperatorparseBinaryOperator(String opcode, int k) static MultiThreadedOperatorparseBinaryOrBuiltinOperator(String opcode, CPOperand in1, CPOperand in2) static AggregateUnaryOperatorstatic BinaryOperatorparseExtendedBinaryOperator(String opcode) static OperatorparseExtendedBinaryOrBuiltinOperator(String opcode, CPOperand in1, CPOperand in2) static OperatorparseGroupedAggOperator(String fn, String other) static ScalarOperatorparseScalarBinaryOperator(String opcode, boolean arg1IsScalar) scalar-matrix operatorstatic ScalarOperatorparseScalarBinaryOperator(String opcode, boolean arg1IsScalar, double constant) scalar-matrix operatorstatic ScalarOperatorparseScalarBinaryOperator(String opcode, boolean arg1IsScalar, double constant, int k) static TernaryOperatorparseTernaryOperator(String opcode) static TernaryOperatorparseTernaryOperator(String opcode, int numThreads) static UnaryOperatorparseUnaryOperator(String opcode) static UnaryOperatorparseUnaryOperator(String opcode, int k) static StringremoveFEDOutputFlag(String linst) Removes federated output flag from the end of the instruction string if the flag is present.static StringremoveOperand(String instStr, int operand) static StringreplaceOperand(String instStr, int operand, String newValue) static StringreplaceOperandName(String instStr) static StringstripThreadCount(String str)
-
Constructor Details
-
InstructionUtils
public InstructionUtils()
-
-
Method Details
-
getStringBuilder
-
checkNumFields
-
checkNumFields
-
checkNumFields
-
checkNumFields
-
checkNumFields
-
checkNumFields
-
getInstructionParts
Given an instruction string, strip-off the execution type and return opcode and all input/output operands WITHOUT their data/value type. i.e., ret.length = parts.length-1 (-1 for execution type)- Parameters:
str- instruction string- Returns:
- instruction parts as string array
-
getInstructionPartsWithValueType
Given an instruction string, this function strips-off the execution type (CP or SPARK) and returns the remaining parts, which include the opcode as well as the input and output operands. Each returned part will have the datatype and valuetype associated with the operand. This function is invoked mainly for parsing CPInstructions.- Parameters:
str- instruction string- Returns:
- instruction parts as string array
-
stripThreadCount
-
getExecType
-
getOpCode
-
getSPType
-
getCPType
-
getSPTypeByOpcode
-
getCPTypeByOpcode
-
getGPUType
-
getFEDType
-
getOOCType
-
isBuiltinFunction
-
isUnaryMetadata
-
parseBasicAggregateUnaryOperator
-
parseBasicAggregateUnaryOperator
public static AggregateUnaryOperator parseBasicAggregateUnaryOperator(String opcode, int numThreads) Parse the given opcode into an aggregate unary operator.- Parameters:
opcode- opcodenumThreads- number of threads- Returns:
- Parsed aggregate unary operator object. Caller must handle possible null return value.
-
parseAggregateUnaryRowIndexOperator
public static AggregateUnaryOperator parseAggregateUnaryRowIndexOperator(String opcode, int numOutputs, int numThreads) -
parseAggregateTernaryOperator
-
parseAggregateTernaryOperator
-
parseAggregateOperator
-
parseBasicCumulativeAggregateUnaryOperator
-
parseCumulativeAggregateUnaryOperator
-
parseUnaryOperator
-
parseUnaryOperator
-
parseBinaryOrBuiltinOperator
public static MultiThreadedOperator parseBinaryOrBuiltinOperator(String opcode, CPOperand in1, CPOperand in2) -
parseExtendedBinaryOrBuiltinOperator
-
parseBinaryOperator
-
parseBinaryOperator
-
parseTernaryOperator
-
parseTernaryOperator
-
parseScalarBinaryOperator
scalar-matrix operator- Parameters:
opcode- the opcodearg1IsScalar- ?- Returns:
- scalar operator
-
parseScalarBinaryOperator
public static ScalarOperator parseScalarBinaryOperator(String opcode, boolean arg1IsScalar, double constant) scalar-matrix operator- Parameters:
opcode- the opcodearg1IsScalar- ?constant- ?- Returns:
- scalar operator
-
parseExtendedBinaryOperator
-
parseScalarBinaryOperator
public static ScalarOperator parseScalarBinaryOperator(String opcode, boolean arg1IsScalar, double constant, int k) -
deriveAggregateOperatorOpcode
-
getAggOp
-
getAggDirection
-
deriveAggregateOperatorCorrectionLocation
-
isDistQuaternaryOpcode
-
getMatMultOperator
-
parseGroupedAggOperator
-
createLiteralOperand
-
createOperand
-
replaceOperand
-
removeOperand
-
replaceOperandName
-
concatOperands
Concat the inputs as operands to generate the instruction string. The inputs are separated by the operand delimiter and appended using a ThreadLocal StringBuilder.- Parameters:
inputs- operand inputs given as strings- Returns:
- the instruction string with the given inputs concatenated
-
concatOperands
-
concatOperandParts
Concat the input parts with the value type delimiter.- Parameters:
inputs- input operand parts as strings- Returns:
- concatenated input parts
-
concatStrings
-
constructTernaryString
-
constructBinaryInstString
-
constructUnaryInstString
-
instructionStringFEDPrepare
public static String instructionStringFEDPrepare(String inst, CPOperand varOldOut, long id, CPOperand[] varOldIn, long[] varNewIn, boolean rmFederatedOutput) Prepare instruction string for sending in a FederatedRequest as a CP instruction. This involves replacing the coordinator operand names with the worker operand names, changing the execution type, and removing the federated output flag if necessary.- Parameters:
inst- instruction string to prepare for federated requestvarOldOut- current output operand (to be replaced)id- new output operand (always a number)varOldIn- current input operand (to be replaced)varNewIn- new input operand names (always numbers)rmFederatedOutput- remove federated output flag- Returns:
- instruction string prepared for federated request
-
removeFEDOutputFlag
Removes federated output flag from the end of the instruction string if the flag is present.- Parameters:
linst- instruction string- Returns:
- instruction string with no federated output flag
-