Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BINDINGS/GO/PERF: Implement flag.Value for UcsMemoryType #10312

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

Artemy-Mellanox
Copy link
Contributor

What?

Implement flag.Value interface for ucx.UcsMemoryType and use flag.Var function to set -m argument.

Why?

For enums, flag.Value/flag.Var is the better choice because it promotes good software design principles like type safety, reusability, and clean separation of concerns.

tvegas1
tvegas1 previously approved these changes Nov 21, 2024
switch strings.ToLower(value) {
case "host": *mt = UCS_MEMORY_TYPE_HOST
case "cuda": *mt = UCS_MEMORY_TYPE_CUDA
default: return errors.New("memory type can be host or cuda")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can either be

@@ -67,3 +72,12 @@ func (m *UcpMemory) Close() error {

return nil
}

func (mt *UcsMemoryType) Set (value string) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does it mean that ucx go bindings set memory type by string instead of value?
IMO string->Value logic should be in perftest, not in go bindings.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in golang interface can't be implemented on type from other package, though may created wrapper for mem type in perftest
on the other hand value -> string logic already implemented in go bindings,

func (m UcsMemoryType) String() string {
and in those languages it's convenient to implement from/to string conversion along with the object

Comment on lines 12 to 19
static inline const char* ucxgo_get_ucs_mem_type_name(ucs_memory_type_t idx) {
return ucs_memory_type_names[idx];
}

static inline ssize_t ucxgo_parse_ucs_mem_type_name(void* value) {
ssize_t idx = ucs_string_find_in_list((const char *)value, ucs_memory_type_names, 0);
free(value);
return idx;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do these functions have to be inline?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants