GetSysInfo.cpp 2.8 KB
Newer Older
Y
yangwei.yao 已提交
1 2 3 4 5

#include "utils/Log.h"
#include "LicenseLibrary.h"
#include "utils/Error.h"

J
jinhai 已提交
6
#include <iostream>
J
jinhai 已提交
7 8 9
#include <getopt.h>
#include <memory.h>
// Not provide path: current work path will be used and system.info.
Y
yangwei.yao 已提交
10
using namespace zilliz::vecwise;
J
jinhai 已提交
11 12 13 14 15 16

void
print_usage(const std::string &app_name) {
    printf("\n Usage: %s [OPTIONS]\n\n", app_name.c_str());
    printf("  Options:\n");
    printf("   -h --help               Print this help\n");
Y
yangwei.yao 已提交
17
    printf("   -s --sysinfo filename   Generate system info file as given name\n");
J
jinhai 已提交
18 19
    printf("\n");
}
J
jinhai 已提交
20

Y
yangwei.yao 已提交
21
int main(int argc, char *argv[]) {
J
jinhai 已提交
22
    std::string app_name = argv[0];
Y
yangwei.yao 已提交
23
    if (argc != 1 && argc != 3) {
J
jinhai 已提交
24 25 26 27
        print_usage(app_name);
        return EXIT_FAILURE;
    }

Y
yangwei.yao 已提交
28
    static struct option long_options[] = {{"system_info", required_argument, 0, 's'},
J
jinhai 已提交
29 30 31 32 33
                                           {"help", no_argument, 0, 'h'},
                                           {NULL, 0, 0, 0}};
    int value = 0;
    int option_index = 0;
    std::string system_info_filename = "./system.info";
Y
yangwei.yao 已提交
34
    while ((value = getopt_long(argc, argv, "s:h", long_options, &option_index)) != -1) {
J
jinhai 已提交
35
        switch (value) {
Y
yangwei.yao 已提交
36
            case 's': {
J
jinhai 已提交
37 38 39 40 41 42
                char *system_info_filename_ptr = strdup(optarg);
                system_info_filename = system_info_filename_ptr;
                free(system_info_filename_ptr);
//                printf("Generate system info file: %s\n", system_info_filename.c_str());
                break;
            }
Y
yangwei.yao 已提交
43
            case 'h':print_usage(app_name);
J
jinhai 已提交
44
                return EXIT_SUCCESS;
Y
yangwei.yao 已提交
45
            case '?':print_usage(app_name);
J
jinhai 已提交
46
                return EXIT_FAILURE;
Y
yangwei.yao 已提交
47
            default:print_usage(app_name);
J
jinhai 已提交
48 49 50 51
                break;
        }
    }

Y
yangwei.yao 已提交
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
    int device_count = 0;
    server::ServerError err = server::LicenseLibrary::GetDeviceCount(device_count);
    if (err != server::SERVER_SUCCESS) return -1;

    // 2. Get All GPU UUID
    std::vector<std::string> uuid_array;
    err = server::LicenseLibrary::GetUUID(device_count, uuid_array);
    if (err != server::SERVER_SUCCESS) return -1;

    // 3. Get UUID SHA256
    std::vector<std::string> uuid_sha256_array;
    err = server::LicenseLibrary::GetUUIDSHA256(device_count, uuid_array, uuid_sha256_array);
    if (err != server::SERVER_SUCCESS) return -1;

    // 4. Generate GPU ID map with GPU UUID
    std::map<int, std::string> uuid_encrption_map;
    for (int i = 0; i < device_count; ++i) {
        uuid_encrption_map[i] = uuid_sha256_array[i];
    }


    // 6. Generate GPU_info File
    err = server::LicenseLibrary::GPUinfoFileSerialization(system_info_filename,
                                                           device_count,
                                                           uuid_encrption_map);
    if (err != server::SERVER_SUCCESS) return -1;

    printf("Generate GPU_info File Success\n");


J
jinhai 已提交
82 83
    return 0;
}