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

Method writeConstantOperator

src/codegen/cppCodeGen.cpp:369–409  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

367}
368
369std::string dnnc::cppCodeGen::writeConstantOperator(opNode &computeNode,
370 std::vector<node *> &outs) {
371 std::string code;
372
373 assert(outs.size() == 1);
374
375 std::string opCode = getOpCodeStr(computeNode.symbol());
376
377 std::string opName = computeNode.name();
378
379 assert(opName.length());
380
381 std::string outType = getDNNC_DataTypeStr(computeNode.dtype());
382
383 // Step 1: Instantiate opterator
384 code += "\n";
385 code +=
386 _tab + opCode + "<" + outType + "> " + opName + "(\"" + opName + "\");\n";
387
388 // Step 2: Add attribute
389 for (nodeAttribute attr : computeNode) {
390 std::string attrName = getAttrNameStr(attr.name());
391 std::string attrVar = opName + "_" + attrName;
392 code += initializeData(attr.data(), attrVar);
393 code += _tab + opName + ".setAttribute ( attr_" + attrName + ", " +
394 attrVar + " );\n";
395 }
396
397 // Step 3: Add compute function.
398 std::string outTensor = nodeName(&computeNode);
399 code += _tab + "tensor<" + outType + "> " + outTensor + " = " + opName +
400 ".compute ();\n";
401
402 if (_graph.isOutput(computeNode.outputs()[0])) {
403 code += "\n" + _tab + "// Write the output tensor in a file.\n";
404 code += _tab + outTensor + ".write(\"" + computeNode.outputs()[0] +
405 ".out\");\n";
406 }
407
408 return code;
409}
410
411std::string dnnc::cppCodeGen::writeUnaryOperator(opNode &computeNode,
412 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