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

Code before:
                // only support F32 and F16.
                return false;
            }

            if (!ggml_are_same_shape(op, src) && !ggml_is_contiguous(op)) {
                // unsupport dst is not contiguous.
                return false;
            }

            return true;
        } break;
        case GGML_OP_CONT: {
            // TODO: support GGML_TYPE_BF16
            switch (op->src[0]->type) {
                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]) {

Review comment (suggestion):
I think `use_cann_graph`is not necessary. You need only set `cann_graph_update_required` = true for both acl_graph on and off.

Code after:
        ACL_CHECK(aclmdlRIExecuteAsync(cann_ctx->cann_graph->graph, cann_ctx->stream()));
    }
#endif // USE_ACL_GRAPH
}


/**
 * @brief Computes a computational graph using a CANN backend.
 *
 * This function computes the operations defined in the computational graph
 * using the specified CANN backend.
 *
 * @param backend Pointer to the CANN backend structure to use for computation.
 * @param cgraph Pointer to the computational graph structure containing nodes
 *               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,