Skip to content

Commit

Permalink
release gpu memory
Browse files Browse the repository at this point in the history
  • Loading branch information
Comma Device committed Jul 29, 2024
1 parent 5ebc65f commit b2ad0bd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
3 changes: 3 additions & 0 deletions selfdrive/modeld/thneed/thneed.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ class GPUMalloc {
private:
uint64_t base;
int remaining;
uint64_t mmapsize;
unsigned int alloc_id;
int gpu_fd;
};

class CLQueuedKernel {
Expand Down
17 changes: 14 additions & 3 deletions selfdrive/modeld/thneed/thneed_qcom2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -116,21 +116,32 @@ int ioctl(int filedes, unsigned long request, void *argp) {

// *********** GPUMalloc ***********

GPUMalloc::GPUMalloc(int size, int fd) {
GPUMalloc::GPUMalloc(int size, int fd) : gpu_fd(fd) {
struct kgsl_gpuobj_alloc alloc;
memset(&alloc, 0, sizeof(alloc));
alloc.size = size;
alloc.flags = 0x10000a00;
ioctl(fd, IOCTL_KGSL_GPUOBJ_ALLOC, &alloc);
ioctl(gpu_fd, IOCTL_KGSL_GPUOBJ_ALLOC, &alloc);
void *addr = mmap64(NULL, alloc.mmapsize, 0x3, 0x1, fd, alloc.id*0x1000);
assert(addr != MAP_FAILED);

base = (uint64_t)addr;
remaining = size;
mmapsize = alloc.mmapsize;
alloc_id = alloc.id;
}

GPUMalloc::~GPUMalloc() {
// TODO: free the GPU malloced area
// Unmap the allocated GPU memory
int ret = munmap((void *)base, mmapsize);
assert(ret == 0);

// Free the allocated GPU object
struct kgsl_gpuobj_free free_ioctl;
memset(&free_ioctl, 0, sizeof(free_ioctl));
free_ioctl.id = alloc_id;
ret = ioctl(gpu_fd, IOCTL_KGSL_GPUOBJ_FREE, &free_ioctl);
assert(ret == 0);
}

void *GPUMalloc::alloc(int size) {
Expand Down

0 comments on commit b2ad0bd

Please sign in to comment.