diff --git a/gpgpu-testcase/driver/include/ventus.h b/gpgpu-testcase/driver/include/ventus.h index 6aaa5417..2ccac664 100644 --- a/gpgpu-testcase/driver/include/ventus.h +++ b/gpgpu-testcase/driver/include/ventus.h @@ -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 设备端保存数据的起始虚拟地址 diff --git a/spike_main/spike_device.cc b/spike_main/spike_device.cc index 51cd4759..68cb0701 100644 --- a/spike_main/spike_device.cc +++ b/spike_main/spike_device.cc @@ -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::iterator it = buffer.begin(); it != buffer.end(); it++ ) + if(it->base == paddr) { + it = buffer.erase(it); + break; + } + for (std::vector>::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); @@ -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; } diff --git a/spike_main/spike_main.h b/spike_main/spike_main.h index 55bd9f87..73069bbc 100644 --- a/spike_main/spike_main.h +++ b/spike_main/spike_main.h @@ -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);