[v0.10] Add --list-gpus option
This commit is contained in:
@@ -19,6 +19,7 @@
|
|||||||
struct args_struct {
|
struct args_struct {
|
||||||
bool help_flag;
|
bool help_flag;
|
||||||
bool version_flag;
|
bool version_flag;
|
||||||
|
bool list_gpus;
|
||||||
int gpu_idx;
|
int gpu_idx;
|
||||||
STYLE style;
|
STYLE style;
|
||||||
struct color** colors;
|
struct color** colors;
|
||||||
@@ -28,17 +29,19 @@ int errn = 0;
|
|||||||
static struct args_struct args;
|
static struct args_struct args;
|
||||||
|
|
||||||
const char args_chr[] = {
|
const char args_chr[] = {
|
||||||
/* [ARG_CHAR_COLOR] = */ 'c',
|
/* [ARG_COLOR] = */ 'c',
|
||||||
/* [ARG_CHAR_GPU] = */ 'g',
|
/* [ARG_GPU] = */ 'g',
|
||||||
/* [ARG_CHAR_HELP] = */ 'h',
|
/* [ARG_LIST] = */ 'l',
|
||||||
/* [ARG_CHAR_VERSION] = */ 'V',
|
/* [ARG_HELP] = */ 'h',
|
||||||
|
/* [ARG_VERSION] = */ 'V',
|
||||||
};
|
};
|
||||||
|
|
||||||
const char *args_str[] = {
|
const char *args_str[] = {
|
||||||
/* [ARG_CHAR_COLOR] = */ "color",
|
/* [ARG_COLOR] = */ "color",
|
||||||
/* [ARG_CHAR_GPU] = */ "gpu",
|
/* [ARG_GPU] = */ "gpu",
|
||||||
/* [ARG_CHAR_HELP] = */ "help",
|
/* [ARG_LIST] = */ "list-gpus",
|
||||||
/* [ARG_CHAR_VERSION] = */ "version",
|
/* [ARG_HELP] = */ "help",
|
||||||
|
/* [ARG_VERSION] = */ "version",
|
||||||
};
|
};
|
||||||
|
|
||||||
int getarg_int(char* str) {
|
int getarg_int(char* str) {
|
||||||
@@ -100,6 +103,10 @@ bool show_help() {
|
|||||||
return args.help_flag;
|
return args.help_flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool list_gpus() {
|
||||||
|
return args.list_gpus;
|
||||||
|
}
|
||||||
|
|
||||||
bool show_version() {
|
bool show_version() {
|
||||||
return args.version_flag;
|
return args.version_flag;
|
||||||
}
|
}
|
||||||
@@ -119,8 +126,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[ARG_GPU],
|
sprintf(str, "%c:%c:%c%c%c", c[ARG_GPU],
|
||||||
c[ARG_COLOR], c[ARG_HELP], c[ARG_VERSION]);
|
c[ARG_COLOR], c[ARG_HELP], c[ARG_LIST],
|
||||||
|
c[ARG_VERSION]);
|
||||||
|
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
@@ -185,12 +193,14 @@ 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.gpu_idx = 0;
|
args.gpu_idx = 0;
|
||||||
args.colors = NULL;
|
args.colors = NULL;
|
||||||
|
|
||||||
const struct option long_options[] = {
|
const struct option long_options[] = {
|
||||||
{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_HELP], no_argument, 0, args_chr[ARG_HELP] },
|
{args_str[ARG_HELP], no_argument, 0, args_chr[ARG_HELP] },
|
||||||
{args_str[ARG_VERSION], no_argument, 0, args_chr[ARG_VERSION] },
|
{args_str[ARG_VERSION], no_argument, 0, args_chr[ARG_VERSION] },
|
||||||
{0, 0, 0, 0}
|
{0, 0, 0, 0}
|
||||||
@@ -199,7 +209,7 @@ bool parse_args(int argc, char* argv[]) {
|
|||||||
char* short_options = build_short_options();
|
char* short_options = build_short_options();
|
||||||
opt = getopt_long(argc, argv, short_options, long_options, &option_index);
|
opt = getopt_long(argc, argv, short_options, long_options, &option_index);
|
||||||
|
|
||||||
while (!args.help_flag && !args.version_flag && opt != -1) {
|
while (!args.help_flag && !args.version_flag && !args.list_gpus && opt != -1) {
|
||||||
if(opt == args_chr[ARG_COLOR]) {
|
if(opt == args_chr[ARG_COLOR]) {
|
||||||
args.colors = (struct color **) emalloc(sizeof(struct color *) * NUM_COLORS);
|
args.colors = (struct color **) emalloc(sizeof(struct color *) * NUM_COLORS);
|
||||||
if(!parse_color(optarg, &args.colors)) {
|
if(!parse_color(optarg, &args.colors)) {
|
||||||
@@ -215,8 +225,11 @@ bool parse_args(int argc, char* argv[]) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if(opt == args_chr[ARG_LIST]) {
|
||||||
|
args.list_gpus = true;
|
||||||
|
}
|
||||||
else if(opt == args_chr[ARG_HELP]) {
|
else if(opt == args_chr[ARG_HELP]) {
|
||||||
args.help_flag = true;
|
args.help_flag = true;
|
||||||
}
|
}
|
||||||
else if(opt == args_chr[ARG_VERSION]) {
|
else if(opt == args_chr[ARG_VERSION]) {
|
||||||
args.version_flag = true;
|
args.version_flag = true;
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ enum {
|
|||||||
enum {
|
enum {
|
||||||
ARG_COLOR,
|
ARG_COLOR,
|
||||||
ARG_GPU,
|
ARG_GPU,
|
||||||
|
ARG_LIST,
|
||||||
ARG_HELP,
|
ARG_HELP,
|
||||||
ARG_VERSION
|
ARG_VERSION
|
||||||
};
|
};
|
||||||
@@ -33,6 +34,7 @@ extern const char *args_str[];
|
|||||||
int max_arg_str_length();
|
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 show_version();
|
bool show_version();
|
||||||
void free_colors_struct(struct color** cs);
|
void free_colors_struct(struct color** cs);
|
||||||
int get_gpu_idx();
|
int get_gpu_idx();
|
||||||
|
|||||||
@@ -18,10 +18,11 @@ void print_help(char *argv[]) {
|
|||||||
printf("Simple yet fancy GPU architecture fetching tool\n\n");
|
printf("Simple yet fancy GPU architecture fetching tool\n\n");
|
||||||
|
|
||||||
printf("Options: \n");
|
printf("Options: \n");
|
||||||
printf(" -%c, --%s %*s Sets 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 Selects the GPU to use (default: 0)\n", c[ARG_GPU], t[ARG_GPU], (int) (max_len-strlen(t[ARG_GPU])), "");
|
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 Prints this help and exit\n", c[ARG_HELP], t[ARG_HELP], (int) (max_len-strlen(t[ARG_HELP])), "");
|
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 Prints gpufetch version and exit\n", c[ARG_VERSION], t[ARG_VERSION], (int) (max_len-strlen(t[ARG_VERSION])), "");
|
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("\nCOLORS: \n");
|
printf("\nCOLORS: \n");
|
||||||
printf(" Color scheme can be set using a predefined color scheme or a custom one:\n");
|
printf(" Color scheme can be set using a predefined color scheme or a custom one:\n");
|
||||||
@@ -64,6 +65,10 @@ int main(int argc, char* argv[]) {
|
|||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(list_gpus()) {
|
||||||
|
return print_gpus_list();
|
||||||
|
}
|
||||||
|
|
||||||
set_log_level(true);
|
set_log_level(true);
|
||||||
|
|
||||||
printWarn("gpufetch is in beta. The provided information may be incomplete or wrong.\n\
|
printWarn("gpufetch is in beta. The provided information may be incomplete or wrong.\n\
|
||||||
|
|||||||
@@ -6,6 +6,42 @@
|
|||||||
#include "uarch.hpp"
|
#include "uarch.hpp"
|
||||||
#include "../common/global.hpp"
|
#include "../common/global.hpp"
|
||||||
|
|
||||||
|
int print_gpus_list() {
|
||||||
|
cudaError_t err = cudaSuccess;
|
||||||
|
int num_gpus = -1;
|
||||||
|
|
||||||
|
if ((err = cudaGetDeviceCount(&num_gpus)) != cudaSuccess) {
|
||||||
|
printErr("%s: %s", cudaGetErrorName(err), cudaGetErrorString(err));
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
printf("CUDA GPUs available: %d\n", num_gpus);
|
||||||
|
|
||||||
|
if(num_gpus > 0) {
|
||||||
|
cudaDeviceProp deviceProp;
|
||||||
|
int max_len = 0;
|
||||||
|
|
||||||
|
for(int idx=0; idx < num_gpus; idx++) {
|
||||||
|
if ((err = cudaGetDeviceProperties(&deviceProp, idx)) != cudaSuccess) {
|
||||||
|
printErr("%s: %s", cudaGetErrorName(err), cudaGetErrorString(err));
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
max_len = max(max_len, (int) strlen(deviceProp.name));
|
||||||
|
}
|
||||||
|
|
||||||
|
for(int i=0; i < max_len + 32; i++) putchar('-');
|
||||||
|
putchar('\n');
|
||||||
|
for(int idx=0; idx < num_gpus; idx++) {
|
||||||
|
if ((err = cudaGetDeviceProperties(&deviceProp, idx)) != cudaSuccess) {
|
||||||
|
printErr("%s: %s", cudaGetErrorName(err), cudaGetErrorString(err));
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
printf("GPU %d: %s (Compute Capability %d.%d)\n", idx, deviceProp.name, deviceProp.major, deviceProp.minor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
struct cache* get_cache_info(cudaDeviceProp prop) {
|
struct cache* get_cache_info(cudaDeviceProp prop) {
|
||||||
struct cache* cach = (struct cache*) emalloc(sizeof(struct cache));
|
struct cache* cach = (struct cache*) emalloc(sizeof(struct cache));
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
#include "../common/gpu.hpp"
|
#include "../common/gpu.hpp"
|
||||||
|
|
||||||
struct gpu_info* get_gpu_info(int gpu_idx);
|
struct gpu_info* get_gpu_info(int gpu_idx);
|
||||||
|
int print_gpus_list();
|
||||||
char* get_str_sm(struct gpu_info* gpu);
|
char* get_str_sm(struct gpu_info* gpu);
|
||||||
char* get_str_cores_sm(struct gpu_info* gpu);
|
char* get_str_cores_sm(struct gpu_info* gpu);
|
||||||
char* get_str_cuda_cores(struct gpu_info* gpu);
|
char* get_str_cuda_cores(struct gpu_info* gpu);
|
||||||
|
|||||||
Reference in New Issue
Block a user