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

Method writeUnaryOperator

src/codegen/cppCodeGen.cpp:411–453  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

409}
410
411std::string dnnc::cppCodeGen::writeUnaryOperator(opNode &computeNode,
412 std::vector<node *> &ins,
413 std::vector<node *> &outs) {
414 std::string code;
415
416 assert(ins.size() == 1 && outs.size() == 1);
417
418 std::string opCode = getOpCodeStr(computeNode.symbol());
419
420 std::string opName = computeNode.name();
421
422 assert(opName.length());
423
424 std::string outType = getDNNC_DataTypeStr(computeNode.dtype());
425 std::string inType = getDNNC_DataTypeStr(ins[0]->dtype());
426
427 // Step 1: Instantiate opterator
428 code += "\n";
429 code += _tab + opCode + "<" + outType + ", " + inType + "> " + opName +
430 "(\"" + opName + "\");\n";
431
432 // Step 2: Add attribute
433 for (nodeAttribute attr : computeNode) {
434 std::string attrName = getAttrNameStr(attr.name());
435 std::string attrVar = opName + "_" + attrName;
436 code += initializeData(attr.data(), attrVar);
437 code += _tab + opName + ".setAttribute ( attr_" + attrName + ", " +
438 attrVar + " );\n";
439 }
440
441 // Step 3: Add compute function.
442 std::string outTensor = nodeName(&computeNode);
443 code += _tab + "tensor<" + outType + "> " + outTensor + " = " + opName +
444 ".compute ( " + nodeName(ins[0]) + ");\n";
445
446 if (_graph.isOutput(computeNode.outputs()[0])) {
447 code += "\n" + _tab + "// Write the output tensor in a file.\n";
448 code += _tab + outTensor + ".write(\"" + computeNode.outputs()[0] +
449 ".out\");\n";
450 }
451
452 return code;
453}
454
455std::string dnnc::cppCodeGen::writeBinaryOperator(opNode &computeNode,
456 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