Skip to content

Commit 2d48944

Browse files
committed
Simplify the environment variable setting to specify the memory pool type.
1 parent cf0a43b commit 2d48944

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

ggml/src/ggml-cann/ggml-cann.cpp

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ struct ggml_cann_pool_buf_prio : public ggml_cann_pool {
213213
* @param device The device ID to associate with this buffer pool.
214214
*/
215215
explicit ggml_cann_pool_buf_prio(int device) : device(device) {
216-
disable_clean = getenv("GGML_CANN_DISABLE_BUF_POOL_CLEAN") != nullptr;
216+
disable_clean = getenv("GGML_CANN_POOL_DISABLE_CLEAN") != nullptr;
217217
}
218218

219219
/**
@@ -409,7 +409,7 @@ struct ggml_cann_pool_buf : public ggml_cann_pool {
409409
* @param device The device ID to associate with this buffer pool.
410410
*/
411411
explicit ggml_cann_pool_buf(int device) : device(device) {
412-
disable_clean = getenv("GGML_CANN_DISABLE_BUF_POOL_CLEAN") != nullptr;
412+
disable_clean = getenv("GGML_CANN_POOL_DISABLE_CLEAN") != nullptr;
413413
}
414414

415415
/**
@@ -730,16 +730,23 @@ struct ggml_cann_pool_vmm : public ggml_cann_pool {
730730
*/
731731
std::unique_ptr<ggml_cann_pool> ggml_backend_cann_context::new_pool_for_device(
732732
int device) {
733-
bool disable_vmm = (getenv("GGML_CANN_DISABLE_VMM_POOL") != nullptr);
734-
if (!disable_vmm && ggml_cann_info().devices[device].vmm) {
735-
GGML_LOG_INFO("%s: device %d use vmm pool\n", __func__, device);
736-
return std::unique_ptr<ggml_cann_pool>(new ggml_cann_pool_vmm(device));
737-
}
738-
bool enable_buf_prio = (getenv("GGML_CANN_ENABLE_BUF_PRIO_POOL") != nullptr);
739-
if (enable_buf_prio) {
733+
const char* env_var = getenv("GGML_CANN_MEM_POOL");
734+
std::string mem_pool_type(env_var ? env_var : "");
735+
std::transform(mem_pool_type.begin(), mem_pool_type.end(), mem_pool_type.begin(), ::tolower);
736+
737+
if (mem_pool_type == "prio") {
740738
GGML_LOG_INFO("%s: device %d use buffer pool with priority queue\n", __func__, device);
741739
return std::unique_ptr<ggml_cann_pool>(new ggml_cann_pool_buf_prio(device));
742740
}
741+
742+
if (mem_pool_type.empty() && ggml_cann_info().devices[device].vmm) {
743+
GGML_LOG_INFO("%s: device %d use vmm pool\n", __func__, device);
744+
return std::unique_ptr<ggml_cann_pool>(new ggml_cann_pool_vmm(device));
745+
}else{
746+
GGML_LOG_INFO("%s: device %d use buffer pool\n", __func__, device);
747+
return std::unique_ptr<ggml_cann_pool>(new ggml_cann_pool_buf(device));
748+
}
749+
743750
GGML_LOG_INFO("%s: device %d use buffer pool\n", __func__, device);
744751
return std::unique_ptr<ggml_cann_pool>(new ggml_cann_pool_buf(device));
745752
}

0 commit comments

Comments
 (0)