add cgo wrapper for recordio, make go_cmake automatically download go…#2294
add cgo wrapper for recordio, make go_cmake automatically download go…#2294helinwang merged 8 commits intoPaddlePaddle:developfrom
Conversation
| install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/${NAME} DESTINATION bin) | ||
| endfunction(add_go_executable) | ||
|
|
||
| set(PADDLE_IN_GOPATH "${GOPATH}/src/github.com/PaddlePaddle") |
There was a problem hiding this comment.
Why don't we put these .cmake files /cmake, but in /go/cmake?
There was a problem hiding this comment.
I think they are not ready yet, this cmake's purpose is for not blocking the development. I was planning to move to /cmake with the help from @gangliao in another PR.
paddle/go/cmake/golang.cmake
Outdated
| set(PADDLE_IN_GOPATH "${GOPATH}/src/github.com/PaddlePaddle") | ||
| file(MAKE_DIRECTORY ${PADDLE_IN_GOPATH}) | ||
|
|
||
| function(ADD_GO_LIBRARY NAME BUILD_TYPE) |
There was a problem hiding this comment.
Is this add_go_library actually the go_library in our design?
There was a problem hiding this comment.
Yes, will rename.
paddle/go/crecordio/crecordio.go
Outdated
| } | ||
|
|
||
| //export paddle_new_writer | ||
| func paddle_new_writer(path *C.char) C.writer { |
There was a problem hiding this comment.
Why not create_recordio_writer? I mean this seems not specific for paddle.
wangkuiyi
left a comment
There was a problem hiding this comment.
I think we can add recordio.Multi{Reader/Writer} to the Go code, before we wrap the functionality for C/C++.
|
@wangkuiyi Added |
paddle/go/recordio/multi_reader.go
Outdated
| ) | ||
|
|
||
| // MultiScanner is a scanner for multiple recordio files. | ||
| type MultiScanner struct { |
There was a problem hiding this comment.
We'd rename this high-level API to Scanner. And we rename the existing Scanner to RangeScanner. We can do this in a future PR.
paddle/go/recordio/multi_reader.go
Outdated
| } | ||
|
|
||
| // NewMultiScanner creates a new MultiScanner. | ||
| func NewMultiScanner(paths []string) (*MultiScanner, error) { |
There was a problem hiding this comment.
[]string to ...string, so that it can accept only one filename pattern easily?
There was a problem hiding this comment.
Good point! Done.
| // Err returns the first non-EOF error that was encountered by the | ||
| // Scanner. | ||
| func (s *Scanner) Err() error { | ||
| if s.err == io.EOF { |
| scanner *recordio.MultiScanner | ||
| } | ||
|
|
||
| func cArrayToSlice(p unsafe.Pointer, len int) []byte { |
There was a problem hiding this comment.
It seems that this function duplicates with the one in cclient.go?
There was a problem hiding this comment.
We can create a package to hold a few commonly used functions. Since they are simple, and probably will never change, I duplicated the code when different package uses them. I can create a package to hold them if you think it's better.
paddle/go/crecordio/crecordio.go
Outdated
| } | ||
|
|
||
| //export write_recordio | ||
| func write_recordio(writer C.writer, buf *C.uchar, size C.int) int { |
There was a problem hiding this comment.
It seems that this function should be named write_records or recordio_write. I prefer the later.
There was a problem hiding this comment.
Should we make this function return the number of bytes like C's write function?
There was a problem hiding this comment.
Good point! Done.
paddle/go/crecordio/crecordio.go
Outdated
| } | ||
|
|
||
| //export read_next_item | ||
| func read_next_item(reader C.reader, size *C.int) *C.uchar { |
There was a problem hiding this comment.
It seems that this function should be defined:
func recordio_read(reader C.reader, record *C.uchar) int so to return the number of read bytes as C's read does?
There was a problem hiding this comment.
Good point! Done.
paddle/go/crecordio/crecordio.go
Outdated
| } | ||
|
|
||
| //export release_recordio | ||
| func release_recordio(writer C.writer) { |
There was a problem hiding this comment.
Rename this function to release_recordio_writer?
|
Let 's move |
|
Let's move |
|
Thanks! Will fix the issues with a follow up PR. |
… dependency