Skip to content

[CANN]Support Acl Graph #13915

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions ggml/src/ggml-cann/aclnn_ops.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,16 @@ static void cann_copy(ggml_backend_cann_context& ctx, aclTensor* acl_src,
void ggml_cann_dup(ggml_backend_cann_context& ctx, ggml_tensor* dst) {
ggml_tensor* src0 = dst->src[0];

// ---- TODO: ----
// if (ctx.cann_graph && ctx.cann_graph->use_cpy_indirection) {
// int &idx = ctx.cann_graph->graph_cpynode_index; // 引用,方便自增
// if (idx < ctx.cann_graph->dest_ptrs_size && ctx.cann_graph->dest_ptrs_d != nullptr) {
// dst->data = ggml_cann_get_dynamic_dst_ptr(ctx, idx);
// idx++;
// } else {
// std::cerr << "Warning: graph_cpynode_index out of range or dest_ptrs_d null!" << std::endl;
// }
// }
aclTensor* acl_src = ggml_cann_create_tensor(src0);
aclTensor* acl_dst = ggml_cann_create_tensor(dst);
if (ggml_are_same_shape(src0, dst)) {
Expand Down
53 changes: 53 additions & 0 deletions ggml/src/ggml-cann/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,58 @@ class cann_task_queue {
int32_t device_;
};

// TODO: 删除 //
// #if defined(GGML_CANN_USE_GRAPHS)
#define USE_CANN_GRAPH
// #endif

struct ggml_graph_node_properties {
void * node_address;
ggml_op node_op;
int64_t ne[GGML_MAX_DIMS];
size_t nb[GGML_MAX_DIMS];
void * src_address[GGML_MAX_SRC];
int32_t op_params[GGML_MAX_OP_PARAMS / sizeof(int32_t)];
};

struct ggml_cann_graph {
#ifdef USE_CANN_GRAPH
~ggml_cann_graph() {
// if (instance != nullptr) {
// aclmdlRIDestroy(instance);
// }
if (graph != nullptr) {
aclmdlRIDestroy(graph);
}
}

aclmdlRI graph = nullptr;
// aclmdlRI instance = nullptr;

size_t num_nodes = 0;

// std::vector<aclGraphNode*> nodes;
std::vector<aclopAttr*> op_attrs;
std::vector<aclTensor*> input_tensors;
std::vector<aclTensor*> output_tensors;

// bool disable_due_to_npu_arch = false;
bool disable_due_to_too_many_updates = false;
// bool disable_due_to_failed_graph_capture = false;
int number_consecutive_updates = 0;

std::vector<ggml_graph_node_properties> ggml_graph_properties;

// TODO: user cpy indirection
bool use_cpy_indirection = false;
std::vector<char *> cpy_dest_ptrs;
char ** dest_ptrs_d = nullptr;
int dest_ptrs_size = 0;

int graph_cpynode_index = -1;
#endif // USE_CANN_GRAPH
};

/**
* @brief Context for managing CANN backend operations.
*/
Expand All @@ -341,6 +393,7 @@ struct ggml_backend_cann_context {
std::string name; /**< Name of the device. */
std::string description; /**< Description of the device. */
aclrtEvent copy_event = nullptr; /**< Event for managing copy operations. */
std::unique_ptr<ggml_cann_graph> cann_graph;
cann_task_queue task_queue;
bool async_mode;

Expand Down
Loading
Loading