MCPcopy Create free account
hub / github.com/ai-techsystems/deepC / writeBinaryOperator

Method writeBinaryOperator

src/codegen/cppCodeGen.cpp:455–498  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

453}
454
455std::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
500std::string dnnc::cppCodeGen::writeTernaryOperator(opNode &computeNode,
501 std::vector<node *> &ins,

Callers

nothing calls this directly

Calls 11

getOpCodeStrFunction · 0.85
getDNNC_DataTypeStrFunction · 0.85
getAttrNameStrFunction · 0.85
isOutputMethod · 0.80
sizeMethod · 0.45
symbolMethod · 0.45
nameMethod · 0.45
lengthMethod · 0.45
dtypeMethod · 0.45
dataMethod · 0.45
outputsMethod · 0.45

Tested by

no test coverage detected