Skip to content

Commit 091e5a1

Browse files
committed
CANN: optimize rope cache
1 parent fb22dd0 commit 091e5a1

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

ggml/src/ggml-cann/aclnn_ops.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2216,16 +2216,14 @@ static void aclnn_cache_init(ggml_backend_cann_context& ctx, ggml_tensor* dst,
22162216
ggml_cann_release_resources(ctx, acl_theta_scale_tensor,acl_theta_scale);
22172217
}
22182218

2219-
if(ctx.sin_ptr == nullptr) {
2220-
int64_t theta_length = theta_scale_length * ctx.max_prompt_length;
2221-
ACL_CHECK(aclrtMalloc(&ctx.sin_ptr, theta_length * sizeof(float_t), ACL_MEM_MALLOC_HUGE_FIRST));
2222-
ACL_CHECK(aclrtMalloc(&ctx.cos_ptr, theta_length * sizeof(float_t), ACL_MEM_MALLOC_HUGE_FIRST));
2223-
}
22242219
if(position_length > ctx.max_prompt_length) {
22252220
ctx.max_prompt_length = position_length;
22262221
int64_t theta_length = theta_scale_length * ctx.max_prompt_length;
2227-
ACL_CHECK(aclrtFree(ctx.sin_ptr));
2228-
ACL_CHECK(aclrtFree(ctx.cos_ptr));
2222+
2223+
if (ctx.sin_ptr != nullptr)
2224+
ACL_CHECK(aclrtFree(ctx.sin_ptr));
2225+
if (ctx.cos_ptr != nullptr)
2226+
ACL_CHECK(aclrtFree(ctx.cos_ptr));
22292227
ACL_CHECK(aclrtMalloc(&ctx.sin_ptr, theta_length * sizeof(float_t), ACL_MEM_MALLOC_HUGE_FIRST));
22302228
ACL_CHECK(aclrtMalloc(&ctx.cos_ptr, theta_length * sizeof(float_t), ACL_MEM_MALLOC_HUGE_FIRST));
22312229
}

ggml/src/ggml-cann/common.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ struct ggml_backend_cann_context {
371371
void* init_ptr = nullptr;
372372
void* sin_ptr = nullptr;
373373
void* cos_ptr = nullptr;
374-
int64_t max_prompt_length = 65536;
374+
int64_t max_prompt_length = 0;
375375
#ifdef USE_ACL_GRAPH
376376
/// Cached CANN ACL graph used for executing the current ggml computation graph.
377377
std::unique_ptr<ggml_cann_graph> cann_graph;

0 commit comments

Comments
 (0)