提交 44d60bd9 编写于 作者: H Helin Wang

add comments for exported functions

上级 27fdccc3
...@@ -37,6 +37,7 @@ type ParameterWithConfig struct { ...@@ -37,6 +37,7 @@ type ParameterWithConfig struct {
// Gradient is the gradient of the parameter. // Gradient is the gradient of the parameter.
type Gradient Parameter type Gradient Parameter
// Service is the RPC service for pserver.
type Service struct { type Service struct {
initialized chan struct{} initialized chan struct{}
...@@ -45,6 +46,7 @@ type Service struct { ...@@ -45,6 +46,7 @@ type Service struct {
paramMap map[string]Parameter paramMap map[string]Parameter
} }
// NewService creates a new service.
func NewService() *Service { func NewService() *Service {
s := &Service{} s := &Service{}
s.paramMap = make(map[string]Parameter) s.paramMap = make(map[string]Parameter)
...@@ -52,6 +54,8 @@ func NewService() *Service { ...@@ -52,6 +54,8 @@ func NewService() *Service {
return s return s
} }
// BeginInitParams tells the parameter server that the parameter
// initialization has begun.
func (s *Service) BeginInitParams(config []byte, dummy *int) error { func (s *Service) BeginInitParams(config []byte, dummy *int) error {
select { select {
case <-s.initialized: case <-s.initialized:
...@@ -71,6 +75,7 @@ func (s *Service) BeginInitParams(config []byte, dummy *int) error { ...@@ -71,6 +75,7 @@ func (s *Service) BeginInitParams(config []byte, dummy *int) error {
return nil return nil
} }
// InitParam initializes a parameter.
func (s *Service) InitParam(paramWithConfigs ParameterWithConfig, dummy *int) error { func (s *Service) InitParam(paramWithConfigs ParameterWithConfig, dummy *int) error {
select { select {
case <-s.initialized: case <-s.initialized:
...@@ -90,6 +95,8 @@ func (s *Service) InitParam(paramWithConfigs ParameterWithConfig, dummy *int) er ...@@ -90,6 +95,8 @@ func (s *Service) InitParam(paramWithConfigs ParameterWithConfig, dummy *int) er
return nil return nil
} }
// FinishInitParams tells the parameter server that the parameter
// initialization has finished.
func (s *Service) FinishInitParams(dummy0 int, dummy1 *int) error { func (s *Service) FinishInitParams(dummy0 int, dummy1 *int) error {
select { select {
case <-s.initialized: case <-s.initialized:
...@@ -101,6 +108,8 @@ func (s *Service) FinishInitParams(dummy0 int, dummy1 *int) error { ...@@ -101,6 +108,8 @@ func (s *Service) FinishInitParams(dummy0 int, dummy1 *int) error {
return nil return nil
} }
// SendGrads sends gradients to parameter servers for parameter
// optimization.
func (s *Service) SendGrads(grads []Gradient, dummy *int) error { func (s *Service) SendGrads(grads []Gradient, dummy *int) error {
<-s.initialized <-s.initialized
...@@ -140,6 +149,7 @@ func (s *Service) SendGrads(grads []Gradient, dummy *int) error { ...@@ -140,6 +149,7 @@ func (s *Service) SendGrads(grads []Gradient, dummy *int) error {
return nil return nil
} }
// GetParams gets parameters from the parameter server.
func (s *Service) GetParams(names []string, parameters *[]Parameter) error { func (s *Service) GetParams(names []string, parameters *[]Parameter) error {
<-s.initialized <-s.initialized
s.mu.Lock() s.mu.Lock()
...@@ -166,7 +176,8 @@ func (s *Service) GetParams(names []string, parameters *[]Parameter) error { ...@@ -166,7 +176,8 @@ func (s *Service) GetParams(names []string, parameters *[]Parameter) error {
return nil return nil
} }
func (s *Service) SaveModel(path string, dummy *int) error { // Save tells the parameter server to save parameters.
func (s *Service) Save(path string, dummy *int) error {
<-s.initialized <-s.initialized
// TODO // TODO
......
...@@ -124,7 +124,7 @@ func TestBlockUntilInitialized(t *testing.T) { ...@@ -124,7 +124,7 @@ func TestBlockUntilInitialized(t *testing.T) {
wg.Add(1) wg.Add(1)
go func() { go func() {
var dummy int var dummy int
err := s.SaveModel("", &dummy) err := s.Save("", &dummy)
if err != nil { if err != nil {
t.FailNow() t.FailNow()
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册