| 6241 | }; |
| 6242 | |
| 6243 | static struct ggml_tensor * ggml_map_custom3_impl( |
| 6244 | struct ggml_context * ctx, |
| 6245 | struct ggml_tensor * a, |
| 6246 | struct ggml_tensor * b, |
| 6247 | struct ggml_tensor * c, |
| 6248 | const ggml_custom3_op_t fun, |
| 6249 | int n_tasks, |
| 6250 | void * userdata, |
| 6251 | bool inplace) { |
| 6252 | GGML_ASSERT(n_tasks == GGML_N_TASKS_MAX || n_tasks > 0); |
| 6253 | |
| 6254 | bool is_node = false; |
| 6255 | |
| 6256 | if (!inplace && (a->grad || b->grad || c->grad)) { |
| 6257 | is_node = true; |
| 6258 | } |
| 6259 | |
| 6260 | struct ggml_tensor * result = inplace ? ggml_view_tensor(ctx, a) : ggml_dup_tensor(ctx, a); |
| 6261 | |
| 6262 | struct ggml_map_custom3_op_params params = { |
| 6263 | /*.fun =*/ fun, |
| 6264 | /*.n_tasks =*/ n_tasks, |
| 6265 | /*.userdata =*/ userdata |
| 6266 | }; |
| 6267 | ggml_set_op_params(result, (const void *) ¶ms, sizeof(params)); |
| 6268 | |
| 6269 | result->op = GGML_OP_MAP_CUSTOM3; |
| 6270 | result->grad = is_node ? ggml_dup_tensor(ctx, result) : NULL; |
| 6271 | result->src[0] = a; |
| 6272 | result->src[1] = b; |
| 6273 | result->src[2] = c; |
| 6274 | |
| 6275 | return result; |
| 6276 | } |
| 6277 | |
| 6278 | struct ggml_tensor * ggml_map_custom3( |
| 6279 | struct ggml_context * ctx, |
no test coverage detected