| 367 | } |
| 368 | |
| 369 | std::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 | |
| 411 | std::string dnnc::cppCodeGen::writeUnaryOperator(opNode &computeNode, |
| 412 | std::vector<node *> &ins, |
nothing calls this directly
no test coverage detected