#include #include #include #include #include #include #include "icx3.h" #include "evga-card.h" #define MAX_GPUS 16 static const char helpstring[] = "Available options:\n" "--gpu N : Control only GPU N instead of all supported cards\n" "--fan SPEED : Set all fans at once to SPEED (see below)\n" "--fanN SPEED : Set fan N (0-3) to SPEED\n" " SPEED may be one of the following:\n" " 'auto' to return the fan to its default control mode\n" " N to set the fan to that manual % speed\n" " [+/-]N to set that fan to an RPM offset from the GPU-controlled speed\n" "--reset : Reset all fans to their default mode\n" "--sensors : Print sensor readings even if setting a fan speed \n" "--compact : Print sensor reading in a compact one-line per card format\n"; void print_gpu_info(int gpu_num, struct card_info gpus[], int compact); int main (int argc, char **argv) { struct card_info gpus[MAX_GPUS]; int gpu_count; int print_info = 0; int compact = 0; int gpu_num = -1; /* Card to control */ char *fan_speed[ICX3_MAX_FANS] = {NULL}; /* Input parsing */ for (int i = 1; i < argc; i++){ if (strcmp(argv[i], "--gpu") == 0) { i++; if (i < argc) { gpu_num = atoi(argv[i]); } else { printf(helpstring); return -1; } } else if (strcmp(argv[i], "--fan") == 0) { i++; if (i < argc) { for (int j = 0; j < ICX3_MAX_FANS; j++) fan_speed[j] = argv[i]; } else { printf(helpstring); return -1; } } else if (strncmp(argv[i], "--fan", 5) == 0) { int fan_num = atoi(argv[i]+5); i++; if (i < argc) { if (fan_num <= ICX3_MAX_FANS) fan_speed[fan_num] = argv[i]; } else { printf(helpstring); return -1; } } else if (strcmp(argv[i], "--reset") == 0) { for (int j = 0; j < ICX3_MAX_FANS; j++) fan_speed[j] = "auto"; } else if (strcmp(argv[i], "--sensors") == 0) { print_info = 1; } else if (strcmp(argv[i], "--compact") == 0) { compact = 1; } else { printf(helpstring); return 0; } } if (print_info == 0) { /* Check for no fan commands given, so display info by default */ print_info = 1; for (int i = 0; i < ICX3_MAX_FANS; i++) { if (fan_speed[i] != NULL) print_info = 0; } } gpu_count = find_evga_gpu_i2cs(gpus, MAX_GPUS); if (gpu_count == -1) { printf("Error scanning I2C devices\n"); return -1; } else if (gpu_count == 0) { printf("No supported GPUs found.\nAre you root or do you have udev access to i2c devices?\nDo you need to run `modprobe i2c-dev`?\n"); return -1; } if (gpu_num > gpu_count - 1) { printf("Invalid GPU number specified (%d, max %d)\n", gpu_num, gpu_count - 1); return -1; } /* execute fan commands */ if (gpu_num == -1) { for (int i = 0; i < gpu_count; i++){ for (int j = 0; j < ICX3_MAX_FANS; j++) { if (fan_speed[j] != NULL) set_fan(j, fan_speed[j], gpus[i].i2c_dev_path); /* printf("gpu %d fan %d : %s\n", i, j, fan_speed[j]); */ } } } else if (gpu_num <= gpu_count - 1) { for (int j = 0; j < ICX3_MAX_FANS; j++) { if (fan_speed[j] != NULL) set_fan(gpu_num, fan_speed[j], gpus[gpu_num].i2c_dev_path); /* printf("gpu %d fan %d : %s\n", gpu_num, j, fan_speed[j]);*/ } } /* print sensor info */ if (print_info) { if (gpu_num == -1) { for (int i = 0; i < gpu_count; i++){ print_gpu_info(i, gpus, compact); } } else if (gpu_num <= gpu_count - 1) { print_gpu_info(gpu_num, gpus, compact); } } } void print_gpu_info(int gpu_num, struct card_info gpus[], int compact) { if (compact) { printf("#%d ", gpu_num); print_icx3_fans_oneline(gpus[gpu_num].i2c_dev_path); print_icx3_temps_oneline(gpus[gpu_num].i2c_dev_path); printf("\n"); } else { printf("#%d: %s (%s) @ %s\n", gpu_num, gpus[gpu_num].card_name, gpus[gpu_num].i2c_dev_path, gpus[gpu_num].pci_id); print_icx3_fans(gpus[gpu_num].i2c_dev_path); print_icx3_temps(gpus[gpu_num].i2c_dev_path); printf("\n"); } }