Skip to content

Commit 724f12f

Browse files
committed
Adjust the GGML_CANN_ASYNC_MODE setting to accept yes, enable, 1, or on (case-insensitive) as valid options.
1 parent ee3299c commit 724f12f

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

ggml/src/ggml-cann/common.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include <thread>
3838
#include <unistd.h>
3939
#include <functional>
40+
#include <set>
4041

4142
#include "../include/ggml-cann.h"
4243
#include "../include/ggml.h"
@@ -103,6 +104,8 @@ const ggml_cann_device_info& ggml_cann_info();
103104
void ggml_cann_set_device(int32_t device);
104105
int32_t ggml_cann_get_device();
105106

107+
static std::string to_lower_case(const char* env_var);
108+
106109
/**
107110
* @brief Abstract base class for memory pools used by CANN.
108111
*/
@@ -354,7 +357,10 @@ struct ggml_backend_cann_context {
354357
: device(device), name("CANN" + std::to_string(device)), task_queue(1024, device) {
355358
ggml_cann_set_device(device);
356359
description = aclrtGetSocName();
357-
async_mode = (getenv("GGML_CANN_ASYNC_MODE") != nullptr);
360+
361+
std::string value = to_lower_case(getenv("GGML_CANN_ASYNC_MODE"));
362+
std::set<std::string> valid_values = {"on", "1", "yes", "enable"};
363+
async_mode = valid_values.find(value) != valid_values.end();
358364
GGML_LOG_INFO("%s: device %d async operator submission is %s\n", __func__,
359365
device, async_mode ? "ON" : "OFF");
360366
}

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,18 @@ int32_t ggml_cann_get_device() {
9292
return id;
9393
}
9494

95+
/**
96+
* @brief Convert the value obtained from getenv to a lowercase std::string.
97+
*
98+
* @param env_var C-style string(char*)
99+
* @return A string of type std::stringD.
100+
*/
101+
static std::string to_lower_case(const char* env_var){
102+
std::string mem_pool_type(env_var ? env_var : "");
103+
std::transform(mem_pool_type.begin(), mem_pool_type.end(), mem_pool_type.begin(), ::tolower);
104+
return mem_pool_type;
105+
}
106+
95107
/**
96108
* @brief Initialize the CANN device information.
97109
*
@@ -731,8 +743,7 @@ struct ggml_cann_pool_vmm : public ggml_cann_pool {
731743
std::unique_ptr<ggml_cann_pool> ggml_backend_cann_context::new_pool_for_device(
732744
int device) {
733745
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);
746+
std::string mem_pool_type = to_lower_case(env_var);
736747

737748
if (mem_pool_type == "prio") {
738749
GGML_LOG_INFO("%s: device %d use buffer pool with priority queue\n", __func__, device);

0 commit comments

Comments
 (0)