c converts the SessionOptions to the C API's TF_SessionOptions. Callers must deallocate by calling the returned done() closure.
()
| 321 | // c converts the SessionOptions to the C API's TF_SessionOptions. Callers must |
| 322 | // deallocate by calling the returned done() closure. |
| 323 | func (o *SessionOptions) c() (ret *C.TF_SessionOptions, done func(), err error) { |
| 324 | opt := C.TF_NewSessionOptions() |
| 325 | if o == nil { |
| 326 | return opt, func() { C.TF_DeleteSessionOptions(opt) }, nil |
| 327 | } |
| 328 | t := C.CString(o.Target) |
| 329 | C.TF_SetTarget(opt, t) |
| 330 | C.free(unsafe.Pointer(t)) |
| 331 | |
| 332 | var cConfig unsafe.Pointer |
| 333 | if sz := len(o.Config); sz > 0 { |
| 334 | status := newStatus() |
| 335 | // Copying into C-memory is the simplest thing to do in terms |
| 336 | // of memory safety and cgo rules ("C code may not keep a copy |
| 337 | // of a Go pointer after the call returns" from |
| 338 | // https://golang.org/cmd/cgo/#hdr-Passing_pointers). |
| 339 | cConfig = C.CBytes(o.Config) |
| 340 | C.TF_SetConfig(opt, cConfig, C.size_t(sz), status.c) |
| 341 | if err := status.Err(); err != nil { |
| 342 | C.TF_DeleteSessionOptions(opt) |
| 343 | return nil, func() {}, fmt.Errorf("invalid SessionOptions.Config: %v", err) |
| 344 | } |
| 345 | } |
| 346 | return opt, func() { |
| 347 | C.TF_DeleteSessionOptions(opt) |
| 348 | C.free(cConfig) |
| 349 | }, nil |
| 350 | } |
| 351 | |
| 352 | // cRunArgs translates the arguments to Session.Run and PartialRun.Run into |
| 353 | // values suitable for C library calls. |
no test coverage detected