MCPcopy Create free account
hub / github.com/MegEngine/MegCC / SimpleCombineModel

Method SimpleCombineModel

runtime/test/common/common.h:48–123  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

46class SimpleCombineModel {
47public:
48 SimpleCombineModel(
49 int nr_device_model, int nr_instruction, int nr_input = 1,
50 int nr_output = 1, const std::vector<const char*>& input_name = {"data"},
51 const std::vector<const char*>& output_name = {"output"},
52 const std::vector<std::vector<std::vector<size_t>>>& input_shape =
53 {{{1, 3, 224, 224}}},
54 const std::vector<std::vector<std::vector<size_t>>>& output_shape = {
55 {{1, 2}}}) {
56 TINYNN_ASSERT(
57 nr_device_model > 0 && nr_device_model == input_shape.size() &&
58 nr_device_model == output_shape.size());
59 TINYNN_ASSERT(
60 nr_input > 0 && nr_input == input_name.size() && nr_output > 0 &&
61 nr_output == output_name.size());
62 for (size_t i = 0; i < nr_device_model; ++i) {
63 TINYNN_ASSERT(
64 nr_input == input_shape[i].size() &&
65 nr_output == output_shape[i].size());
66 }
67 m_combine_model = (CombineModel*)malloc(sizeof(CombineModel));
68 m_combine_model->combo_iotensor = create_combo_io_tensor();
69 m_combine_model->nr_device_model = nr_device_model;
70 m_combine_model->device_models =
71 (DeviceModel**)malloc(sizeof(DeviceModel*) * nr_device_model);
72 m_combine_model->weights = (Tensor*)malloc(sizeof(Tensor) * 10);
73 for (int i = 0; i < nr_device_model; i++) {
74 DeviceModel* dev_model = (DeviceModel*)malloc(sizeof(DeviceModel));
75 m_device_models.push_back(dev_model);
76 m_combine_model->device_models[i] = dev_model;
77 dev_model->tensors = (Tensor*)malloc(sizeof(Tensor) * 10);
78
79 dev_model->nr_input = nr_input;
80 dev_model->inputs = (Tensor**)malloc(sizeof(Tensor*) * dev_model->nr_input);
81 for (size_t j = 0; j < dev_model->nr_input; ++j) {
82 dev_model->inputs[j] = (Tensor*)malloc(sizeof(Tensor));
83 memset(dev_model->inputs[j], 0, sizeof(Tensor));
84 dev_model->inputs[j]->name = (char*)input_name[j];
85 dev_model->inputs[j]->layout.nr_dim = input_shape[i][j].size();
86 for (size_t k = 0; k < dev_model->inputs[j]->layout.nr_dim; ++k) {
87 dev_model->inputs[j]->layout.dims[k] = input_shape[i][j][k];
88 }
89 }
90
91 dev_model->nr_output = nr_output;
92 dev_model->outputs =
93 (Tensor**)malloc(sizeof(Tensor*) * dev_model->nr_output);
94 for (size_t j = 0; j < dev_model->nr_output; ++j) {
95 dev_model->outputs[j] = (Tensor*)malloc(sizeof(Tensor));
96 memset(dev_model->outputs[j], 0, sizeof(Tensor));
97 dev_model->outputs[j]->name = (char*)output_name[j];
98 dev_model->outputs[j]->layout.nr_dim = output_shape[i][j].size();
99 for (size_t k = 0; k < dev_model->outputs[j]->layout.nr_dim; ++k) {
100 dev_model->outputs[j]->layout.dims[k] = output_shape[i][j][k];
101 }
102 }
103
104 dev_model->device.device_type = TinyNN_BARE_METAL;
105 init_device(&dev_model->device);

Callers

nothing calls this directly

Calls 3

create_combo_io_tensorFunction · 0.85
init_deviceFunction · 0.85
create_runtime_optFunction · 0.85

Tested by

no test coverage detected