-
Notifications
You must be signed in to change notification settings - Fork 5.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add cgo wrapper for recordio, make go_cmake automatically download go… #2294
Conversation
paddle/go/cmake/golang.cmake
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why don't we put these .cmake files /cmake
, but in /go/cmake
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
endfunction(add_go_executable) | ||
|
||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this add_go_library actually the go_library in our design?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, will rename.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not create_recordio_writer? I mean this seems not specific for paddle.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[]string
to ...string
, so that it can accept only one filename pattern easily?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point! Done.
paddle/go/recordio/reader.go
Outdated
// Err returns the first non-EOF error that was encountered by the | ||
// Scanner. | ||
func (s *Scanner) Err() error { | ||
if s.err == io.EOF { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point!
paddle/go/crecordio/crecordio.go
Outdated
scanner *recordio.MultiScanner | ||
} | ||
|
||
func cArrayToSlice(p unsafe.Pointer, len int) []byte { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that this function duplicates with the one in cclient.go?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that this function should be named write_records
or recordio_write
. I prefer the later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we make this function return the number of bytes like C's write
function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename this function to release_recordio_writer
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Let 's move |
Let's move |
Thanks! Will fix the issues with a follow up PR. |
… dependency