Skip to content

Commit ebed710

Browse files
committed
Add device brand to the device informations and requirements
1 parent a141a7a commit ebed710

File tree

9 files changed

+100
-5
lines changed

9 files changed

+100
-5
lines changed

src/cli/configure.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ static error_t configure_parser(int, char *, struct argp_state *);
1313
static int check_cuda_version(const struct dsl_data *, enum dsl_comparator, const char *);
1414
static int check_driver_version(const struct dsl_data *, enum dsl_comparator, const char *);
1515
static int check_device_arch(const struct dsl_data *, enum dsl_comparator, const char *);
16+
static int check_device_brand(const struct dsl_data *, enum dsl_comparator, const char *);
1617

1718
const struct argp configure_usage = {
1819
(const struct argp_option[]){
@@ -46,6 +47,7 @@ static const struct dsl_rule rules[] = {
4647
{"cuda", &check_cuda_version},
4748
{"driver", &check_driver_version},
4849
{"arch", &check_device_arch},
50+
{"brand", &check_device_brand},
4951
};
5052

5153
static error_t
@@ -159,6 +161,15 @@ check_device_arch(const struct dsl_data *data, enum dsl_comparator cmp, const ch
159161
return (dsl_compare_version(data->dev->arch, cmp, arch));
160162
}
161163

164+
static int
165+
check_device_brand(const struct dsl_data *data, enum dsl_comparator cmp, const char *brand)
166+
{
167+
/* XXX No device is visible, assume the brand is ok. */
168+
if (data->dev == NULL)
169+
return (true);
170+
return (dsl_compare_string(data->dev->brand, cmp, brand));
171+
}
172+
162173
int
163174
configure_command(const struct context *ctx)
164175
{

src/cli/dsl.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,16 @@ dsl_compare_version(const char *v1, enum dsl_comparator cmp, const char *v2)
7676
return (-1);
7777
}
7878

79+
int
80+
dsl_compare_string(const char *s1, enum dsl_comparator cmp, const char *s2)
81+
{
82+
if (cmp == EQUAL)
83+
return (str_case_equal(s1, s2));
84+
else if (cmp == NOT_EQUAL)
85+
return (!str_case_equal(s1, s2));
86+
return (-1);
87+
}
88+
7989
static int
8090
evaluate_rule(char *buf, char *expr, void *ctx, const struct dsl_rule rules[], size_t size)
8191
{

src/cli/dsl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ struct dsl_rule {
2929
};
3030

3131
int dsl_compare_version(const char *, enum dsl_comparator, const char *);
32+
int dsl_compare_string(const char *, enum dsl_comparator, const char *);
3233
int dsl_evaluate(struct error *, const char *, void *, const struct dsl_rule [], size_t);
3334

3435
#endif /* HEADER_DSL_H */

src/cli/info.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,16 +95,17 @@ info_command(const struct context *ctx)
9595

9696
if (ctx->csv_output) {
9797
printf("NVRM version,CUDA version\n%s,%s\n", drv->nvrm_version, drv->cuda_version);
98-
printf("\nDevice Index,Device Minor,Model,GPU UUID,Bus Location,Architecture\n");
98+
printf("\nDevice Index,Device Minor,Model,Brand,GPU UUID,Bus Location,Architecture\n");
9999
for (size_t i = 0; i < dev->ngpus; ++i)
100-
printf("%zu,%u,%s,%s,%s,%s\n", i, minor(dev->gpus[i].node.id), dev->gpus[i].model, dev->gpus[i].uuid, dev->gpus[i].busid, dev->gpus[i].arch);
100+
printf("%zu,%u,%s,%s,%s,%s,%s\n", i, minor(dev->gpus[i].node.id), dev->gpus[i].model, dev->gpus[i].brand,
101+
dev->gpus[i].uuid, dev->gpus[i].busid, dev->gpus[i].arch);
101102

102103
} else {
103104
printf("%-15s %s\n%-15s %s\n", "NVRM version:", drv->nvrm_version, "CUDA version:", drv->cuda_version);
104105
for (size_t i = 0; i < dev->ngpus; ++i)
105-
printf("\n%-15s %zu\n%-15s %u\n%-15s %s\n%-15s %s\n%-15s %s\n%-15s %s\n",
106-
"Device Index:", i, "Device Minor:", minor(dev->gpus[i].node.id), "Model:", dev->gpus[i].model, "GPU UUID:", dev->gpus[i].uuid,
107-
"Bus Location:", dev->gpus[i].busid, "Architecture:", dev->gpus[i].arch);
106+
printf("\n%-15s %zu\n%-15s %u\n%-15s %s\n%-15s %s\n%-15s %s\n%-15s %s\n%-15s %s\n",
107+
"Device Index:", i, "Device Minor:", minor(dev->gpus[i].node.id), "Model:", dev->gpus[i].model, "Brand:",
108+
dev->gpus[i].brand, "GPU UUID:", dev->gpus[i].uuid, "Bus Location:", dev->gpus[i].busid, "Architecture:", dev->gpus[i].arch);
108109
}
109110

110111
if (run_as_root && perm_set_capabilities(&err, CAP_EFFECTIVE, ecaps[NVC_SHUTDOWN], ecaps_size(NVC_SHUTDOWN)) < 0) {

src/driver.c

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,65 @@ driver_get_device_model_1_svc(ptr_t ctxptr, ptr_t dev, driver_get_device_model_r
633633
return (true);
634634
}
635635

636+
int
637+
driver_get_device_brand(struct driver *ctx, struct driver_device *dev, char **brand)
638+
{
639+
struct driver_get_device_brand_res res = {0};
640+
int rv = -1;
641+
642+
if (call_rpc(ctx, &res, driver_get_device_brand_1, (ptr_t)dev) < 0)
643+
goto fail;
644+
if ((*brand = xstrdup(ctx->err, res.driver_get_device_brand_res_u.brand)) == NULL)
645+
goto fail;
646+
rv = 0;
647+
648+
fail:
649+
xdr_free((xdrproc_t)xdr_driver_get_device_brand_res, (caddr_t)&res);
650+
return (rv);
651+
}
652+
653+
bool_t
654+
driver_get_device_brand_1_svc(ptr_t ctxptr, ptr_t dev, driver_get_device_brand_res *res, maybe_unused struct svc_req *req)
655+
{
656+
struct driver *ctx = (struct driver *)ctxptr;
657+
struct driver_device *handle = (struct driver_device *)dev;
658+
nvmlBrandType_t brand;
659+
const char *buf;
660+
661+
memset(res, 0, sizeof(*res));
662+
if (call_nvml(ctx, nvmlDeviceGetBrand, handle->nvml, &brand) < 0)
663+
goto fail;
664+
switch (brand) {
665+
case NVML_BRAND_QUADRO:
666+
buf = "Quadro";
667+
break;
668+
case NVML_BRAND_TESLA:
669+
buf = "Tesla";
670+
break;
671+
case NVML_BRAND_NVS:
672+
buf = "NVS";
673+
break;
674+
case NVML_BRAND_GRID:
675+
buf = "GRID";
676+
break;
677+
case NVML_BRAND_GEFORCE:
678+
buf = "GeForce";
679+
break;
680+
case NVML_BRAND_TITAN:
681+
buf = "TITAN";
682+
break;
683+
default:
684+
buf = "Unknown";
685+
}
686+
if ((res->driver_get_device_brand_res_u.brand = xstrdup(ctx->err, buf)) == NULL)
687+
goto fail;
688+
return (true);
689+
690+
fail:
691+
error_to_xdr(ctx->err, res);
692+
return (true);
693+
}
694+
636695
int
637696
driver_get_device_arch(struct driver *ctx, struct driver_device *dev, char **arch)
638697
{

src/driver.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,6 @@ int driver_get_device_busid(struct driver *, struct driver_device *, char **);
4646
int driver_get_device_uuid(struct driver *, struct driver_device *, char **);
4747
int driver_get_device_arch(struct driver *, struct driver_device *, char **);
4848
int driver_get_device_model(struct driver *, struct driver_device *, char **);
49+
int driver_get_device_brand(struct driver *, struct driver_device *, char **);
4950

5051
#endif /* HEADER_DRIVER_H */

src/driver_rpc.x

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,13 @@ union driver_get_device_model_res switch (int errcode) {
9595
string errmsg<>;
9696
};
9797

98+
union driver_get_device_brand_res switch (int errcode) {
99+
case 0:
100+
string brand<>;
101+
default:
102+
string errmsg<>;
103+
};
104+
98105
program DRIVER_PROGRAM {
99106
version DRIVER_VERSION {
100107
driver_init_res DRIVER_INIT(ptr_t) = 1;
@@ -108,5 +115,6 @@ program DRIVER_PROGRAM {
108115
driver_get_device_uuid_res DRIVER_GET_DEVICE_UUID(ptr_t, ptr_t) = 9;
109116
driver_get_device_arch_res DRIVER_GET_DEVICE_ARCH(ptr_t, ptr_t) = 10;
110117
driver_get_device_model_res DRIVER_GET_DEVICE_MODEL(ptr_t, ptr_t) = 11;
118+
driver_get_device_brand_res DRIVER_GET_DEVICE_BRAND(ptr_t, ptr_t) = 12;
111119
} = 1;
112120
} = 0x1;

src/nvc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ struct nvc_device {
6262
char *uuid;
6363
char *busid;
6464
char *arch;
65+
char *brand;
6566
struct nvc_device_node node;
6667
};
6768

src/nvc_info.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,8 @@ nvc_device_info_new(struct nvc_context *ctx, const char *opts)
508508
goto fail;
509509
if (driver_get_device_arch(&ctx->drv, dev, &gpu->arch) < 0)
510510
goto fail;
511+
if (driver_get_device_brand(&ctx->drv, dev, &gpu->brand) < 0)
512+
goto fail;
511513
if (driver_get_device_minor(&ctx->drv, dev, &minor) < 0)
512514
goto fail;
513515
if (xasprintf(&ctx->err, &gpu->node.path, NV_DEVICE_PATH, minor) < 0)
@@ -533,6 +535,7 @@ nvc_device_info_free(struct nvc_device_info *info)
533535
free(info->gpus[i].uuid);
534536
free(info->gpus[i].busid);
535537
free(info->gpus[i].arch);
538+
free(info->gpus[i].brand);
536539
free(info->gpus[i].node.path);
537540
}
538541
free(info->gpus);

0 commit comments

Comments
 (0)