5 Commits
v0.23 ... v0.24

10 changed files with 133 additions and 26 deletions

View File

@@ -68,8 +68,10 @@ if(ENABLE_CUDA_BACKEND)
# https://en.wikipedia.org/w/index.php?title=CUDA&section=5#GPUs_supported # https://en.wikipedia.org/w/index.php?title=CUDA&section=5#GPUs_supported
# https://raw.githubusercontent.com/PointCloudLibrary/pcl/master/cmake/pcl_find_cuda.cmake # https://raw.githubusercontent.com/PointCloudLibrary/pcl/master/cmake/pcl_find_cuda.cmake
if(${CMAKE_CUDA_COMPILER_VERSION} VERSION_GREATER_EQUAL "11.0") if(${CMAKE_CUDA_COMPILER_VERSION} VERSION_GREATER_EQUAL "11.1")
set(CMAKE_CUDA_ARCHITECTURES 35 37 50 52 53 60 61 62 70 72 75 80 86) set(CMAKE_CUDA_ARCHITECTURES 35 37 50 52 53 60 61 62 70 72 75 80 86)
elseif(${CMAKE_CUDA_COMPILER_VERSION} EQUAL "11.0")
set(CMAKE_CUDA_ARCHITECTURES 30 32 35 37 50 52 53 60 61 62 70 72 75 80)
elseif(${CMAKE_CUDA_COMPILER_VERSION} VERSION_GREATER_EQUAL "10.0") elseif(${CMAKE_CUDA_COMPILER_VERSION} VERSION_GREATER_EQUAL "10.0")
set(CMAKE_CUDA_ARCHITECTURES 30 32 35 37 50 52 53 60 61 62 70 72 75) set(CMAKE_CUDA_ARCHITECTURES 30 32 35 37 50 52 53 60 61 62 70 72 75)
elseif(${CMAKE_CUDA_COMPILER_VERSION} VERSION_GREATER_EQUAL "9.0") elseif(${CMAKE_CUDA_COMPILER_VERSION} VERSION_GREATER_EQUAL "9.0")
@@ -84,7 +86,7 @@ if(ENABLE_CUDA_BACKEND)
add_dependencies(cuda_backend pciutils) add_dependencies(cuda_backend pciutils)
endif() endif()
target_include_directories(cuda_backend PUBLIC ${CMAKE_CUDA_COMPILER_TOOLKIT_ROOT}/samples/common/inc ${CMAKE_CUDA_COMPILER_TOOLKIT_ROOT}/targets/x86_64-linux/include) target_include_directories(cuda_backend PUBLIC ${CMAKE_CUDA_COMPILER_TOOLKIT_ROOT}/targets/x86_64-linux/include)
target_link_libraries(cuda_backend PRIVATE cudart) target_link_libraries(cuda_backend PRIVATE cudart)
target_link_libraries(gpufetch cuda_backend) target_link_libraries(gpufetch cuda_backend)

View File

@@ -20,7 +20,7 @@
<p align="center"> </p> <p align="center"> </p>
<p align="center"> <p align="center">
gpufetch is a command-line tool written in C that displays the GPU information in a clean and beautiful way gpufetch is a command-line tool written in C++ that displays the GPU information in a clean and beautiful way
</p> </p>
<p align="center"> <p align="center">

View File

