|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +package org.apache.sysds.common; |
| 21 | + |
| 22 | +import org.apache.sysds.lops.Append; |
| 23 | +import org.apache.sysds.lops.Compression; |
| 24 | +import org.apache.sysds.lops.DataGen; |
| 25 | +import org.apache.sysds.lops.DeCompression; |
| 26 | +import org.apache.sysds.lops.LeftIndex; |
| 27 | +import org.apache.sysds.lops.Local; |
| 28 | +import org.apache.sysds.lops.RightIndex; |
| 29 | + |
| 30 | +import org.apache.sysds.runtime.instructions.cp.CPInstruction.CPType; |
| 31 | +import org.apache.sysds.common.Types.OpOp1; |
| 32 | +import org.apache.sysds.hops.FunctionOp; |
| 33 | + |
| 34 | +import java.util.EnumSet; |
| 35 | +import java.util.HashMap; |
| 36 | +import java.util.Map; |
| 37 | + |
| 38 | +public enum Opcodes { |
| 39 | + MMULT("ba+*", CPType.AggregateBinary), |
| 40 | + TAKPM("tak+*", CPType.AggregateTernary), |
| 41 | + TACKPM("tack+*", CPType.AggregateTernary), |
| 42 | + |
| 43 | + UAKP("uak+", CPType.AggregateUnary), |
| 44 | + UARKP("uark+", CPType.AggregateUnary), |
| 45 | + UACKP("uack+", CPType.AggregateUnary), |
| 46 | + UASQKP("uasqk+", CPType.AggregateUnary), |
| 47 | + UARSQKP("uarsqk+", CPType.AggregateUnary), |
| 48 | + UACSQKP("uacsqk+", CPType.AggregateUnary), |
| 49 | + UAMEAN("uamean", CPType.AggregateUnary), |
| 50 | + UARMEAN("uarmean", CPType.AggregateUnary), |
| 51 | + UACMEAN("uacmean", CPType.AggregateUnary), |
| 52 | + UAVAR("uavar", CPType.AggregateUnary), |
| 53 | + UARVAR("uarvar", CPType.AggregateUnary), |
| 54 | + UACVAR("uacvar", CPType.AggregateUnary), |
| 55 | + UAMAX("uamax", CPType.AggregateUnary), |
| 56 | + UARMAX("uarmax", CPType.AggregateUnary), |
| 57 | + UARIMAX("uarimax", CPType.AggregateUnary), |
| 58 | + UACMAX("uacmax", CPType.AggregateUnary), |
| 59 | + UAMIN("uamin", CPType.AggregateUnary), |
| 60 | + UARMIN("uarmin", CPType.AggregateUnary), |
| 61 | + UARIMIN("uarimin", CPType.AggregateUnary), |
| 62 | + UACMIN("uacmin", CPType.AggregateUnary), |
| 63 | + UAP("ua+", CPType.AggregateUnary), |
| 64 | + UARP("uar+", CPType.AggregateUnary), |
| 65 | + UACP("uac+", CPType.AggregateUnary), |
| 66 | + UAM("ua*", CPType.AggregateUnary), |
| 67 | + UARM("uar*", CPType.AggregateUnary), |
| 68 | + UACM("uac*", CPType.AggregateUnary), |
| 69 | + UATRACE("uatrace", CPType.AggregateUnary), |
| 70 | + UAKTRACE("uaktrace", CPType.AggregateUnary), |
| 71 | + |
| 72 | + NROW("nrow", CPType.AggregateUnary), |
| 73 | + NCOL("ncol", CPType.AggregateUnary), |
| 74 | + LENGTH("length", CPType.AggregateUnary), |
| 75 | + EXISTS("exists", CPType.AggregateUnary), |
| 76 | + LINEAGE("lineage", CPType.AggregateUnary), |
| 77 | + UACD("uacd", CPType.AggregateUnary), |
| 78 | + UACDR("uacdr", CPType.AggregateUnary), |
| 79 | + UACDC("uacdc", CPType.AggregateUnary), |
| 80 | + UACDAP("uacdap", CPType.AggregateUnary), |
| 81 | + UACDAPR("uacdapr", CPType.AggregateUnary), |
| 82 | + UACDAPC("uacdapc", CPType.AggregateUnary), |
| 83 | + UNIQUE("unique", CPType.AggregateUnary), |
| 84 | + UNIQUER("uniquer", CPType.AggregateUnary), |
| 85 | + UNIQUEC("uniquec", CPType.AggregateUnary), |
| 86 | + |
| 87 | + UAGGOUTERCHAIN("uaggouterchain", CPType.UaggOuterChain), |
| 88 | + |
| 89 | + // Arithmetic Instruction Opcodes |
| 90 | + PLUS("+", CPType.Binary), |
| 91 | + MINUS("-", CPType.Binary), |
| 92 | + MULT("*", CPType.Binary), |
| 93 | + DIV("/", CPType.Binary), |
| 94 | + MODULUS("%%", CPType.Binary), |
| 95 | + INTDIV("%/%", CPType.Binary), |
| 96 | + POW("^", CPType.Binary), |
| 97 | + MINUS1_MULT("1-*", CPType.Binary), //special * case |
| 98 | + POW2("^2", CPType.Binary), //special ^ case |
| 99 | + MULT2("*2", CPType.Binary), //special * case |
| 100 | + MINUS_NZ("-nz", CPType.Binary), //special - case |
| 101 | + |
| 102 | + // Boolean Instruction Opcodes |
| 103 | + AND("&&", CPType.Binary), |
| 104 | + OR("||", CPType.Binary), |
| 105 | + XOR("xor", CPType.Binary), |
| 106 | + BITWAND("bitwAnd", CPType.Binary), |
| 107 | + BITWOR("bitwOr", CPType.Binary), |
| 108 | + BITWXOR("bitwXor", CPType.Binary), |
| 109 | + BITWSHIFTL("bitwShiftL", CPType.Binary), |
| 110 | + BITWSHIFTR("bitwShiftR", CPType.Binary), |
| 111 | + NOT("!", CPType.Unary), |
| 112 | + |
| 113 | + // Relational Instruction Opcodes |
| 114 | + EQUAL("==", CPType.Binary), |
| 115 | + NOTEQUAL("!=", CPType.Binary), |
| 116 | + LESS("<", CPType.Binary), |
| 117 | + GREATER(">", CPType.Binary), |
| 118 | + LESSEQUAL("<=", CPType.Binary), |
| 119 | + GREATEREQUAL(">=", CPType.Binary), |
| 120 | + |
| 121 | + // Builtin Instruction Opcodes |
| 122 | + LOG("log", CPType.Builtin), |
| 123 | + LOGNZ("log_nz", CPType.Builtin), |
| 124 | + |
| 125 | + SOLVE("solve", CPType.Binary), |
| 126 | + MAX("max", CPType.Binary), |
| 127 | + MIN("min", CPType.Binary), |
| 128 | + DROPINVALIDTYPE("dropInvalidType", CPType.Binary), |
| 129 | + DROPINVALIDLENGTH("dropInvalidLength", CPType.Binary), |
| 130 | + FREPLICATE("freplicate", CPType.Binary), |
| 131 | + VALUESWAP("valueSwap", CPType.Binary), |
| 132 | + APPLYSCHEMA("applySchema", CPType.Binary), |
| 133 | + MAP("_map", CPType.Ternary), |
| 134 | + |
| 135 | + NMAX("nmax", CPType.BuiltinNary), |
| 136 | + NMIN("nmin", CPType.BuiltinNary), |
| 137 | + NP("n+", CPType.BuiltinNary), |
| 138 | + NM("n*", CPType.BuiltinNary), |
| 139 | + |
| 140 | + EXP("exp", CPType.Unary), |
| 141 | + ABS("abs", CPType.Unary), |
| 142 | + SIN("sin", CPType.Unary), |
| 143 | + COS("cos", CPType.Unary), |
| 144 | + TAN("tan", CPType.Unary), |
| 145 | + SINH("sinh", CPType.Unary), |
| 146 | + COSH("cosh", CPType.Unary), |
| 147 | + TANH("tanh", CPType.Unary), |
| 148 | + ASIN("asin", CPType.Unary), |
| 149 | + ACOS("acos", CPType.Unary), |
| 150 | + ATAN("atan", CPType.Unary), |
| 151 | + SIGN("sign", CPType.Unary), |
| 152 | + SQRT("sqrt", CPType.Unary), |
| 153 | + PLOGP("plogp", CPType.Unary), |
| 154 | + PRINT("print", CPType.Unary), |
| 155 | + ASSERT("assert", CPType.Unary), |
| 156 | + ROUND("round", CPType.Unary), |
| 157 | + CEIL("ceil", CPType.Unary), |
| 158 | + FLOOR("floor", CPType.Unary), |
| 159 | + UCUMKP("ucumk+", CPType.Unary), |
| 160 | + UCUMM("ucum*", CPType.Unary), |
| 161 | + UCUMKPM("ucumk+*", CPType.Unary), |
| 162 | + UCUMMIN("ucummin", CPType.Unary), |
| 163 | + UCUMMAX("ucummax", CPType.Unary), |
| 164 | + STOP("stop", CPType.Unary), |
| 165 | + INVERSE("inverse", CPType.Unary), |
| 166 | + CHOLESKY("cholesky", CPType.Unary), |
| 167 | + SPROP("sprop", CPType.Unary), |
| 168 | + SIGMOID("sigmoid", CPType.Unary), |
| 169 | + TYPEOF("typeOf", CPType.Unary), |
| 170 | + DETECTSCHEMA("detectSchema", CPType.Unary), |
| 171 | + COLNAMES("colnames", CPType.Unary), |
| 172 | + ISNA("isna", CPType.Unary), |
| 173 | + ISNAN("isnan", CPType.Unary), |
| 174 | + ISINF("isinf", CPType.Unary), |
| 175 | + PRINTF("printf", CPType.BuiltinNary), |
| 176 | + CBIND("cbind", CPType.BuiltinNary), |
| 177 | + RBIND("rbind", CPType.BuiltinNary), |
| 178 | + EVAL("eval", CPType.BuiltinNary), |
| 179 | + LIST("list", CPType.BuiltinNary), |
| 180 | + |
| 181 | + //Parametrized builtin functions |
| 182 | + AUTODIFF("autoDiff", CPType.ParameterizedBuiltin), |
| 183 | + CONTAINS("contains", CPType.ParameterizedBuiltin), |
| 184 | + PARAMSERV("paramserv", CPType.ParameterizedBuiltin), |
| 185 | + NVLIST("nvlist", CPType.ParameterizedBuiltin), |
| 186 | + CDF("cdf", CPType.ParameterizedBuiltin), |
| 187 | + INVCDF("invcdf", CPType.ParameterizedBuiltin), |
| 188 | + GROUPEDAGG("groupedagg", CPType.ParameterizedBuiltin), |
| 189 | + RMEMPTY("rmempty", CPType.ParameterizedBuiltin), |
| 190 | + REPLACE("replace", CPType.ParameterizedBuiltin), |
| 191 | + LOWERTRI("lowertri", CPType.ParameterizedBuiltin), |
| 192 | + UPPERTRI("uppertri", CPType.ParameterizedBuiltin), |
| 193 | + REXPAND("rexpand", CPType.ParameterizedBuiltin), |
| 194 | + TOSTRING("toString", CPType.ParameterizedBuiltin), |
| 195 | + TOKENIZE("tokenize", CPType.ParameterizedBuiltin), |
| 196 | + TRANSFORMAPPLY("transformapply", CPType.ParameterizedBuiltin), |
| 197 | + TRANSFORMDECODE("transformdecode", CPType.ParameterizedBuiltin), |
| 198 | + TRANSFORMCOLMAP("transformcolmap", CPType.ParameterizedBuiltin), |
| 199 | + TRANSFORMMETA("transformmeta", CPType.ParameterizedBuiltin), |
| 200 | + TRANSFORMENCODE("transformencode", CPType.MultiReturnParameterizedBuiltin), |
| 201 | + |
| 202 | + //Ternary instruction opcodes |
| 203 | + PM("+*", CPType.Ternary), |
| 204 | + MINUSMULT("-*", CPType.Ternary), |
| 205 | + IFELSE("ifelse", CPType.Ternary), |
| 206 | + |
| 207 | + //Variable instruction opcodes |
| 208 | + ASSIGNVAR("assignvar", CPType.Variable), |
| 209 | + CPVAR("cpvar", CPType.Variable), |
| 210 | + MVVAR("mvvar", CPType.Variable), |
| 211 | + RMVAR("rmvar", CPType.Variable), |
| 212 | + RMFILEVAR("rmfilevar", CPType.Variable), |
| 213 | + CAST_AS_SCALAR(OpOp1.CAST_AS_SCALAR.toString(), CPType.Variable), |
| 214 | + CAST_AS_MATRIX(OpOp1.CAST_AS_MATRIX.toString(), CPType.Variable), |
| 215 | + CAST_AS_FRAME_VAR("cast_as_frame", CPType.Variable), |
| 216 | + CAST_AS_FRAME(OpOp1.CAST_AS_FRAME.toString(), CPType.Variable), |
| 217 | + CAST_AS_LIST(OpOp1.CAST_AS_LIST.toString(), CPType.Variable), |
| 218 | + CAST_AS_DOUBLE(OpOp1.CAST_AS_DOUBLE.toString(), CPType.Variable), |
| 219 | + CAST_AS_INT(OpOp1.CAST_AS_INT.toString(), CPType.Variable), |
| 220 | + CAST_AS_BOOLEAN(OpOp1.CAST_AS_BOOLEAN.toString(), CPType.Variable), |
| 221 | + ATTACHFILETOVAR("attachfiletovar", CPType.Variable), |
| 222 | + READ("read", CPType.Variable), |
| 223 | + WRITE("write", CPType.Variable), |
| 224 | + CREATEVAR("createvar", CPType.Variable), |
| 225 | + |
| 226 | + //Reorg instruction opcodes |
| 227 | + TRANSPOSE("r'", CPType.Reorg), |
| 228 | + REV("rev", CPType.Reorg), |
| 229 | + ROLL("roll", CPType.Reorg), |
| 230 | + DIAG("rdiag", CPType.Reorg), |
| 231 | + RESHAPE("rshape", CPType.Reshape), |
| 232 | + SORT("rsort", CPType.Reorg), |
| 233 | + |
| 234 | + // Opcodes related to convolutions |
| 235 | + RELU_BACKWARD("relu_backward", CPType.Dnn), |
| 236 | + RELU_MAXPOOLING("relu_maxpooling", CPType.Dnn), |
| 237 | + RELU_MAXPOOLING_BACKWARD("relu_maxpooling_backward", CPType.Dnn), |
| 238 | + MAXPOOLING("maxpooling", CPType.Dnn), |
| 239 | + MAXPOOLING_BACKWARD("maxpooling_backward", CPType.Dnn), |
| 240 | + AVGPOOLING("avgpooling", CPType.Dnn), |
| 241 | + AVGPOOLING_BACKWARD("avgpooling_backward", CPType.Dnn), |
| 242 | + CONV2D("conv2d", CPType.Dnn), |
| 243 | + CONV2D_BIAS_ADD("conv2d_bias_add", CPType.Dnn), |
| 244 | + CONV2D_BACKWARD_FILTER("conv2d_backward_filter", CPType.Dnn), |
| 245 | + CONV2D_BACKWARD_DATA("conv2d_backward_data", CPType.Dnn), |
| 246 | + BIAS_ADD("bias_add", CPType.Dnn), |
| 247 | + BIAS_MULTIPLY("bias_multiply", CPType.Dnn), |
| 248 | + BATCH_NORM2D("batch_norm2d", CPType.Dnn), |
| 249 | + BATCH_NORM2D_BACKWARD("batch_norm2d_backward", CPType.Dnn), |
| 250 | + LSTM("lstm", CPType.Dnn), |
| 251 | + LSTM_BACKWARD("lstm_backward", CPType.Dnn), |
| 252 | + |
| 253 | + //Quaternary instruction opcodes |
| 254 | + WSLOSS("wsloss", CPType.Quaternary), |
| 255 | + WSIGMOID("wsigmoid", CPType.Quaternary), |
| 256 | + WDIVMM("wdivmm", CPType.Quaternary), |
| 257 | + WCEMM("wcemm", CPType.Quaternary), |
| 258 | + WUMM("wumm", CPType.Quaternary), |
| 259 | + |
| 260 | + //User-defined function Opcodes |
| 261 | + FCALL(FunctionOp.OPCODE, CPType.FCall), |
| 262 | + |
| 263 | + APPEND(Append.OPCODE, CPType.Append), |
| 264 | + REMOVE("remove", CPType.Append), |
| 265 | + |
| 266 | + //data generation opcodes |
| 267 | + RANDOM(DataGen.RAND_OPCODE, CPType.Rand), |
| 268 | + SEQUENCE(DataGen.SEQ_OPCODE, CPType.Rand), |
| 269 | + STRINGINIT(DataGen.SINIT_OPCODE, CPType.StringInit), |
| 270 | + SAMPLE(DataGen.SAMPLE_OPCODE, CPType.Rand), |
| 271 | + TIME(DataGen.TIME_OPCODE, CPType.Rand), |
| 272 | + FRAME(DataGen.FRAME_OPCODE, CPType.Rand), |
| 273 | + |
| 274 | + CTABLE("ctable", CPType.Ctable), |
| 275 | + CTABLEEXPAND("ctableexpand", CPType.Ctable), |
| 276 | + |
| 277 | + //central moment, covariance, quantiles (sort/pick) |
| 278 | + CM("cm", CPType.CentralMoment), |
| 279 | + COV("cov", CPType.Covariance), |
| 280 | + QSORT("qsort", CPType.QSort), |
| 281 | + QPICK("qpick", CPType.QPick), |
| 282 | + |
| 283 | + RIGHT_INDEX(RightIndex.OPCODE, CPType.MatrixIndexing), |
| 284 | + LEFT_INDEX(LeftIndex.OPCODE, CPType.MatrixIndexing), |
| 285 | + |
| 286 | + TSMM("tsmm", CPType.MMTSJ), |
| 287 | + PMM("pmm", CPType.PMMJ), |
| 288 | + MMCHAIN("mmchain", CPType.MMChain), |
| 289 | + |
| 290 | + QR("qr", CPType.MultiReturnBuiltin), |
| 291 | + LU("lu", CPType.MultiReturnBuiltin), |
| 292 | + EIGEN("eigen", CPType.MultiReturnBuiltin), |
| 293 | + FFT("fft", CPType.MultiReturnBuiltin), |
| 294 | + IFFT("ifft", CPType.MultiReturnComplexMatrixBuiltin), |
| 295 | + FFT_LINEARIZED("fft_linearized", CPType.MultiReturnBuiltin), |
| 296 | + IFFT_LINEARIZED("ifft_linearized", CPType.MultiReturnComplexMatrixBuiltin), |
| 297 | + STFT("stft", CPType.MultiReturnComplexMatrixBuiltin), |
| 298 | + SVD("svd", CPType.MultiReturnBuiltin), |
| 299 | + RCM("rcm", CPType.MultiReturnComplexMatrixBuiltin), |
| 300 | + |
| 301 | + PARTITION("partition", CPType.Partition), |
| 302 | + COMPRESS(Compression.OPCODE, CPType.Compression), |
| 303 | + DECOMPRESS(DeCompression.OPCODE, CPType.DeCompression), |
| 304 | + SPOOF("spoof", CPType.SpoofFused), |
| 305 | + PREFETCH("prefetch", CPType.Prefetch), |
| 306 | + EVICT("_evict", CPType.EvictLineageCache), |
| 307 | + BROADCAST("broadcast", CPType.Broadcast), |
| 308 | + TRIGREMOTE("trigremote", CPType.TrigRemote), |
| 309 | + LOCAL(Local.OPCODE, CPType.Local), |
| 310 | + |
| 311 | + SQL("sql", CPType.Sql); |
| 312 | + |
| 313 | + // Constructor |
| 314 | + Opcodes(String name, CPType type) { |
| 315 | + this._name = name; |
| 316 | + this._type = type; |
| 317 | + } |
| 318 | + |
| 319 | + // Fields |
| 320 | + private final String _name; |
| 321 | + private final CPType _type; |
| 322 | + |
| 323 | + private static final Map<String, Opcodes> _lookupMap = new HashMap<>(); |
| 324 | + |
| 325 | + // Initialize lookup map |
| 326 | + static { |
| 327 | + for (Opcodes op : EnumSet.allOf(Opcodes.class)) { |
| 328 | + _lookupMap.put(op.toString(), op); |
| 329 | + } |
| 330 | + } |
| 331 | + |
| 332 | + // Getters |
| 333 | + @Override |
| 334 | + public String toString() { |
| 335 | + return _name; |
| 336 | + } |
| 337 | + |
| 338 | + public CPType getType() { |
| 339 | + return _type; |
| 340 | + } |
| 341 | + |
| 342 | + public static CPType getCPTypeByOpcode(String opcode) { |
| 343 | + for (Opcodes op : Opcodes.values()) { |
| 344 | + if (op.toString().equalsIgnoreCase(opcode.trim())) { |
| 345 | + return op.getType(); |
| 346 | + } |
| 347 | + } |
| 348 | + return null; |
| 349 | + } |
| 350 | +} |
0 commit comments