| 14782 | } |
| 14783 | |
| 14784 | static void ggml_compute_forward(struct ggml_compute_params * params, struct ggml_tensor * tensor) { |
| 14785 | GGML_ASSERT(params); |
| 14786 | |
| 14787 | if (tensor->op == GGML_OP_NONE) { |
| 14788 | return; |
| 14789 | } |
| 14790 | |
| 14791 | #ifdef GGML_USE_CUBLAS |
| 14792 | bool skip_cpu = ggml_cuda_compute_forward(params, tensor); |
| 14793 | if (skip_cpu) { |
| 14794 | return; |
| 14795 | } |
| 14796 | // Make sure src[0] (weight for binary ops) is on CPU to avoid any weight transfer |
| 14797 | GGML_ASSERT((tensor->src[0] == NULL || tensor->src[0]->backend == GGML_BACKEND_CPU) && "weight should be on the CPU to compute on the CPU"); |
| 14798 | #endif // GGML_USE_CUBLAS |
| 14799 | |
| 14800 | switch (tensor->op) { |
| 14801 | case GGML_OP_DUP: |
| 14802 | { |
| 14803 | ggml_compute_forward_dup(params, tensor->src[0], tensor); |
| 14804 | } break; |
| 14805 | case GGML_OP_ADD: |
| 14806 | { |
| 14807 | ggml_compute_forward_add(params, tensor->src[0], tensor->src[1], tensor); |
| 14808 | } break; |
| 14809 | case GGML_OP_ADD1: |
| 14810 | { |
| 14811 | ggml_compute_forward_add1(params, tensor->src[0], tensor->src[1], tensor); |
| 14812 | } break; |
| 14813 | case GGML_OP_ACC: |
| 14814 | { |
| 14815 | ggml_compute_forward_acc(params, tensor->src[0], tensor->src[1], tensor); |
| 14816 | } break; |
| 14817 | case GGML_OP_SUB: |
| 14818 | { |
| 14819 | ggml_compute_forward_sub(params, tensor->src[0], tensor->src[1], tensor); |
| 14820 | } break; |
| 14821 | case GGML_OP_MUL: |
| 14822 | { |
| 14823 | ggml_compute_forward_mul(params, tensor->src[0], tensor->src[1], tensor); |
| 14824 | } break; |
| 14825 | case GGML_OP_DIV: |
| 14826 | { |
| 14827 | ggml_compute_forward_div(params, tensor->src[0], tensor->src[1], tensor); |
| 14828 | } break; |
| 14829 | case GGML_OP_SQR: |
| 14830 | { |
| 14831 | ggml_compute_forward_sqr(params, tensor->src[0], tensor); |
| 14832 | } break; |
| 14833 | case GGML_OP_SQRT: |
| 14834 | { |
| 14835 | ggml_compute_forward_sqrt(params, tensor->src[0], tensor); |
| 14836 | } break; |
| 14837 | case GGML_OP_LOG: |
| 14838 | { |
| 14839 | ggml_compute_forward_log(params, tensor->src[0], tensor); |
| 14840 | } break; |
| 14841 | case GGML_OP_SUM: |
no test coverage detected