Repository: ggerganov/llama.cpp
File: ggml/src/ggml-cann/ggml-cann.cpp (C++)

Code before:
                case GGML_TYPE_F32:
                case GGML_TYPE_F16:
                    return true;
                default:
                    return false;
            }
        }
        case GGML_OP_ROPE: {
            // TODO: with ops-test v == 1
            float ext_factor = 0.0f;
            memcpy(&ext_factor, (const float *) op->op_params + 7, sizeof(float));
            // TODO: n_dims <= ne0
            if (op->src[0]->ne[0] != op->op_params[1]) {
                return false;
            }
            // TODO: ext_factor != 0
            if (ext_factor != 0) {
                return false;
            }

            const int mode = ((const int32_t *) op->op_params)[2];
            if (mode & GGML_ROPE_TYPE_MROPE) {
                return false;
            }
            if (mode & GGML_ROPE_TYPE_VISION) {
                return false;
            }

            if(!ggml_is_contiguous(op->src[0])){
                return false;
            }
            return true;
        }
        case GGML_OP_UPSCALE: {
            // aclnnUpsampleNearest2dGetWorkspaceSize not support
            // selfDimN[2]/outDimN[2] or selfDimC[3]/outDimC[3] not equal
            if (op->src[0]->ne[2] * op->ne[3] != op->src[0]->ne[3] * op->ne[2]) {
                return false;
            }
            if (op->op_params[0] != GGML_SCALE_MODE_NEAREST) {
                return false;
            }
            return true;
        }
        case GGML_OP_POOL_2D: {
            const int32_t * opts = (const int32_t *) op->op_params;
#ifdef ASCEND_310P
            enum ggml_op_pool opt = static_cast<ggml_op_pool>(opts[0]);
            if(opt == GGML_OP_POOL_MAX){
                return false;
            }

Review comment (bug):
Wouldn’t it be more appropriate to put this code inside the else block? When cann_graph is nullptr, there’s no need to check here.

Code after:
 *               representing operations to be computed.
 * @return enum ggml_status Returns GGML_STATUS_SUCCESS if computation
 *         completes successfully, otherwise an appropriate error status.
 */
static enum ggml_status ggml_backend_cann_graph_compute(
    ggml_backend_t backend, ggml_cgraph* cgraph) {
    ggml_backend_cann_context* cann_ctx =
        (ggml_backend_cann_context*)backend->context;
    ggml_cann_set_device(cann_ctx->device);
    release_nz_workspace();
#ifdef USE_ACL_GRAPH
    bool use_cann_graph = true;
    bool cann_graph_update_required = false;

    // check environment LLAMA_SET_ROWS
    if (!cann_ctx->support_set_rows) {
        use_cann_graph = false;
    }

    if (use_cann_graph) {
        if (cann_ctx->cann_graph == nullptr) {
            cann_ctx->cann_graph.reset(new ggml_cann_graph());
            cann_graph_update_required = true;
        }

        cann_graph_update_required = is_cann_graph_update_required(cann_ctx, cgraph);
        set_ggml_graph_node_properties(cann_ctx, cgraph);
    }
#else
    bool use_cann_graph = false;
    bool cann_graph_update_required = false;
#endif  // USE_ACL_GRAPH

    evaluate_and_capture_cann_graph(
        cann_ctx,
        cgraph,
        use_cann_graph,
        cann_graph_update_required
    );

    return GGML_STATUS_SUCCESS;
}

/**
 * @brief Checks if the CANN backend supports a specific operation.
 *
 * This function checks whether the specified operation is supported by the
 * CANN backend.
 *
 * @param backend Pointer to the CANN backend structure to check support for
 *                the operation.