| 498 | } |
| 499 | |
| 500 | std::string dnnc::cppCodeGen::writeTernaryOperator(opNode &computeNode, |
| 501 | std::vector<node *> &ins, |
| 502 | std::vector<node *> &outs) { |
| 503 | std::string code; |
| 504 | |
| 505 | assert(ins.size() == 3 && outs.size() == 1); |
| 506 | |
| 507 | std::string opCode = getOpCodeStr(computeNode.symbol()); |
| 508 | |
| 509 | std::string opName = computeNode.name(); |
| 510 | |
| 511 | assert(opName.length()); |
| 512 | |
| 513 | std::string outType = getDNNC_DataTypeStr(computeNode.dtype()); |
| 514 | std::string in1Type = getDNNC_DataTypeStr(ins[0]->dtype()); |
| 515 | std::string in2Type = getDNNC_DataTypeStr(ins[1]->dtype()); |
| 516 | |
| 517 | // Step 1: Instantiate opterator |
| 518 | code += "\n"; |
| 519 | code += _tab + opCode + "<" + outType + ", " + in1Type + ", " + in2Type + |
| 520 | "> " + opName + "(\"" + opName + "\");\n"; |
| 521 | |
| 522 | // Step 2: Add attribute |
| 523 | for (nodeAttribute attr : computeNode) { |
| 524 | std::string attrName = getAttrNameStr(attr.name()); |
| 525 | std::string attrVar = opName + "_" + attrName; |
| 526 | code += initializeData(attr.data(), attrVar); |
| 527 | code += _tab + opName + ".setAttribute ( attr_" + attrName + ", " + |
| 528 | attrVar + " );\n"; |
| 529 | } |
| 530 | |
| 531 | // Step 3: Add compute function. |
| 532 | std::string outTensor = nodeName(&computeNode); |
| 533 | code += _tab + "tensor<" + outType + "> " + outTensor + " = " + opName + |
| 534 | ".compute ( " + nodeName(ins[0]) + ", " + nodeName(ins[1]) + ", " + |
| 535 | nodeName(ins[2]) + ");\n"; |
| 536 | |
| 537 | if (_graph.isOutput(computeNode.outputs()[0])) { |
| 538 | code += "\n" + _tab + "// Write the output tensor in a file.\n"; |
| 539 | code += _tab + outTensor + ".write(\"" + computeNode.outputs()[0] + |
| 540 | ".out\");\n"; |
| 541 | } |
| 542 | |
| 543 | return code; |
| 544 | } |
| 545 | |
| 546 | std::string dnnc::cppCodeGen::writeCustomOperator(opNode &computeNode, |
| 547 | std::vector<node *> &ins, |
nothing calls this directly
no test coverage detected