-
Notifications
You must be signed in to change notification settings - Fork 3
/
profiler.go
44 lines (36 loc) · 910 Bytes
/
profiler.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package pytorch
// #include "cbits/predictor.hpp"
// #include <stdlib.h>
import "C"
import (
"unsafe"
"github.com/pkg/errors"
)
func (p *Predictor) StartProfiling(name, metadata string) error {
cname := C.CString(name)
cmetadata := C.CString(metadata)
defer C.free(unsafe.Pointer(cname))
defer C.free(unsafe.Pointer(cmetadata))
C.Torch_ProfilingStart(p.ctx, cname, cmetadata)
return nil
}
func (p *Predictor) EndProfiling() error {
C.Torch_ProfilingEnd(p.ctx)
return nil
}
func (p *Predictor) EnableProfiling() error {
C.Torch_ProfilingEnable(p.ctx)
return nil
}
func (p *Predictor) DisableProfiling() error {
C.Torch_ProfilingDisable(p.ctx)
return nil
}
func (p *Predictor) ReadProfile() (string, error) {
cstr := C.Torch_ProfilingRead(p.ctx)
if cstr == nil {
return "", errors.New("failed to read nil profile")
}
defer C.free(unsafe.Pointer(cstr))
return C.GoString(cstr), nil
}