mirror of
https://github.com/vortexgpgpu/vortex.git
synced 2025-04-24 13:57:17 -04:00
adding vx_mem_info runtime API
This commit is contained in:
parent
ad110b74d8
commit
5e2b8709bd
9 changed files with 113 additions and 35 deletions
|
@ -18,6 +18,7 @@ public:
|
|||
, pageAlign_(pageAlign)
|
||||
, blockAlign_(blockAlign)
|
||||
, pages_(nullptr)
|
||||
, allocated_(0)
|
||||
{}
|
||||
|
||||
~MemoryAllocator() {
|
||||
|
@ -98,6 +99,9 @@ public:
|
|||
// Return the free block address
|
||||
*addr = freeBlock->addr;
|
||||
|
||||
// Update allocated size
|
||||
allocated_ += size;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -133,6 +137,8 @@ public:
|
|||
// Insert the block into the free M-list.
|
||||
currPage->InsertFreeMBlock(usedBlock);
|
||||
|
||||
auto size = usedBlock->size;
|
||||
|
||||
// Check if we can merge adjacent free blocks from the left.
|
||||
if (usedBlock->prevFreeM) {
|
||||
// Calculate the previous address
|
||||
|
@ -141,7 +147,7 @@ public:
|
|||
auto prevBlock = usedBlock->prevFreeM;
|
||||
|
||||
// Merge the blocks to the left
|
||||
prevBlock->size += usedBlock->size;
|
||||
prevBlock->size += size;
|
||||
prevBlock->nextFreeM = usedBlock->nextFreeM;
|
||||
if (prevBlock->nextFreeM) {
|
||||
prevBlock->nextFreeM->prevFreeM = prevBlock;
|
||||
|
@ -159,7 +165,7 @@ public:
|
|||
// Check if we can merge adjacent free blocks from the right.
|
||||
if (usedBlock->nextFreeM) {
|
||||
// Calculate the next allocation start address
|
||||
auto nextAddr = usedBlock->addr + usedBlock->size;
|
||||
auto nextAddr = usedBlock->addr + size;
|
||||
if (usedBlock->nextFreeM->addr == nextAddr) {
|
||||
auto nextBlock = usedBlock->nextFreeM;
|
||||
|
||||
|
@ -188,7 +194,14 @@ public:
|
|||
|
||||
}
|
||||
|
||||
return 0;
|
||||
// update allocated size
|
||||
allocated_ -= size;
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
uint64_t allocated() const {
|
||||
return allocated_;
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -406,8 +419,9 @@ private:
|
|||
uint64_t nextAddress_;
|
||||
uint64_t maxAddress_;
|
||||
uint32_t pageAlign_;
|
||||
uint32_t blockAlign_;
|
||||
page_t* pages_;
|
||||
uint32_t blockAlign_;
|
||||
page_t* pages_;
|
||||
uint64_t allocated_;
|
||||
};
|
||||
|
||||
} // namespace vortex
|
|
@ -24,4 +24,5 @@ void perf_remove_device(vx_device_h device);
|
|||
|
||||
#define CACHE_BLOCK_SIZE 64
|
||||
#define ALLOC_BASE_ADDR CACHE_BLOCK_SIZE
|
||||
#define LOCAL_MEM_SIZE 4294967296 // 4 GB
|
||||
#define ALLOC_MAX_ADDR 0x080000000 // 2 GB
|
||||
#define LOCAL_MEM_SIZE 0x100000000 // 4 GB
|
|
@ -20,9 +20,8 @@ typedef void* vx_buffer_h;
|
|||
#define VX_CAPS_MAX_THREADS 0x3
|
||||
#define VX_CAPS_CACHE_LINE_SIZE 0x4
|
||||
#define VX_CAPS_LOCAL_MEM_SIZE 0x5
|
||||
#define VX_CAPS_ALLOC_BASE_ADDR 0x6
|
||||
#define VX_CAPS_KERNEL_BASE_ADDR 0x7
|
||||
#define VX_CAPS_ISA_FLAGS 0x8
|
||||
#define VX_CAPS_KERNEL_BASE_ADDR 0x6
|
||||
#define VX_CAPS_ISA_FLAGS 0x7
|
||||
|
||||
// device isa flags
|
||||
#define VX_ISA_STD_A (1ull << 0)
|
||||
|
@ -68,6 +67,9 @@ int vx_mem_alloc(vx_device_h hdevice, uint64_t size, uint64_t* dev_maddr);
|
|||
// release device memory
|
||||
int vx_mem_free(vx_device_h hdevice, uint64_t dev_maddr);
|
||||
|
||||
// get device memory info
|
||||
int vx_mem_info(vx_device_h hdevice, uint64_t* mem_free, uint64_t* mem_total);
|
||||
|
||||
// Copy bytes from buffer to device local memory
|
||||
int vx_copy_to_dev(vx_buffer_h hbuffer, uint64_t dev_maddr, uint64_t size, uint64_t src_offset);
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ public:
|
|||
vx_device()
|
||||
: mem_allocator(
|
||||
ALLOC_BASE_ADDR,
|
||||
ALLOC_BASE_ADDR + LOCAL_MEM_SIZE,
|
||||
ALLOC_MAX_ADDR,
|
||||
4096,
|
||||
CACHE_BLOCK_SIZE)
|
||||
{}
|
||||
|
|
|
@ -65,9 +65,6 @@ extern int vx_dev_caps(vx_device_h hdevice, uint32_t caps_id, uint64_t *value) {
|
|||
case VX_CAPS_LOCAL_MEM_SIZE:
|
||||
*value = LOCAL_MEM_SIZE;
|
||||
break;
|
||||
case VX_CAPS_ALLOC_BASE_ADDR:
|
||||
*value = ALLOC_BASE_ADDR;
|
||||
break;
|
||||
case VX_CAPS_KERNEL_BASE_ADDR:
|
||||
*value = device->dcrs.read(DCR_BASE_STARTUP_ADDR);
|
||||
break;
|
||||
|
@ -252,6 +249,20 @@ extern int vx_mem_free(vx_device_h hdevice, uint64_t dev_maddr) {
|
|||
return device->mem_allocator.release(dev_maddr);
|
||||
}
|
||||
|
||||
extern int vx_mem_info(vx_device_h hdevice, uint64_t* mem_free, uint64_t* mem_total) {
|
||||
if (nullptr == hdevice)
|
||||
return -1;
|
||||
|
||||
auto device = ((vx_device*)hdevice);
|
||||
if (mem_free) {
|
||||
*mem_free = (ALLOC_MAX_ADDR - ALLOC_BASE_ADDR) - device->mem_allocator.allocated();
|
||||
}
|
||||
if (mem_total) {
|
||||
*mem_total = (ALLOC_MAX_ADDR - ALLOC_BASE_ADDR);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
extern int vx_buf_alloc(vx_device_h hdevice, uint64_t size, vx_buffer_h* hbuffer) {
|
||||
void* host_ptr;
|
||||
uint64_t wsid;
|
||||
|
|
|
@ -69,7 +69,7 @@ public:
|
|||
: ram_(RAM_PAGE_SIZE)
|
||||
, mem_allocator_(
|
||||
ALLOC_BASE_ADDR,
|
||||
ALLOC_BASE_ADDR + LOCAL_MEM_SIZE,
|
||||
ALLOC_MAX_ADDR,
|
||||
RAM_PAGE_SIZE,
|
||||
CACHE_BLOCK_SIZE)
|
||||
{
|
||||
|
@ -82,14 +82,18 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
int alloc_local_mem(uint64_t size, uint64_t* dev_maddr) {
|
||||
int mem_alloc(uint64_t size, uint64_t* dev_maddr) {
|
||||
return mem_allocator_.allocate(size, dev_maddr);
|
||||
}
|
||||
|
||||
int free_local_mem(uint64_t dev_maddr) {
|
||||
int mem_free(uint64_t dev_maddr) {
|
||||
return mem_allocator_.release(dev_maddr);
|
||||
}
|
||||
|
||||
uint64_t mem_used() const {
|
||||
return mem_allocator_.allocated();
|
||||
}
|
||||
|
||||
int upload(const void* src, uint64_t dest_addr, uint64_t size, uint64_t src_offset) {
|
||||
uint64_t asize = aligned_size(size, CACHE_BLOCK_SIZE);
|
||||
if (dest_addr + asize > LOCAL_MEM_SIZE)
|
||||
|
@ -203,9 +207,6 @@ extern int vx_dev_caps(vx_device_h hdevice, uint32_t caps_id, uint64_t *value) {
|
|||
case VX_CAPS_LOCAL_MEM_SIZE:
|
||||
*value = LOCAL_MEM_SIZE;
|
||||
break;
|
||||
case VX_CAPS_ALLOC_BASE_ADDR:
|
||||
*value = ALLOC_BASE_ADDR;
|
||||
break;
|
||||
case VX_CAPS_KERNEL_BASE_ADDR:
|
||||
*value = device->read_dcr(DCR_BASE_STARTUP_ADDR);
|
||||
break;
|
||||
|
@ -266,7 +267,7 @@ extern int vx_mem_alloc(vx_device_h hdevice, uint64_t size, uint64_t* dev_maddr)
|
|||
return -1;
|
||||
|
||||
vx_device *device = ((vx_device*)hdevice);
|
||||
return device->alloc_local_mem(size, dev_maddr);
|
||||
return device->mem_alloc(size, dev_maddr);
|
||||
}
|
||||
|
||||
extern int vx_mem_free(vx_device_h hdevice, uint64_t dev_maddr) {
|
||||
|
@ -274,7 +275,21 @@ extern int vx_mem_free(vx_device_h hdevice, uint64_t dev_maddr) {
|
|||
return -1;
|
||||
|
||||
vx_device *device = ((vx_device*)hdevice);
|
||||
return device->free_local_mem(dev_maddr);
|
||||
return device->mem_free(dev_maddr);
|
||||
}
|
||||
|
||||
extern int vx_mem_info(vx_device_h hdevice, uint64_t* mem_free, uint64_t* mem_total) {
|
||||
if (nullptr == hdevice)
|
||||
return -1;
|
||||
|
||||
auto device = ((vx_device*)hdevice);
|
||||
if (mem_free) {
|
||||
*mem_free = (ALLOC_MAX_ADDR - ALLOC_BASE_ADDR) - device->mem_used();
|
||||
}
|
||||
if (mem_total) {
|
||||
*mem_total = (ALLOC_MAX_ADDR - ALLOC_BASE_ADDR);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
extern int vx_buf_alloc(vx_device_h hdevice, uint64_t size, vx_buffer_h* hbuffer) {
|
||||
|
|
|
@ -79,7 +79,7 @@ public:
|
|||
, processor_(arch_)
|
||||
, mem_allocator_(
|
||||
ALLOC_BASE_ADDR,
|
||||
ALLOC_BASE_ADDR + LOCAL_MEM_SIZE,
|
||||
ALLOC_MAX_ADDR,
|
||||
RAM_PAGE_SIZE,
|
||||
CACHE_BLOCK_SIZE)
|
||||
{
|
||||
|
@ -93,14 +93,18 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
int alloc_local_mem(uint64_t size, uint64_t* dev_maddr) {
|
||||
int mem_alloc(uint64_t size, uint64_t* dev_maddr) {
|
||||
return mem_allocator_.allocate(size, dev_maddr);
|
||||
}
|
||||
|
||||
int free_local_mem(uint64_t dev_maddr) {
|
||||
int mem_free(uint64_t dev_maddr) {
|
||||
return mem_allocator_.release(dev_maddr);
|
||||
}
|
||||
|
||||
uint64_t mem_used() const {
|
||||
return mem_allocator_.allocated();
|
||||
}
|
||||
|
||||
int upload(const void* src, uint64_t dest_addr, uint64_t size, uint64_t src_offset) {
|
||||
uint64_t asize = aligned_size(size, CACHE_BLOCK_SIZE);
|
||||
if (dest_addr + asize > LOCAL_MEM_SIZE)
|
||||
|
@ -251,9 +255,6 @@ extern int vx_dev_caps(vx_device_h hdevice, uint32_t caps_id, uint64_t *value) {
|
|||
case VX_CAPS_LOCAL_MEM_SIZE:
|
||||
*value = LOCAL_MEM_SIZE;
|
||||
break;
|
||||
case VX_CAPS_ALLOC_BASE_ADDR:
|
||||
*value = ALLOC_BASE_ADDR;
|
||||
break;
|
||||
case VX_CAPS_KERNEL_BASE_ADDR:
|
||||
*value = device->read_dcr(DCR_BASE_STARTUP_ADDR);
|
||||
break;
|
||||
|
@ -276,7 +277,7 @@ extern int vx_mem_alloc(vx_device_h hdevice, uint64_t size, uint64_t* dev_maddr)
|
|||
return -1;
|
||||
|
||||
vx_device *device = ((vx_device*)hdevice);
|
||||
return device->alloc_local_mem(size, dev_maddr);
|
||||
return device->mem_alloc(size, dev_maddr);
|
||||
}
|
||||
|
||||
extern int vx_mem_free(vx_device_h hdevice, uint64_t dev_maddr) {
|
||||
|
@ -284,7 +285,21 @@ extern int vx_mem_free(vx_device_h hdevice, uint64_t dev_maddr) {
|
|||
return -1;
|
||||
|
||||
vx_device *device = ((vx_device*)hdevice);
|
||||
return device->free_local_mem(dev_maddr);
|
||||
return device->mem_free(dev_maddr);
|
||||
}
|
||||
|
||||
extern int vx_mem_info(vx_device_h hdevice, uint64_t* mem_free, uint64_t* mem_total) {
|
||||
if (nullptr == hdevice)
|
||||
return -1;
|
||||
|
||||
auto device = ((vx_device*)hdevice);
|
||||
if (mem_free) {
|
||||
*mem_free = (ALLOC_MAX_ADDR - ALLOC_BASE_ADDR) - device->mem_used();
|
||||
}
|
||||
if (mem_total) {
|
||||
*mem_total = (ALLOC_MAX_ADDR - ALLOC_BASE_ADDR);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
extern int vx_buf_alloc(vx_device_h hdevice, uint64_t size, vx_buffer_h* hbuffer) {
|
||||
|
|
|
@ -16,10 +16,15 @@ extern int vx_mem_alloc(vx_device_h /*hdevice*/, uint64_t /*size*/, uint64_t* /*
|
|||
return -1;
|
||||
}
|
||||
|
||||
int vx_mem_free(vx_device_h /*hdevice*/, uint64_t /*dev_maddr*/) {
|
||||
extern int vx_mem_free(vx_device_h /*hdevice*/, uint64_t /*dev_maddr*/) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// get device memory info
|
||||
extern int vx_mem_info(vx_device_h /*hdevice*/, uint64_t* /*mem_free*/, uint64_t* /*mem_total*/) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
extern int vx_buf_alloc(vx_device_h /*hdevice*/, uint64_t /*size*/, vx_buffer_h* /*hbuffer*/) {
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -133,7 +133,7 @@ public:
|
|||
, bank_size_(bank_size)
|
||||
, mem_allocator_(
|
||||
ALLOC_BASE_ADDR,
|
||||
ALLOC_BASE_ADDR + LOCAL_MEM_SIZE,
|
||||
ALLOC_MAX_ADDR,
|
||||
4096,
|
||||
CACHE_BLOCK_SIZE)
|
||||
{}
|
||||
|
@ -207,6 +207,10 @@ public:
|
|||
return 0;
|
||||
}
|
||||
|
||||
uint64_t mem_used() const {
|
||||
return mem_allocator_.allocated();
|
||||
}
|
||||
|
||||
int get_buffer(uint32_t bank_id, xrt_buffer_t* pBuf) {
|
||||
auto it = xrtBuffers_.find(bank_id);
|
||||
if (it != xrtBuffers_.end()) {
|
||||
|
@ -324,9 +328,6 @@ extern int vx_dev_caps(vx_device_h hdevice, uint32_t caps_id, uint64_t *value) {
|
|||
case VX_CAPS_LOCAL_MEM_SIZE:
|
||||
*value = LOCAL_MEM_SIZE;
|
||||
break;
|
||||
case VX_CAPS_ALLOC_BASE_ADDR:
|
||||
*value = ALLOC_BASE_ADDR;
|
||||
break;
|
||||
case VX_CAPS_KERNEL_BASE_ADDR:
|
||||
*value = device->dcrs.read(DCR_BASE_STARTUP_ADDR);
|
||||
break;
|
||||
|
@ -559,7 +560,7 @@ extern int vx_mem_alloc(vx_device_h hdevice, uint64_t size, uint64_t* dev_maddr)
|
|||
return device->mem_alloc(size, dev_maddr);
|
||||
}
|
||||
|
||||
int vx_mem_free(vx_device_h hdevice, uint64_t dev_maddr) {
|
||||
extern int vx_mem_free(vx_device_h hdevice, uint64_t dev_maddr) {
|
||||
if (nullptr == hdevice)
|
||||
return -1;
|
||||
|
||||
|
@ -567,6 +568,20 @@ int vx_mem_free(vx_device_h hdevice, uint64_t dev_maddr) {
|
|||
return device->mem_free(dev_maddr);
|
||||
}
|
||||
|
||||
extern int vx_mem_info(vx_device_h hdevice, uint64_t* mem_free, uint64_t* mem_total) {
|
||||
if (nullptr == hdevice)
|
||||
return -1;
|
||||
|
||||
auto device = (vx_device*)hdevice;
|
||||
if (mem_free) {
|
||||
*mem_free = (ALLOC_MAX_ADDR - ALLOC_BASE_ADDR) - device->mem_used();
|
||||
}
|
||||
if (mem_total) {
|
||||
*mem_total = (ALLOC_MAX_ADDR - ALLOC_BASE_ADDR);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
extern int vx_buf_alloc(vx_device_h hdevice, uint64_t size, vx_buffer_h* hbuffer) {
|
||||
if (nullptr == hdevice)
|
||||
return -1;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue