File tree Expand file tree Collapse file tree 2 files changed +20
-3
lines changed Expand file tree Collapse file tree 2 files changed +20
-3
lines changed Original file line number Diff line number Diff line change 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();
103104void ggml_cann_set_device (int32_t device);
104105int32_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 }
Original file line number Diff line number Diff 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 {
731743std::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);
You can’t perform that action at this time.
0 commit comments