gpu_info.h 1.63 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
#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)
12
#define LOAD_ERR() strdup(dlerror())
13
14
15
16
17
18
#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)
19
20
21
22
23
24
25
26
#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; \
})
27
28
29

#endif

30
#ifndef LOG
31
32
33
34
35
36
#define LOG(verbose, ...) \
  do { \
    if (verbose) { \
      fprintf(stderr, __VA_ARGS__); \
    } \
  } while (0)
37
#endif
38

39
40
41
42
#ifdef __cplusplus
extern "C" {
#endif

Daniel Hiltgen's avatar
Daniel Hiltgen committed
43
#define GPU_ID_LEN 64
Daniel Hiltgen's avatar
Daniel Hiltgen committed
44
#define GPU_NAME_LEN 96
Daniel Hiltgen's avatar
Daniel Hiltgen committed
45

46
typedef struct mem_info {
Daniel Hiltgen's avatar
Daniel Hiltgen committed
47
48
  char *err;  // If non-nill, caller responsible for freeing
  char gpu_id[GPU_ID_LEN];
Daniel Hiltgen's avatar
Daniel Hiltgen committed
49
  char gpu_name[GPU_NAME_LEN];
50
51
  uint64_t total;
  uint64_t free;
52
  uint64_t used;
Daniel Hiltgen's avatar
Daniel Hiltgen committed
53
54
55
56

  // Compute Capability
  int major; 
  int minor;
Daniel Hiltgen's avatar
Daniel Hiltgen committed
57
  int patch;
58
59
60
61
62
63
64
65
} mem_info_t;

void cpu_check_ram(mem_info_t *resp);

#ifdef __cplusplus
}
#endif

66
#include "gpu_info_cudart.h"
67
#include "gpu_info_nvcuda.h"
68
#include "gpu_info_nvml.h"
Wang,Zhe's avatar
Wang,Zhe committed
69
#include "gpu_info_oneapi.h"
70
71

#endif  // __GPU_INFO_H__
Michael Yang's avatar
lint  
Michael Yang committed
72
#endif  // __APPLE__