@@ -26,6 +26,8 @@ struct args_struct {
bool verbose_flag; bool verbose_flag;
bool version_flag; bool version_flag;
bool list_gpus; bool list_gpus;
bool logo_long;
bool logo_short;
int gpu_idx; int gpu_idx;
STYLE style; STYLE style;
struct color** colors; struct color** colors;
@@ -38,6 +40,8 @@ const char args_chr[] = {
/* [ARG_COLOR] = */ 'c', /* [ARG_COLOR] = */ 'c',
/* [ARG_GPU] = */ 'g', /* [ARG_GPU] = */ 'g',
/* [ARG_LIST] = */ 'l', /* [ARG_LIST] = */ 'l',
/* [ARG_LOGO_LONG] = */ 1,
/* [ARG_LOGO_SHORT] = */ 2,
/* [ARG_HELP] = */ 'h', /* [ARG_HELP] = */ 'h',
/* [ARG_VERBOSE] = */ 'v', /* [ARG_VERBOSE] = */ 'v',
/* [ARG_VERSION] = */ 'V', /* [ARG_VERSION] = */ 'V',
@@ -47,6 +51,8 @@ const char *args_str[] = {
/* [ARG_COLOR] = */ "color", /* [ARG_COLOR] = */ "color",
/* [ARG_GPU] = */ "gpu", /* [ARG_GPU] = */ "gpu",
/* [ARG_LIST] = */ "list-gpus", /* [ARG_LIST] = */ "list-gpus",
/* [ARG_LOGO_LONG] = */ "logo-long",
/* [ARG_LOGO_SHORT] = */ "logo-short",
/* [ARG_HELP] = */ "help", /* [ARG_HELP] = */ "help",
/* [ARG_VERBOSE] = */ "verbose", /* [ARG_VERBOSE] = */ "verbose",
/* [ARG_VERSION] = */ "version", /* [ARG_VERSION] = */ "version",
@@ -111,6 +117,14 @@ bool list_gpus() {
return args.list_gpus; return args.list_gpus;
} }
bool show_logo_long() {
return args.logo_long;
}
bool show_logo_short() {
return args.logo_short;
}
bool show_version() { bool show_version() {
return args.version_flag; return args.version_flag;
} }
@@ -134,8 +148,9 @@ char* build_short_options() {
char* str = (char *) emalloc(sizeof(char) * (len*2 + 1)); char* str = (char *) emalloc(sizeof(char) * (len*2 + 1));
memset(str, 0, sizeof(char) * (len*2 + 1)); memset(str, 0, sizeof(char) * (len*2 + 1));
sprintf(str, "%c:%c:%c%c%c%c", c[ARG_GPU], sprintf(str, "%c:%c:%c%c%c%c%c%c", c[ARG_GPU],
c[ARG_COLOR], c[ARG_HELP], c[ARG_LIST], c[ARG_COLOR], c[ARG_HELP], c[ARG_LIST],
c[ARG_LOGO_SHORT], c[ARG_LOGO_LONG],
c[ARG_VERBOSE], c[ARG_VERSION]); c[ARG_VERBOSE], c[ARG_VERSION]);
return str; return str;
@@ -203,6 +218,8 @@ bool parse_args(int argc, char* argv[]) {
args.version_flag = false; args.version_flag = false;
args.help_flag = false; args.help_flag = false;
args.list_gpus = false; args.list_gpus = false;
args.logo_long = false;
args.logo_short = false;
args.gpu_idx = 0; args.gpu_idx = 0;
args.colors = NULL; args.colors = NULL;
@@ -210,6 +227,8 @@ bool parse_args(int argc, char* argv[]) {
{args_str[ARG_COLOR], required_argument, 0, args_chr[ARG_COLOR] }, {args_str[ARG_COLOR], required_argument, 0, args_chr[ARG_COLOR] },
{args_str[ARG_GPU], required_argument, 0, args_chr[ARG_GPU] }, {args_str[ARG_GPU], required_argument, 0, args_chr[ARG_GPU] },
{args_str[ARG_LIST], no_argument, 0, args_chr[ARG_LIST] }, {args_str[ARG_LIST], no_argument, 0, args_chr[ARG_LIST] },
{args_str[ARG_LOGO_SHORT], no_argument, 0, args_chr[ARG_LOGO_SHORT] },
{args_str[ARG_LOGO_LONG], no_argument, 0, args_chr[ARG_LOGO_LONG] },
{args_str[ARG_HELP], no_argument, 0, args_chr[ARG_HELP] }, {args_str[ARG_HELP], no_argument, 0, args_chr[ARG_HELP] },
{args_str[ARG_VERBOSE], no_argument, 0, args_chr[ARG_VERBOSE] }, {args_str[ARG_VERBOSE], no_argument, 0, args_chr[ARG_VERBOSE] },
{args_str[ARG_VERSION], no_argument, 0, args_chr[ARG_VERSION] }, {args_str[ARG_VERSION], no_argument, 0, args_chr[ARG_VERSION] },
@@ -237,6 +256,12 @@ bool parse_args(int argc, char* argv[]) {
else if(opt == args_chr[ARG_LIST]) { else if(opt == args_chr[ARG_LIST]) {
args.list_gpus = true; args.list_gpus = true;
} }
else if(opt == args_chr[ARG_LOGO_SHORT]) {
args.logo_short = true;
}
else if(opt == args_chr[ARG_LOGO_LONG]) {
args.logo_long = true;
}
else if(opt == args_chr[ARG_HELP]) { else if(opt == args_chr[ARG_HELP]) {
args.help_flag = true; args.help_flag = true;
} }
@@ -260,6 +285,12 @@ bool parse_args(int argc, char* argv[]) {
args.help_flag = true; args.help_flag = true;
} }
if(args.logo_short && args.logo_long) {
printWarn("%s and %s cannot be specified together", args_str[ARG_LOGO_SHORT], args_str[ARG_LOGO_LONG]);
args.logo_short = false;
args.logo_long = false;
}
if((args.help_flag + args.version_flag) > 1) { if((args.help_flag + args.version_flag) > 1) {
printWarn("You should specify just one option"); printWarn("You should specify just one option");
args.help_flag = true; args.help_flag = true;

View File

@@ -20,6 +20,8 @@ enum {
ARG_COLOR, ARG_COLOR,
ARG_GPU, ARG_GPU,
ARG_LIST, ARG_LIST,
ARG_LOGO_LONG,
ARG_LOGO_SHORT,
ARG_HELP, ARG_HELP,
ARG_VERBOSE, ARG_VERBOSE,
ARG_VERSION ARG_VERSION
@@ -34,6 +36,8 @@ int max_arg_str_length();
bool parse_args(int argc, char* argv[]); bool parse_args(int argc, char* argv[]);
bool show_help(); bool show_help();
bool list_gpus(); bool list_gpus();
bool show_logo_long();
bool show_logo_short();
bool show_version(); bool show_version();
bool verbose_enabled(); bool verbose_enabled();
void free_colors_struct(struct color** cs); void free_colors_struct(struct color** cs);

View File

@@ -8,7 +8,7 @@
#include "../cuda/cuda.hpp" #include "../cuda/cuda.hpp"
#include "../cuda/uarch.hpp" #include "../cuda/uarch.hpp"
static const char* VERSION = "0.23"; static const char* VERSION = "0.24";
void print_help(char *argv[]) { void print_help(char *argv[]) {
const char **t = args_str; const char **t = args_str;
@@ -22,6 +22,8 @@ void print_help(char *argv[]) {
printf(" -%c, --%s %*s Set the color scheme (by default, gpufetch uses the system color scheme) See COLORS section for a more detailed explanation\n", c[ARG_COLOR], t[ARG_COLOR], (int) (max_len-strlen(t[ARG_COLOR])), ""); printf(" -%c, --%s %*s Set the color scheme (by default, gpufetch uses the system color scheme) See COLORS section for a more detailed explanation\n", c[ARG_COLOR], t[ARG_COLOR], (int) (max_len-strlen(t[ARG_COLOR])), "");
printf(" -%c, --%s %*s List the available GPUs in the system\n", c[ARG_LIST], t[ARG_LIST], (int) (max_len-strlen(t[ARG_LIST])), ""); printf(" -%c, --%s %*s List the available GPUs in the system\n", c[ARG_LIST], t[ARG_LIST], (int) (max_len-strlen(t[ARG_LIST])), "");
printf(" -%c, --%s %*s Select the GPU to use (default: 0)\n", c[ARG_GPU], t[ARG_GPU], (int) (max_len-strlen(t[ARG_GPU])), ""); printf(" -%c, --%s %*s Select the GPU to use (default: 0)\n", c[ARG_GPU], t[ARG_GPU], (int) (max_len-strlen(t[ARG_GPU])), "");
printf(" --%s %*s Show the short version of the logo\n", t[ARG_LOGO_SHORT], (int) (max_len-strlen(t[ARG_LOGO_SHORT])), "");
printf(" --%s %*s Show the long version of the logo\n", t[ARG_LOGO_LONG], (int) (max_len-strlen(t[ARG_LOGO_LONG])), "");
printf(" -%c, --%s %*s Enable verbose output\n", c[ARG_VERBOSE], t[ARG_VERBOSE], (int) (max_len-strlen(t[ARG_VERBOSE])), ""); printf(" -%c, --%s %*s Enable verbose output\n", c[ARG_VERBOSE], t[ARG_VERBOSE], (int) (max_len-strlen(t[ARG_VERBOSE])), "");
printf(" -%c, --%s %*s Print this help and exit\n", c[ARG_HELP], t[ARG_HELP], (int) (max_len-strlen(t[ARG_HELP])), ""); printf(" -%c, --%s %*s Print this help and exit\n", c[ARG_HELP], t[ARG_HELP], (int) (max_len-strlen(t[ARG_HELP])), "");
printf(" -%c, --%s %*s Print gpufetch version and exit\n", c[ARG_VERSION], t[ARG_VERSION], (int) (max_len-strlen(t[ARG_VERSION])), ""); printf(" -%c, --%s %*s Print gpufetch version and exit\n", c[ARG_VERSION], t[ARG_VERSION], (int) (max_len-strlen(t[ARG_VERSION])), "");

View File

@@ -219,6 +219,8 @@ void replace_bgbyfg_color(struct ascii_logo* logo) {
} }
struct ascii_logo* choose_ascii_art_aux(struct ascii_logo* logo_long, struct ascii_logo* logo_short, struct terminal* term, int lf) { struct ascii_logo* choose_ascii_art_aux(struct ascii_logo* logo_long, struct ascii_logo* logo_short, struct terminal* term, int lf) {
if(show_logo_long()) return logo_long;
if(show_logo_short()) return logo_short;
if(ascii_fits_screen(term->w, *logo_long, lf)) { if(ascii_fits_screen(term->w, *logo_long, lf)) {
return logo_long; return logo_long;
} }

View File

@@ -1,8 +1,11 @@
#include <helper_cuda.h>
#include <cuda_runtime.h> #include <cuda_runtime.h>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include "cuda.hpp" #include "cuda.hpp"
#include "uarch.hpp" #include "uarch.hpp"
#include "gpufetch_helper_cuda.hpp"
#include "../common/pci.hpp" #include "../common/pci.hpp"
#include "../common/global.hpp" #include "../common/global.hpp"
#include "../common/uarch.hpp" #include "../common/uarch.hpp"

View File

@@ -0,0 +1,60 @@
#ifndef __GPUFETCH_HELPER_CUDA__
#define __GPUFETCH_HELPER_CUDA__
// gpufetch self contained helper_cuda.h
//
// Avoids relying on helper_cuda.h, which is
// often very hard to include properly, causing
// compilation issues.
//
// URL: https://github.com/NVIDIA/cuda-samples
// Commit: 2e41896
inline int _ConvertSMVer2Cores(int major, int minor) {
// Defines for GPU Architecture types (using the SM version to determine
// the # of cores per SM
typedef struct {
int SM; // 0xMm (hexidecimal notation), M = SM Major version,
// and m = SM minor version
int Cores;
} sSMtoCores;
sSMtoCores nGpuArchCoresPerSM[] = {
{0x30, 192},
{0x32, 192},
{0x35, 192},
{0x37, 192},
{0x50, 128},
{0x52, 128},
{0x53, 128},
{0x60, 64},
{0x61, 128},
{0x62, 128},
{0x70, 64},
{0x72, 64},
{0x75, 64},
{0x80, 64},
{0x86, 128},
{0x87, 128},
{-1, -1}};
int index = 0;
while (nGpuArchCoresPerSM[index].SM != -1) {
if (nGpuArchCoresPerSM[index].SM == ((major << 4) + minor)) {
return nGpuArchCoresPerSM[index].Cores;
}
index++;
}
// If we don't find the values, we default use the previous one
// to run properly
printf(
"MapSMtoCores for SM %d.%d is undefined."
" Default to use %d Cores/SM\n",
major, minor, nGpuArchCoresPerSM[index - 1].Cores);
return nGpuArchCoresPerSM[index - 1].Cores;
}
#endif

View File

@@ -1,7 +1,9 @@
#include <cuda_runtime.h> #include <cuda_runtime.h>
#include <helper_cuda.h> #include <cstdlib>
#include <cstdint> #include <cstdint>
#include <cstddef> #include <cstddef>
#include <cstdio>
#include <cstring>
#include "../common/uarch.hpp" #include "../common/uarch.hpp"
#include "../common/global.hpp" #include "../common/global.hpp"
@@ -329,6 +331,7 @@ char* get_str_chip(struct uarch* arch) {
return arch->chip_str; return arch->chip_str;
} }
// TODO: What about _ConvertSMVer2ArchName?
const char* get_str_uarch_cuda(struct uarch* arch) { const char* get_str_uarch_cuda(struct uarch* arch) {
return uarch_str[arch->uarch]; return uarch_str[arch->uarch];
} }

View File

@@ -50,7 +50,7 @@ static const char *uarch_str[] = {
/*[ARCH_GEN9] = */ "Gen9", /*[ARCH_GEN9] = */ "Gen9",
/*[ARCH_GEN9_5] = */ "Gen9.5", /*[ARCH_GEN9_5] = */ "Gen9.5",
/*[ARCH_GEN11] = */ "Gen11", /*[ARCH_GEN11] = */ "Gen11",
/*[ARCH_GEN12_RKL] = */ "Gen12" /*[ARCH_GEN12_RKL] = */ "Gen12",
/*[ARCH_GEN12_TGL] = */ "Gen12" /*[ARCH_GEN12_TGL] = */ "Gen12"
}; };