Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use up-to-date Cuda driver functions #10

Merged
merged 2 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/memonitor-sys/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "memonitor-sys"
description = "Automatically generated bindings for some of memonitor's backends."
version = "0.2.2"
version = "0.2.3"
authors = ["Pedro Valente <[email protected]>"]
license = "Apache-2.0"
repository = "https://github.com/edgenai/memonitor"
Expand Down
42 changes: 23 additions & 19 deletions crates/memonitor-sys/cuda/src/memonitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,18 @@ typedef void* mod_type;
#endif

typedef int CUresult;
struct CUctx_st;
typedef struct CUctx_st *CUcontext;
typedef int CUdevice_v1;
typedef CUdevice_v1 *CUdevice;
struct CUctx_opaque;
typedef struct CUctx_opaque *CUcontext;
typedef int CUdevice_opaque;
typedef CUdevice_opaque *CUdevice;
struct CUexecAffinityParam {
int type;
unsigned int count;
};

typedef CUresult(*cuInit_type)(unsigned int);

typedef CUresult (*cuCtxCreate_type)(CUcontext *, unsigned int, CUdevice);
typedef CUresult (*cuCtxCreate_type)(CUcontext *, struct CUexecAffinityParam *, int, unsigned int, CUdevice);

typedef CUresult (*cuCtxDestroy_type)(CUcontext);

Expand All @@ -43,7 +47,7 @@ typedef CUresult (*cuMemGetInfo_type)(size_t *, size_t *);

struct Device {
CUdevice handle;
CUdevice_v1 inner;
CUdevice_opaque inner;
};

static mod_type module = NULL;
Expand All @@ -69,16 +73,16 @@ int cu_init() {
}

cuInit = (cuInit_type) GetProcAddress(module, "cuInit");
cuCtxCreate = (cuCtxCreate_type) GetProcAddress(module, "cuCtxCreate");
cuCtxDestroy = (cuCtxDestroy_type) GetProcAddress(module, "cuCtxDestroy");
cuCtxPopCurrent = (cuCtxPopCurrent_type) GetProcAddress(module, "cuCtxPopCurrent");
cuCtxPushCurrent = (cuCtxPushCurrent_type) GetProcAddress(module, "cuCtxPushCurrent");
cuCtxCreate = (cuCtxCreate_type) GetProcAddress(module, "cuCtxCreate_v3");
cuCtxDestroy = (cuCtxDestroy_type) GetProcAddress(module, "cuCtxDestroy_v2");
cuCtxPopCurrent = (cuCtxPopCurrent_type) GetProcAddress(module, "cuCtxPopCurrent_v2");
cuCtxPushCurrent = (cuCtxPushCurrent_type) GetProcAddress(module, "cuCtxPushCurrent_v2");
cuCtxSetCurrent = (cuCtxSetCurrent_type) GetProcAddress(module, "cuCtxSetCurrent");
cuDeviceGetCount = (cuDeviceGetCount_type) GetProcAddress(module, "cuDeviceGetCount");
cuDeviceGet = (cuDeviceGet_type) GetProcAddress(module, "cuDeviceGet");
cuDeviceGetName = (cuDeviceGetName_type) GetProcAddress(module, "cuDeviceGetName");
cuDeviceTotalMem = (cuDeviceTotalMem_type) GetProcAddress(module, "cuDeviceTotalMem");
cuMemGetInfo = (cuMemGetInfo_type) GetProcAddress(module, "cuMemGetInfo");
cuDeviceTotalMem = (cuDeviceTotalMem_type) GetProcAddress(module, "cuDeviceTotalMem_v2");
cuMemGetInfo = (cuMemGetInfo_type) GetProcAddress(module, "cuMemGetInfo_v2");
#elif defined(__APPLE__)
return -1;
#else
Expand All @@ -88,16 +92,16 @@ int cu_init() {
}

cuInit = (cuInit_type) dlsym(module, "cuInit");
cuCtxCreate = (cuCtxCreate_type) dlsym(module, "cuCtxCreate");
cuCtxDestroy = (cuCtxDestroy_type) dlsym(module, "cuCtxDestroy");
cuCtxPopCurrent = (cuCtxPopCurrent_type) dlsym(module, "cuCtxPopCurrent");
cuCtxPushCurrent = (cuCtxPushCurrent_type) dlsym(module, "cuCtxPushCurrent");
cuCtxCreate = (cuCtxCreate_type) dlsym(module, "cuCtxCreate_v3");
cuCtxDestroy = (cuCtxDestroy_type) dlsym(module, "cuCtxDestroy_v2");
cuCtxPopCurrent = (cuCtxPopCurrent_type) dlsym(module, "cuCtxPopCurrent_v2");
cuCtxPushCurrent = (cuCtxPushCurrent_type) dlsym(module, "cuCtxPushCurrent_v2");
cuCtxSetCurrent = (cuCtxSetCurrent_type) dlsym(module, "cuCtxSetCurrent");
cuDeviceGetCount = (cuDeviceGetCount_type) dlsym(module, "cuDeviceGetCount");
cuDeviceGet = (cuDeviceGet_type) dlsym(module, "cuDeviceGet");
cuDeviceGetName = (cuDeviceGetName_type) dlsym(module, "cuDeviceGetName");
cuDeviceTotalMem = (cuDeviceTotalMem_type) dlsym(module, "cuDeviceTotalMem");
cuMemGetInfo = (cuMemGetInfo_type) dlsym(module, "cuMemGetInfo");
cuDeviceTotalMem = (cuDeviceTotalMem_type) dlsym(module, "cuDeviceTotalMem_v2");
cuMemGetInfo = (cuMemGetInfo_type) dlsym(module, "cuMemGetInfo_v2");
#endif

CUresult res = cuInit(0);
Expand Down Expand Up @@ -159,7 +163,7 @@ struct cu_Devices cu_list_devices() {
return invalid_devices;
}

res = cuCtxCreate(&ctx_handles[d], 0, device_handles[d].handle);
res = cuCtxCreate(&ctx_handles[d], NULL, 0, 0, device_handles[d].handle);
if (res != 0) {
free(device_handles);
free(ctx_handles);
Expand Down
4 changes: 2 additions & 2 deletions crates/memonitor/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "memonitor"
description = "Query CPU and GPU memory information in a portable way."
version = "0.2.2"
version = "0.2.3"
authors = ["Pedro Valente <[email protected]>"]
license = "Apache-2.0"
repository = "https://github.com/edgenai/memonitor"
Expand All @@ -10,7 +10,7 @@ edition = "2021"
publish = true

[dependencies]
memonitor-sys = { path = "../memonitor-sys", version = "0.2.2", default-features = false }
memonitor-sys = { path = "../memonitor-sys", version = "0.2.3", default-features = false }
once_cell = "1.19.0"
sysinfo = "0.30.7"
tracing = "0.1.40"
Expand Down
Loading