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 37
37
#include < thread>
38
38
#include < unistd.h>
39
39
#include < functional>
40
+ #include < set>
40
41
41
42
#include " ../include/ggml-cann.h"
42
43
#include " ../include/ggml.h"
@@ -103,6 +104,8 @@ const ggml_cann_device_info& ggml_cann_info();
103
104
void ggml_cann_set_device (int32_t device);
104
105
int32_t ggml_cann_get_device ();
105
106
107
+ static std::string to_lower_case (const char * env_var);
108
+
106
109
/* *
107
110
* @brief Abstract base class for memory pools used by CANN.
108
111
*/
@@ -354,7 +357,10 @@ struct ggml_backend_cann_context {
354
357
: device(device), name(" CANN" + std::to_string(device)), task_queue(1024 , device) {
355
358
ggml_cann_set_device (device);
356
359
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 ();
358
364
GGML_LOG_INFO (" %s: device %d async operator submission is %s\n " , __func__,
359
365
device, async_mode ? " ON" : " OFF" );
360
366
}
Original file line number Diff line number Diff line change @@ -92,6 +92,18 @@ int32_t ggml_cann_get_device() {
92
92
return id;
93
93
}
94
94
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
+
95
107
/* *
96
108
* @brief Initialize the CANN device information.
97
109
*
@@ -731,8 +743,7 @@ struct ggml_cann_pool_vmm : public ggml_cann_pool {
731
743
std::unique_ptr<ggml_cann_pool> ggml_backend_cann_context::new_pool_for_device (
732
744
int device) {
733
745
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);
736
747
737
748
if (mem_pool_type == " prio" ) {
738
749
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