| 453 | } |
| 454 | |
| 455 | std::string dnnc::cppCodeGen::writeBinaryOperator(opNode &computeNode, |
| 456 | std::vector<node *> &ins, |
| 457 | std::vector<node *> &outs) { |
| 458 | std::string code; |
| 459 | |
| 460 | assert(ins.size() == 2 && outs.size() == 1); |
| 461 | |
| 462 | std::string opCode = getOpCodeStr(computeNode.symbol()); |
| 463 | |
| 464 | std::string opName = computeNode.name(); |
| 465 | |
| 466 | assert(opName.length()); |
| 467 | |
| 468 | std::string outType = getDNNC_DataTypeStr(computeNode.dtype()); |
| 469 | std::string in1Type = getDNNC_DataTypeStr(ins[0]->dtype()); |
| 470 | std::string in2Type = getDNNC_DataTypeStr(ins[1]->dtype()); |
| 471 | |
| 472 | // Step 1: Instantiate opterator |
| 473 | code += "\n"; |
| 474 | code += _tab + opCode + "<" + outType + ", " + in1Type + ", " + in2Type + |
| 475 | "> " + opName + "(\"" + opName + "\");\n"; |
| 476 | |
| 477 | // Step 2: Add attribute |
| 478 | for (nodeAttribute attr : computeNode) { |
| 479 | std::string attrName = getAttrNameStr(attr.name()); |
| 480 | std::string attrVar = opName + "_" + attrName; |
| 481 | code += initializeData(attr.data(), attrVar); |
| 482 | code += _tab + opName + ".setAttribute ( attr_" + attrName + ", " + |
| 483 | attrVar + " );\n"; |
| 484 | } |
| 485 | |
| 486 | // Step 3: Add compute function. |
| 487 | std::string outTensor = nodeName(&computeNode); |
| 488 | code += _tab + "tensor<" + outType + "> " + outTensor + " = " + opName + |
| 489 | ".compute ( " + nodeName(ins[0]) + ", " + nodeName(ins[1]) + ");\n"; |
| 490 | |
| 491 | if (_graph.isOutput(computeNode.outputs()[0])) { |
| 492 | code += "\n" + _tab + "// Write the output tensor in a file.\n"; |
| 493 | code += _tab + outTensor + ".write(\"" + computeNode.outputs()[0] + |
| 494 | ".out\");\n"; |
| 495 | } |
| 496 | |
| 497 | return code; |
| 498 | } |
| 499 | |
| 500 | std::string dnnc::cppCodeGen::writeTernaryOperator(opNode &computeNode, |
| 501 | std::vector<node *> &ins, |
nothing calls this directly
no test coverage detected