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
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 1 addition & 11 deletions bindings/go/src/examples/perftest/perftest.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,17 +368,7 @@ func main() {
flag.StringVar(&perfTestParams.ip, "i", "", "server address to connect")

perfTestParams.memType = UCS_MEMORY_TYPE_HOST
flag.CommandLine.Func("m", "memory type: host(default), cuda", func(p string) error {
mtypeStr := strings.ToLower(p)
if mtypeStr == "host" {
perfTestParams.memType = UCS_MEMORY_TYPE_HOST
} else if mtypeStr == "cuda" {
perfTestParams.memType = UCS_MEMORY_TYPE_CUDA
} else {
return errors.New("memory type can be host or cuda")
}
return nil
})
flag.Var(&perfTestParams.memType, "m", "memory type: host(default), cuda")

flag.Parse()

Expand Down
14 changes: 14 additions & 0 deletions bindings/go/src/ucx/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ package ucx
import "C"
import "unsafe"

import (
"errors"
"strings"
)

// Memory handle is an opaque object representing a memory region allocated
// through UCP library, which is optimized for remote memory access
// operations (zero-copy operations). The memory could be registered
Expand Down Expand Up @@ -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

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

}
return nil
}
Loading