2023-11-29 19:00:37 +00:00
|
|
|
#ifndef __APPLE__
|
|
|
|
#ifndef __GPU_INFO_H__
|
|
|
|
#define __GPU_INFO_H__
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#ifndef _WIN32
|
|
|
|
#include <dlfcn.h>
|
|
|
|
#define LOAD_LIBRARY(lib, flags) dlopen(lib, flags)
|
|
|
|
#define LOAD_SYMBOL(handle, sym) dlsym(handle, sym)
|
2023-12-22 23:43:31 +00:00
|
|
|
#define LOAD_ERR() strdup(dlerror())
|
2023-11-29 19:00:37 +00:00
|
|
|
#define UNLOAD_LIBRARY(handle) dlclose(handle)
|
|
|
|
#else
|
|
|
|
#include <windows.h>
|
|
|
|
#define LOAD_LIBRARY(lib, flags) LoadLibrary(lib)
|
|
|
|
#define LOAD_SYMBOL(handle, sym) GetProcAddress(handle, sym)
|
|
|
|
#define UNLOAD_LIBRARY(handle) FreeLibrary(handle)
|
2023-12-22 23:43:31 +00:00
|
|
|
#define LOAD_ERR() ({\
|
|
|
|
LPSTR messageBuffer = NULL; \
|
|
|
|
size_t size = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, \
|
|
|
|
NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)&messageBuffer, 0, NULL); \
|
|
|
|
char *resp = strdup(messageBuffer); \
|
|
|
|
LocalFree(messageBuffer); \
|
|
|
|
resp; \
|
|
|
|
})
|
2023-11-29 19:00:37 +00:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2024-01-23 00:03:32 +00:00
|
|
|
#define LOG(verbose, ...) \
|
|
|
|
do { \
|
|
|
|
if (verbose) { \
|
|
|
|
fprintf(stderr, __VA_ARGS__); \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
2023-11-29 19:00:37 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2024-03-30 16:50:05 +00:00
|
|
|
#define GPU_ID_LEN 64
|
|
|
|
|
2023-11-29 19:00:37 +00:00
|
|
|
typedef struct mem_info {
|
2024-03-30 16:50:05 +00:00
|
|
|
char *err; // If non-nill, caller responsible for freeing
|
|
|
|
char gpu_id[GPU_ID_LEN];
|
2023-11-29 19:00:37 +00:00
|
|
|
uint64_t total;
|
|
|
|
uint64_t free;
|
2024-03-30 16:50:05 +00:00
|
|
|
|
|
|
|
// Compute Capability
|
|
|
|
int major;
|
|
|
|
int minor;
|
2023-11-29 19:00:37 +00:00
|
|
|
} mem_info_t;
|
|
|
|
|
|
|
|
void cpu_check_ram(mem_info_t *resp);
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2024-03-25 15:07:44 +00:00
|
|
|
#include "gpu_info_cudart.h"
|
2023-11-29 19:00:37 +00:00
|
|
|
|
|
|
|
#endif // __GPU_INFO_H__
|
|
|
|
#endif // __APPLE__
|