Skip to content

Commit

Permalink
[fix] fix memory access fault in hw and memory leak
Browse files Browse the repository at this point in the history
(cherry picked from commit 9d27a64)
  • Loading branch information
oywd authored and yangzexia committed Nov 30, 2023
1 parent 146367d commit 4ae0ed4
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
9 changes: 9 additions & 0 deletions gpgpu-testcase/driver/include/ventus.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@ int vt_buf_alloc(vt_device_h hdevice, uint64_t size, uint64_t *vaddr, int BUF_TY
/// @return 若无错误则返回0,否则返回-1
int vt_buf_free(vt_device_h hdevice, uint64_t size, uint64_t *vaddr, uint64_t taskID, uint64_t kernelID);

/// @brief 【已实现】释放指定buffer
/// @param hbuffer 指向设备的指针
/// @param size buffer大小
/// @param vaddr 要释放的设备端内存的起始地址
/// @param taskID context ID
/// @param kernelID kernel IDD
/// @return 若无错误则返回0,否则返回-1
int vt_one_buf_free(vt_device_h hdevice, uint64_t size, uint64_t *vaddr, uint64_t taskID, uint64_t kernelID);

/// @brief 【已实现】将数据从buffer复制到设备内存
/// @param hdevice 指向设备的指针
/// @param dev_vaddr 设备端保存数据的起始虚拟地址
Expand Down
17 changes: 17 additions & 0 deletions spike_main/spike_device.cc
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,22 @@ int spike_device::free_local_mem(){
return 0;
}

// todo: the memory management should be rewrite
int spike_device::free_local_mem(uint64_t paddr) {
for (std::vector<mem_cfg_t>::iterator it = buffer.begin(); it != buffer.end(); it++ )
if(it->base == paddr) {
it = buffer.erase(it);
break;
}
for (std::vector<std::pair<reg_t, mem_t*>>::iterator it = buffer_data.begin(); it != buffer_data.end(); it++ )
if(it->first == paddr) {
delete it->second;
it = buffer_data.erase(it);
break;
}
return 0;
}

int spike_device::copy_to_dev(uint64_t vaddr, uint64_t size,const void *data){
uint64_t i=0;
printf("to copy to 0x%lx with %ld bytes\n",vaddr,size);
Expand Down Expand Up @@ -638,6 +654,7 @@ int spike_device::run(meta_data* knl_data,uint64_t knl_start_pc){
for (auto& plugin_device : plugin_devices)
delete plugin_device.second;
delete[] argv;
delete sim;
return return_code;
}

1 change: 1 addition & 0 deletions spike_main/spike_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class spike_device{
int alloc_const_mem(uint64_t size, uint64_t *dev_maddr);
int alloc_local_mem(uint64_t size, uint64_t *dev_maddr);
int free_local_mem();
int free_local_mem(uint64_t paddr);
int copy_to_dev(uint64_t dev_maddr, uint64_t size,const void* data);
int copy_from_dev(uint64_t dev_maddr, uint64_t size,void* data);
int run(meta_data* knl_data,uint64_t knl_start_pc);
Expand Down

0 comments on commit 4ae0ed4

Please sign in to comment.