Returns ApiDef proto instance for the TensorFlow operation named `opname`.
(opname string)
| 98 | // Returns ApiDef proto instance for the TensorFlow operation |
| 99 | // named `opname`. |
| 100 | func (m *apiDefMap) Get(opname string) (*pb.ApiDef, error) { |
| 101 | cname := C.CString(opname) |
| 102 | defer C.free(unsafe.Pointer(cname)) |
| 103 | status := C.TF_NewStatus() |
| 104 | defer C.TF_DeleteStatus(status) |
| 105 | apidefBuf := C.TF_ApiDefMapGet( |
| 106 | m.c, cname, C.size_t(len(opname)), status) |
| 107 | defer C.TF_DeleteBuffer(apidefBuf) |
| 108 | if C.TF_GetCode(status) != C.TF_OK { |
| 109 | return nil, errors.New(C.GoString(C.TF_Message(status))) |
| 110 | } |
| 111 | if apidefBuf == nil { |
| 112 | return nil, fmt.Errorf("could not find ApiDef for %s", opname) |
| 113 | } |
| 114 | |
| 115 | var ( |
| 116 | apidef = new(pb.ApiDef) |
| 117 | size = int(apidefBuf.length) |
| 118 | // A []byte backed by C memory. |
| 119 | // See: https://github.com/golang/go/wiki/cgo#turning-c-arrays-into-go-slices |
| 120 | data = (*[1 << 30]byte)(unsafe.Pointer(apidefBuf.data))[:size:size] |
| 121 | err = proto.Unmarshal(data, apidef) |
| 122 | ) |
| 123 | if err != nil { |
| 124 | return nil, err |
| 125 | } |
| 126 | return apidef, nil |
| 127 | } |