@@ -1,25 +1,29 @@
|
||||
#include <iostream>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <sys/mman.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <vector>
|
||||
#include <atomic>
|
||||
#include <fcntl.h>
|
||||
#include <mutex>
|
||||
#include <signal.h>
|
||||
#include <string.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <vector>
|
||||
|
||||
#include "acl/acl.h"
|
||||
|
||||
#include "shm_manager.h"
|
||||
#include "npu_helper.h"
|
||||
#include "shm_manager.h"
|
||||
#include "spdlog/spdlog.h"
|
||||
|
||||
|
||||
static ShmManager *shm_manager = nullptr;
|
||||
|
||||
static inline double TO_GB(size_t bytes) {
|
||||
return static_cast<double>(bytes) / (1024.0 * 1024.0 * 1024.0);
|
||||
}
|
||||
|
||||
void handle_signal(int sig) {
|
||||
if (shm_manager) {
|
||||
shm_manager->stop_busy_loop();
|
||||
@@ -49,7 +53,7 @@ size_t get_reserved_vram_size() {
|
||||
reserved_vram_size = size_gb * 1024 * 1024 * 1024;
|
||||
} catch (const std::exception &e) {
|
||||
spdlog::warn("Failed to parse VNPU_RESERVED_VRAM_SIZE_GB: {}, using "
|
||||
"default 8GB",
|
||||
"default 8 GB",
|
||||
e.what());
|
||||
}
|
||||
}
|
||||
@@ -68,12 +72,13 @@ void ensure_context(unsigned long long device) {
|
||||
}
|
||||
|
||||
void init_acl() {
|
||||
int32_t deviceId=0;
|
||||
int32_t deviceId = 0;
|
||||
|
||||
aclError ret = aclrtSetDevice(deviceId);
|
||||
if (ret != ACL_ERROR_NONE) {
|
||||
throw std::runtime_error("aclrtSetDevice failed with acl error code: " +
|
||||
std::to_string(ret) + " " + __FILE__ + ":" + std::to_string(__LINE__));
|
||||
throw std::runtime_error(
|
||||
"aclrtSetDevice failed with acl error code: " + std::to_string(ret) +
|
||||
" " + __FILE__ + ":" + std::to_string(__LINE__));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,8 +114,9 @@ void alloc_physical(uint32_t device_id, aclrtDrvMemHandle &out_mem_handle,
|
||||
spdlog::error("aclrtGetMemInfo failed, error_code: {}", error_code);
|
||||
throw std::runtime_error("aclrtGetMemInfo failed");
|
||||
} else {
|
||||
spdlog::info("aclrtGetMemInfo succeeded, free_mem: {}, total: {}", free_mem,
|
||||
total);
|
||||
spdlog::info(
|
||||
"aclrtGetMemInfo succeeded, free_mem: {:.2f} GB, total: {:.2f} GB",
|
||||
TO_GB(free_mem), TO_GB(total));
|
||||
}
|
||||
|
||||
aclrtPhysicalMemProp prop = {};
|
||||
@@ -129,13 +135,14 @@ void alloc_physical(uint32_t device_id, aclrtDrvMemHandle &out_mem_handle,
|
||||
error_code);
|
||||
throw std::runtime_error("aclrtMemGetAllocationGranularity failed");
|
||||
} else {
|
||||
spdlog::info("aclrtMemGetAllocationGranularity succeeded, granularity: {}",
|
||||
spdlog::info("aclrtMemGetAllocationGranularity succeeded, granularity: {} bytes",
|
||||
granularity);
|
||||
}
|
||||
size_t reserved_mem_size = get_reserved_vram_size();
|
||||
if (free_mem < reserved_mem_size) {
|
||||
spdlog::error("Not enough free memory to reserve: {}, free_mem: {}",
|
||||
reserved_mem_size, free_mem);
|
||||
spdlog::error(
|
||||
"Not enough free memory to reserve: {:.2f} GB, free_mem: {:.2f} GB",
|
||||
TO_GB(reserved_mem_size), TO_GB(free_mem));
|
||||
throw std::runtime_error("Not enough free memory to reserve");
|
||||
}
|
||||
out_g_size = free_mem - reserved_mem_size;
|
||||
@@ -147,8 +154,8 @@ void alloc_physical(uint32_t device_id, aclrtDrvMemHandle &out_mem_handle,
|
||||
spdlog::error("aclrtMallocPhysical failed, error_code: {}", error_code);
|
||||
throw std::runtime_error("aclrtMallocPhysical failed");
|
||||
} else {
|
||||
spdlog::info("device {} aclrtMallocPhysical succeeded, size: {}", device_id,
|
||||
out_g_size);
|
||||
spdlog::info("device {} aclrtMallocPhysical succeeded, size: {:.2f} GB",
|
||||
device_id, TO_GB(out_g_size));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user