| 28 | // TODO Reduce duplicate codes in ResolveCustomOpMatMulPass.cpp |
| 29 | template <typename T> |
| 30 | luci::CircleConst *create_const_node(loco::Graph *g, const loco::DataType dtype, |
| 31 | const std::vector<uint32_t> &shape, |
| 32 | const std::vector<T> &values) |
| 33 | { |
| 34 | auto node = g->nodes()->create<luci::CircleConst>(); |
| 35 | node->dtype(dtype); |
| 36 | node->rank(shape.size()); |
| 37 | |
| 38 | uint32_t size = 1; |
| 39 | for (uint32_t i = 0; i < shape.size(); ++i) |
| 40 | { |
| 41 | node->dim(i) = shape.at(i); |
| 42 | size *= shape.at(i); |
| 43 | } |
| 44 | node->shape_status(luci::ShapeStatus::VALID); |
| 45 | |
| 46 | #define INIT_VALUES(DT) \ |
| 47 | { \ |
| 48 | node->size<DT>(size); \ |
| 49 | for (uint32_t i = 0; i < values.size(); ++i) \ |
| 50 | node->at<DT>(i) = values[i]; \ |
| 51 | } |
| 52 | |
| 53 | switch (dtype) |
| 54 | { |
| 55 | case loco::DataType::U8: |
| 56 | INIT_VALUES(loco::DataType::U8); |
| 57 | break; |
| 58 | case loco::DataType::S16: |
| 59 | INIT_VALUES(loco::DataType::S16); |
| 60 | break; |
| 61 | case loco::DataType::S32: |
| 62 | INIT_VALUES(loco::DataType::S32); |
| 63 | break; |
| 64 | case loco::DataType::FLOAT32: |
| 65 | INIT_VALUES(loco::DataType::FLOAT32) |
| 66 | break; |
| 67 | default: |
| 68 | INTERNAL_EXN("create_const_node called with unsupported type"); |
| 69 | break; |
| 70 | } |
| 71 | return node; |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * Simple graph which adds constant (addition) to the input |