@@ -79,13 +79,31 @@ void *allocate_buffer_allocator_memory(size_t total_size,
7979 }
8080#ifdef USE_ASCEND_DIRECT
8181 if (protocol == " ascend" && total_size > 0 ) {
82- void *buffer = nullptr ;
83- auto ret = aclrtMallocHost (&buffer, total_size);
82+ aclrtDrvMemHandle handle = nullptr ;
83+ aclrtPhysicalMemProp prop = {};
84+ prop.handleType = ACL_MEM_HANDLE_TYPE_NONE;
85+ prop.allocationType = ACL_MEM_ALLOCATION_TYPE_PINNED;
86+ prop.memAttr = ACL_DDR_MEM_HUGE;
87+ prop.location .type = ACL_MEM_LOCATION_TYPE_HOST;
88+ prop.location .id = 0 ;
89+ prop.reserve = 0 ;
90+ auto ret = aclrtMallocPhysical (&handle, total_size, &prop, 0 );
8491 if (ret != ACL_ERROR_NONE) {
8592 LOG (ERROR) << " Failed to allocate memory: " << ret;
8693 return nullptr ;
8794 }
88- return buffer;
95+ void *va;
96+ ret = aclrtReserveMemAddress (&va, total_size, 0 , nullptr , 1 );
97+ if (ret != ACL_ERROR_NONE) {
98+ LOG (ERROR) << " Failed to reserve memory: " << ret;
99+ return nullptr ;
100+ }
101+ ret = aclrtMapMem (va, total_size, 0 , handle, 0 );
102+ if (ret != ACL_ERROR_NONE) {
103+ LOG (ERROR) << " Failed to map memory: " << ret;
104+ return nullptr ;
105+ }
106+ return va;
89107 }
90108#endif
91109 // Allocate aligned memory
@@ -95,7 +113,9 @@ void *allocate_buffer_allocator_memory(size_t total_size,
95113void free_memory (const std::string &protocol, void *ptr) {
96114#ifdef USE_ASCEND_DIRECT
97115 if (protocol == " ascend" ) {
98- aclrtFreeHost (ptr);
116+ aclrtUnmapMem (ptr);
117+ aclrtReleaseMemAddress (ptr);
118+ // TODO retain & free physical
99119 return ;
100120 }
101121#endif
0 commit comments