Go
Wrap the cgo calls that launch GPU work, and flush before exiting.
Go keeps the current span in a context.Context, not per thread, and goroutines move between OS threads. There's nothing to hook, so the Go bridge wraps the calls that launch GPU work instead.
import warpspan "github.com/zraisan/warpspan/bridge/go"
func main() {
if err := warpspan.Install(""); err != nil && !errors.Is(err, warpspan.ErrNotConfigured) {
log.Print(err)
}
defer warpspan.Flush()
// ...
}
func handle(ctx context.Context) {
warpspan.Do(ctx, func() { C.run_model() })
}Do locks the goroutine to its OS thread, publishes the span from ctx, runs fn and restores the thread's previous span. Each call costs a few cgo calls, so wrap a request's or a batch's GPU work, not every kernel.
Install("")readsCUDA_INJECTION64_PATH. It returnsErrNotConfiguredwhen that's unset, which apps that also run without Warpspan can ignore.- Only launches on the calling OS thread are linked: not those from goroutines
fnstarts, nor from threads a C library or a Go CUDA binding launches on. - Call
Flush()before exiting. Go exits without running Catexithandlers, so the library's own exit flush never runs and the last second of kernels is lost.os.Exitandlog.Fatalskip deferred calls too.Flushreturnsfalseif it had nothing to call.
The module is github.com/zraisan/warpspan/bridge/go and needs cgo.