Skip to content

Commit

Permalink
增加昇腾去初始化操作
Browse files Browse the repository at this point in the history
  • Loading branch information
TylunasLi committed Jul 29, 2024
1 parent 3758b1d commit e56280a
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions example/benchmark/benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,5 +198,6 @@ int main(int argc, char **argv) {
printf("prompt use %f s\n", promptSpend);
printf("prompt speed = %f tokens / s\n", (float)promptTokenNum / promptSpend);
printf("output %d tokens\nuse %f s\nspeed = %f tokens / s\n", tokens, spend, tokens / spend);
fastllm::Finalize();
return 0;
}
2 changes: 2 additions & 0 deletions include/fastllm.h
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,8 @@ namespace fastllm {

void PrintProfiler();

void Finalize(); // 程序执行完,释放资源

void ApplyDeviceMap(const std::map <std::string, int> &deviceMap, int current, int total); // 执行到了current, 一共total,使用deviceMap切换设备

int LLMSamplingOnly(Data &logits, int outerOffset, const GenerationConfig &config);
Expand Down
2 changes: 1 addition & 1 deletion main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,6 @@ int main(int argc, char **argv) {
}, generationConfig);
messages.push_back(std::make_pair("assistant", ret));
}

fastllm::Finalize();
return 0;
}
4 changes: 3 additions & 1 deletion src/devices/ascend/fastllm-acl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ void showError(aclError state, char const* const message, const char* const file
int const line) {
if (ACL_SUCCESS != state) {
printf("%s AsecndCL error = %d at %s:%d\n", message, state, file, line);
if (state >= 500000)
if (state >= 500000) {
aclFinalize();
exit(state);
}
}
}

Expand Down
6 changes: 6 additions & 0 deletions src/fastllm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3140,4 +3140,10 @@ namespace fastllm {
std::map <std::string, int> GetDeviceMap() {
return defaultDeviceMap;
}

void Finalize() {
#ifdef USE_ASCEND_NPU
npu::FastllmAclFinalize();
#endif
}
}

0 comments on commit e56280a

Please sign in to comment.