From a15f20a2cc5a9d66fc0938138682033f2fb347b9 Mon Sep 17 00:00:00 2001 From: Dr-Noob Date: Wed, 11 Aug 2021 11:34:47 +0200 Subject: [PATCH] [v0.01] Defining a first approach of the application general structure --- Makefile | 2 +- src/common/gpu.cpp | 24 ++++++++++++++++++++++++ src/common/gpu.hpp | 39 ++++++++++++++++++++++++++++++++++++++- src/common/main.cpp | 15 ++++++++++++++- src/cuda/cuda.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++++ src/cuda/cuda.hpp | 3 +++ src/cuda/uarch.cpp | 4 ++++ src/cuda/uarch.hpp | 1 + 8 files changed, 129 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 152d1f1..d79bbec 100644 --- a/Makefile +++ b/Makefile @@ -16,7 +16,7 @@ CUDA_HDR = $(SRC_CUDA)cuda.hpp $(SRC_CUDA)uarch.hpp CUDA_PATH = /usr/local/cuda/ SOURCE += $(COMMON_SRC) $(CUDA_SRC) -HEADERS += $(COMMON_HDR) $(CUDA_HRC) +HEADERS += $(COMMON_HDR) $(CUDA_HDR) OUTPUT=gpufetch diff --git a/src/common/gpu.cpp b/src/common/gpu.cpp index 283f48a..e6cf603 100644 --- a/src/common/gpu.cpp +++ b/src/common/gpu.cpp @@ -1,6 +1,30 @@ #include "gpu.hpp" +#include char* get_str_gpu_name(struct gpu_info* gpu) { return gpu->name; } +char* get_str_freq(struct gpu_info* gpu) { + return NULL; +} + +char* get_str_memory_size(struct gpu_info* gpu) { + return NULL; +} + +char* get_str_memory_type(struct gpu_info* gpu) { + return NULL; +} + +char* get_str_l1(struct gpu_info* gpu) { + return NULL; +} + +char* get_str_l2(struct gpu_info* gpu) { + return NULL; +} + +char* get_str_peak_performance(struct gpu_info* gpu) { + return NULL; +} diff --git a/src/common/gpu.hpp b/src/common/gpu.hpp index edd547b..dd26dc0 100644 --- a/src/common/gpu.hpp +++ b/src/common/gpu.hpp @@ -8,15 +8,52 @@ enum { GPU_VENDOR_NVIDIA }; +enum { + MEMTYPE_GDDR6 +}; + typedef int32_t VENDOR; +typedef int32_t MEMTYPE; + +struct cach { + int32_t size; + uint8_t num_caches; + bool exists; +}; + +struct cache { + struct cach* L1; + struct cach* L2; +}; + +struct topology { + int32_t shared_mp; + int32_t cores_per_mp; + int32_t cuda_cores; +}; + +struct memory { + int32_t size_bytes; + MEMTYPE type; +}; struct gpu_info { VENDOR vendor; struct uarch* arch; char* name; + int64_t freq; + struct topology* topo; + struct memory* mem; + struct cache* cach; + int64_t peak_performance; }; - char* get_str_gpu_name(struct gpu_info* gpu); +char* get_str_freq(struct gpu_info* gpu); +char* get_str_memory_size(struct gpu_info* gpu); +char* get_str_memory_type(struct gpu_info* gpu); +char* get_str_l1(struct gpu_info* gpu); +char* get_str_l2(struct gpu_info* gpu); +char* get_str_peak_performance(struct gpu_info* gpu); #endif diff --git a/src/common/main.cpp b/src/common/main.cpp index a82b862..fd40e7f 100644 --- a/src/common/main.cpp +++ b/src/common/main.cpp @@ -5,6 +5,7 @@ #include "args.hpp" #include "global.hpp" #include "../cuda/cuda.hpp" +#include "../cuda/uarch.hpp" static const char* VERSION = "0.01"; @@ -52,7 +53,19 @@ int main(int argc, char* argv[]) { if(gpu == NULL) return EXIT_FAILURE; - printf("Name: %s\n", gpu->name); + printf("Name: %s\n", get_str_gpu_name(gpu)); + printf("Microarchitecture: %s\n", get_str_uarch(gpu)); + printf("Compute Capability: %s\n", get_str_cc(gpu)); + printf("Technology: %s\n", get_str_process(gpu)); + printf("Max Frequency: %s\n", get_str_freq(gpu)); + printf("SM: %s\n", get_str_sm(gpu)); + printf("Cores/MP: %s\n", get_str_cores_sm(gpu)); + printf("CUDA cores: %s\n", get_str_cuda_cores(gpu)); + printf("Memory size: %s\n", get_str_memory_size(gpu)); + printf("Memory type: %s\n", get_str_memory_type(gpu)); + printf("L1 size: %s\n", get_str_l1(gpu)); + printf("L2 size: %s\n", get_str_l2(gpu)); + printf("Peak performance: %s\n", get_str_peak_performance(gpu)); return EXIT_FAILURE; } diff --git a/src/cuda/cuda.cpp b/src/cuda/cuda.cpp index b6038c9..71f1b20 100644 --- a/src/cuda/cuda.cpp +++ b/src/cuda/cuda.cpp @@ -2,18 +2,62 @@ #include #include "cuda.hpp" +#include "uarch.hpp" #include "../common/global.hpp" +struct cache* get_cache_info(struct gpu_info* gpu) { + struct cache* cach = (struct cache*) emalloc(sizeof(struct cache)); + + return cach; +} + +struct topology* get_topology_info(struct gpu_info* gpu) { + struct topology* topo = (struct topology*) emalloc(sizeof(struct topology)); + + return topo; +} + +struct memory* get_memory_info(struct gpu_info* gpu) { + struct memory* mem = (struct memory*) emalloc(sizeof(struct memory)); + + return mem; +} + +int64_t get_peak_performance(struct gpu_info* gpu) { + return 1000; +} + struct gpu_info* get_gpu_info() { struct gpu_info* gpu = (struct gpu_info*) emalloc(sizeof(struct gpu_info)); + printf("Waiting for CUDA driver to start...\n"); int dev = 0; cudaSetDevice(dev); cudaDeviceProp deviceProp; cudaGetDeviceProperties(&deviceProp, dev); + gpu->vendor = GPU_VENDOR_NVIDIA; gpu->name = (char *) emalloc(sizeof(char) * (strlen(deviceProp.name) + 1)); strcpy(gpu->name, deviceProp.name); + gpu->freq = 10000; + + gpu->arch = get_uarch_from_cuda(gpu); + gpu->cach = get_cache_info(gpu); + gpu->topo = get_topology_info(gpu); + gpu->peak_performance = get_peak_performance(gpu); return gpu; } + +char* get_str_sm(struct gpu_info* gpu) { + return NULL; +} + +char* get_str_cores_sm(struct gpu_info* gpu) { + return NULL; +} + +char* get_str_cuda_cores(struct gpu_info* gpu) { + return NULL; +} + diff --git a/src/cuda/cuda.hpp b/src/cuda/cuda.hpp index ac4b32b..72ea92a 100644 --- a/src/cuda/cuda.hpp +++ b/src/cuda/cuda.hpp @@ -4,5 +4,8 @@ #include "../common/gpu.hpp" struct gpu_info* get_gpu_info(); +char* get_str_sm(struct gpu_info* gpu); +char* get_str_cores_sm(struct gpu_info* gpu); +char* get_str_cuda_cores(struct gpu_info* gpu); #endif diff --git a/src/cuda/uarch.cpp b/src/cuda/uarch.cpp index 2a16385..d5bb45a 100644 --- a/src/cuda/uarch.cpp +++ b/src/cuda/uarch.cpp @@ -28,6 +28,10 @@ char* get_str_uarch(struct gpu_info* gpu) { return NULL; } +char* get_str_cc(struct gpu_info* gpu) { + return NULL; +} + char* get_str_process(struct gpu_info* gpu) { return NULL; } diff --git a/src/cuda/uarch.hpp b/src/cuda/uarch.hpp index 19dfcd7..a81753d 100644 --- a/src/cuda/uarch.hpp +++ b/src/cuda/uarch.hpp @@ -5,6 +5,7 @@ struct uarch; struct uarch* get_uarch_from_cuda(struct gpu_info* gpu); char* get_str_uarch(struct gpu_info* gpu); +char* get_str_cc(struct gpu_info* gpu); char* get_str_process(struct gpu_info* gpu); void free_uarch_struct(struct uarch* arch);