Skip to content

[ENH]: Provide a helper for NVML "struct version" handling #1535

@mdboom

Description

@mdboom

Is this a duplicate?

Area

cuda.bindings

Is your feature request related to a problem? Please describe.

NVML has a common pattern for specifying the version of struct passed to a function:

(<nvmlType_v2_t*>my_struct).version = sizeof(nvmlType_v2_t) | (2 << 24)

In the NVML header, this is handled by the NVML_STRUCT_VERSION macro:

#define NVML_STRUCT_VERSION(data, ver) (unsigned int)(sizeof(nvml ## data ## _v ## ver ## _t) | \
                                                      (ver << 24U))

We can't use this macro directly from cuda-bindings because:

  1. This is a macro and we don't include the nvml.h header directly
  2. Passing a struct name to a function and calling sizeof on it won't work in Cython

Describe the solution you'd like

There are still some ways this could be made slightly better and more obvious as to what is going on, however. Probably by adding an inline function that does:

nvmlStructVersion(unsigned int sizeof_struct, unsigned int ver)

Called like so:

version = nvmlStructVersion(sizeof(nvmlStruct_v2_t), 2))

Describe alternatives you've considered

No response

Additional context

No response

Metadata

Metadata

Assignees

Labels

cuda.bindingsEverything related to the cuda.bindings moduletriageNeeds the team's attention

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions