Skip to content
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

parameter client library: stub and cgo part with functional test. #2172

Merged
merged 14 commits into from
May 18, 2017

Conversation

helinwang
Copy link
Contributor

@helinwang helinwang commented May 16, 2017

cmake is taken from /~https://github.com/gangliao/cmake_cxx_go .
The CMakeLists.txt I wrote is not perfect (some hard coded path in CMakeLists.txt, and gtest not working, perhaps because I don't know how to use cmake), but something enough to get started.
The temporary cmake solution can be fixed after #2154 being fixed.

Copy link
Collaborator

@wangkuiyi wangkuiyi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest restructure the source tree:

Following the TensorFlow's source code convention, we put all Go code in

github.com/paddlepaddle/paddle/paddle/go

and refer to Go packages in Go code as

import (
  pd "github.com/paddlepaddle/paddle/paddle/go"
)

Under the .../go directory, we should have the following packages:

  1. pd/pserver/rpc_service.go defines the Go RPC type of pserver.

  2. pd/cmd/pserver/pserer.go defines the main function of pserver and builds into $GOPATH/bin/pserver.

  3. pd/pserver/cclient/cclient.go builds into cclient.h, libclient.a

    Please be aware that we need to customize CMake to generate the header file and the static library in corresponding path in /build:

    build/paddle/go/pserver/cclient/cclient.h
    build/paddle_go_pserver_cclient_libcclient.a
    

    and CMake source set the following directories as the default directory when it calls GCC:

    gcc -I~/work/paddle  -I~/work/paddle/build ...

    so that we can write the following header inclusion in paddle_trainer.cc:

    #include "paddle/go/pserver/cclient/cclient.h"

    and our CMake functions should add the link flag -lpaddle_go_pserver_cclient_cclient.a

// servers. Other trainers will be blocked until the initialization is
// done, and they need to get the initialized parameters from
// parameter servers using GetParams.
func (c *Client) BeginInitParams(pserverConfigProto []byte) (selected bool, err error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we naming return parameters, maybe only need return at the end of the function.

Copy link
Contributor

@typhoonzero typhoonzero May 17, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a function or function param to tell parameter server which optimization algorithm to use?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@typhoonzero
we just set optimizer as a parameter in pserverConfig Proto, then parameterserver create optimizer with the optimizer_id
see the related API issue
#2168

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

明白了

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Yancey1989 that's a good use case, but here is mainly for documentation purpose (when user see the name, he understands what the return value stands for.)

ElementType ElementType
Content []byte
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to define the ParameterBlock type(partitioned Parameter ) and put these things in a Constant header file? These things would be a shared concept in many files.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't quite follow what is "ParameterBlock type", do you mean ElementType?

// servers. Other trainers will be blocked until the initialization is
// done, and they need to get the initialized parameters from
// parameter servers using GetParams.
func (c *Client) BeginInitParams(pserverConfigProto []byte) (selected bool, err error) {
Copy link
Contributor

@typhoonzero typhoonzero May 17, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a function or function param to tell parameter server which optimization algorithm to use?

typedef struct {
char* name;
paddle_element_type element_type;
char* content;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be unsigned char * to indicate 0-255 byte stream?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point! Done.

free(param->content);
}

free(param);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to set the pointer to NULL after free. If this function is the finalization step, just ignore this comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's the finalization step :)

@@ -0,0 +1,239 @@
package main
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this main.go program going to compile to a shared library like .so, so that trainers which are written in python can call this lib? If so, we should add a CPython wrapper to call this CGo program, and the paddle/go/pserver/lib/client/test/main.c should be a python example. Current paddle/go/pserver/lib/client/test/main.c can be moved to the python wrapper functions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking this need to be integrated into Paddle C++ code (a lot of pointers are used, not sure how much does CPython supports pointer), maybe I am wrong. I think we will know better when we begin to integrate.

@helinwang
Copy link
Contributor Author

helinwang commented May 17, 2017

@wangkuiyi Thanks! The folder structure is corrected.

Copy link
Contributor

@typhoonzero typhoonzero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Not sure about the CMake part though.

@helinwang
Copy link
Contributor Author

helinwang commented May 18, 2017

@typhoonzero Thanks :) cmake part is very rough, I will fix with the help from @gangliao (his work is still in PR)

@helinwang helinwang merged commit 501b59a into PaddlePaddle:develop May 18, 2017
@helinwang helinwang deleted the cgo branch May 18, 2017 23:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants