| 138 | } |
| 139 | |
| 140 | struct ggml_cgraph * build_graph(const test_model& model) { |
| 141 | static size_t buf_size = ggml_tensor_overhead()*GGML_DEFAULT_GRAPH_SIZE + ggml_graph_overhead(); |
| 142 | static std::vector<uint8_t> buf(buf_size); |
| 143 | |
| 144 | struct ggml_init_params params0 = { |
| 145 | /*.mem_size =*/ buf_size, |
| 146 | /*.mem_buffer =*/ buf.data(), |
| 147 | /*.no_alloc =*/ true, // the tensors will be allocated later by ggml_gallocr_alloc_graph() |
| 148 | }; |
| 149 | |
| 150 | // create a temporally context to build the graph |
| 151 | struct ggml_context * ctx0 = ggml_init(params0); |
| 152 | |
| 153 | struct ggml_cgraph * gf = ggml_new_graph(ctx0); |
| 154 | |
| 155 | int s0 = 1; |
| 156 | int s1 = 1; |
| 157 | int p0 = 1; |
| 158 | int p1 = 1; |
| 159 | int d0 = 1; |
| 160 | int d1 = 1; |
| 161 | |
| 162 | // split conv2d in fundamental methods for test unit |
| 163 | struct ggml_tensor* im2col_0 = ggml_im2col(ctx0, model.a, model.b, s0, s1, p0, p1, d0, d1, true, GGML_TYPE_F16); |
| 164 | ggml_set_name(im2col_0, "im2col_res"); |
| 165 | ggml_build_forward_expand(gf, im2col_0); |
| 166 | |
| 167 | // recalculate for avoid fragmentation |
| 168 | struct ggml_tensor* conv2d_res = ggml_conv_2d(ctx0, model.a, model.b, s0, s1, p0, p1, d0, d1); |
| 169 | ggml_set_name(conv2d_res, "conv2d_res"); |
| 170 | ggml_build_forward_expand(gf, conv2d_res); |
| 171 | |
| 172 | ggml_free(ctx0); |
| 173 | return gf; |
| 174 | } |
| 175 | |
| 176 | struct ggml_cgraph * compute_graph(const test_model & model, ggml_gallocr_t allocr) { |
| 177 | struct ggml_cgraph * gf = build_graph(model); |
no test coverage detected