Skip to content

Commit

Permalink
Merge pull request #9581 from rakhmets/topic/perftest-rm-goroutine
Browse files Browse the repository at this point in the history
BINDINGS/GO: Locked OS thread before setting CUDA device.
  • Loading branch information
yosefe authored Jan 7, 2024
2 parents 1dbcdf0 + 90b303c commit ad5ca70
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions bindings/go/src/examples/perftest/perftest.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
. "ucx"
"unsafe"
. "cuda"
"runtime"
)

type PerfTestParams struct {
Expand Down Expand Up @@ -92,6 +93,7 @@ func initContext() {

func tryCudaSetDevice() {
if perfTestParams.memType == UCS_MEMORY_TYPE_CUDA {
runtime.LockOSThread()
if ret := CudaSetDevice(); ret != nil {
panic(ret)
}
Expand Down Expand Up @@ -233,8 +235,6 @@ func serverAmRecvHandler(header unsafe.Pointer, headerSize uint64, data *UcpAmDa
if data.IsDataValid() {
atomic.AddUint32(&perfTest.numCompletedRequests, 1)
} else {
tryCudaSetDevice()

data.Receive(getAddressOffsetForThread(tid), perfTestParams.messageSize,
(&UcpRequestParams{}).SetMemType(perfTestParams.memType).SetCallback(func(request *UcpRequest, status UcsStatus, length uint64) {
atomic.AddUint32(&perfTest.numCompletedRequests, 1)
Expand Down Expand Up @@ -281,12 +281,12 @@ func serverStart() error {
}

func clientThreadDoIter(i int, t uint) {
tryCudaSetDevice()

start := time.Now()
var request *UcpRequest
requestParams := (&UcpRequestParams{}).SetMemType(perfTestParams.memType)

tryCudaSetDevice()

header := unsafe.Pointer(&t)
request, _ = perfTest.eps[t].SendAmNonBlocking(t, header, uint64(unsafe.Sizeof(t)), getAddressOffsetForThread(t), perfTestParams.messageSize, 0, requestParams)

Expand Down

0 comments on commit ad5ca70

Please sign in to comment.