Skip to content

Commit d344f67

Browse files
authored
Merge branch 'develop' into tensor_to_EigenTensor
2 parents 4d49f1d + 875946f commit d344f67

38 files changed

+583
-110
lines changed

.pre-commit-config.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121
sha: 28c0ea8a67a3e2dbbf4822ef44e85b63a0080a29
2222
hooks:
2323
- id: clang-formater
24-
- repo: https://github.com/dnephin/pre-commit-golang
25-
sha: e4693a4c282b4fc878eda172a929f7a6508e7d16
24+
- repo: https://github.com/PaddlePaddle/pre-commit-golang
25+
sha: 16398aeccf263adaf53b2495eed0406347d76281
2626
hooks:
2727
- id: go-fmt
28-
files: (.*\.go)
29-
- id: go-lint
30-
files: (.*\.go)
28+
types: [go]
29+
- id: gometalinter
30+
types: [go]

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ before_install:
4141
- pip install rarfile
4242
- curl https://glide.sh/get | bash
4343
- eval "$(GIMME_GO_VERSION=1.8.3 gimme)"
44+
- go get -u github.com/alecthomas/gometalinter
45+
- gometalinter --install
4446
- |
4547
function timeout() { perl -e 'alarm shift; exec @ARGV' "$@"; }
4648
script:

go/master/c/client.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323
log "github.com/sirupsen/logrus"
2424
)
2525

26-
var nullPtr = unsafe.Pointer(uintptr(0))
2726
var mu sync.Mutex
2827
var handleMap = make(map[C.paddle_master_client]*master.Client)
2928
var curHandle C.paddle_master_client
@@ -114,13 +113,13 @@ func paddle_next_record(client C.paddle_master_client, record **C.uchar) C.int {
114113
if err != nil {
115114
// Error
116115
// TODO: return the type of error?
117-
*record = (*C.uchar)(nullPtr)
116+
*record = (*C.uchar)(nil)
118117
return -1
119118
}
120119

121120
if len(r) == 0 {
122121
// Empty record
123-
*record = (*C.uchar)(nullPtr)
122+
*record = (*C.uchar)(nil)
124123
return 0
125124
}
126125

go/master/client.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,10 @@ func (c *Client) getRecords() {
6969
// We treat a task as finished whenever the last data
7070
// instance of the task is read. This is not exactly
7171
// correct, but a reasonable approximation.
72-
c.taskFinished(t.Meta.ID)
72+
err = c.taskFinished(t.Meta.ID)
73+
if err != nil {
74+
log.Errorln(err)
75+
}
7376
}
7477
}
7578

go/master/client_internal_test.go

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,21 @@ func TestGetFinishTask(t *testing.T) {
6666

6767
for i := 0; i < totalTask*chunkPerTask; i++ {
6868
w := recordio.NewWriter(f, -1, -1)
69-
w.Write(nil)
69+
_, err = w.Write(nil)
70+
if err != nil {
71+
panic(err)
72+
}
73+
7074
// call Close to force RecordIO writing a chunk.
71-
w.Close()
75+
err = w.Close()
76+
if err != nil {
77+
panic(err)
78+
}
79+
}
80+
err = f.Close()
81+
if err != nil {
82+
panic(err)
7283
}
73-
f.Close()
7484

7585
// Manually intialize client to avoid calling c.getRecords()
7686
c := &Client{}
@@ -79,7 +89,11 @@ func TestGetFinishTask(t *testing.T) {
7989
ch := make(chan string, 1)
8090
ch <- addr
8191
go c.monitorMaster(ch)
82-
c.SetDataset([]string{path})
92+
err = c.SetDataset([]string{path})
93+
if err != nil {
94+
panic(err)
95+
}
96+
8397
checkOnePass := func(i int) {
8498
var tasks []Task
8599
for idx := 0; idx < totalTask; idx++ {

go/master/client_test.go

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,30 @@ func TestNextRecord(t *testing.T) {
5757

5858
w := recordio.NewWriter(f, -1, -1)
5959
for i := 0; i < total; i++ {
60-
w.Write([]byte{byte(i)})
60+
_, err = w.Write([]byte{byte(i)})
61+
if err != nil {
62+
panic(err)
63+
}
64+
}
65+
66+
err = w.Close()
67+
if err != nil {
68+
panic(err)
69+
}
70+
71+
err = f.Close()
72+
if err != nil {
73+
panic(err)
6174
}
62-
w.Close()
63-
f.Close()
75+
6476
curAddr := make(chan string, 1)
6577
curAddr <- fmt.Sprintf(":%d", p)
6678
c := master.NewClient(curAddr, 10)
67-
c.SetDataset([]string{path})
79+
err = c.SetDataset([]string{path})
80+
if err != nil {
81+
panic(err)
82+
}
83+
6884
for pass := 0; pass < 50; pass++ {
6985
received := make(map[byte]bool)
7086
for i := 0; i < total; i++ {

go/master/etcd_client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ type EtcdClient struct {
3030
// NewEtcdClient creates a new EtcdClient.
3131
func NewEtcdClient(endpoints []string, addr string, lockPath, addrPath, statePath string, ttlSec int) (*EtcdClient, error) {
3232
log.Debugf("Connecting to etcd at %v", endpoints)
33-
// TODO(helin): gracefully shutdown etcd store. Becuase etcd
33+
// TODO(helin): gracefully shutdown etcd store. Because etcd
3434
// store holds a etcd lock, even though the lock will expire
3535
// when the lease timeout, we need to implement graceful
3636
// shutdown to release the lock.
@@ -60,7 +60,7 @@ func NewEtcdClient(endpoints []string, addr string, lockPath, addrPath, statePat
6060
}
6161
log.Debugf("Successfully acquired lock at %s.", lockPath)
6262

63-
put := clientv3.OpPut(addrPath, string(addr))
63+
put := clientv3.OpPut(addrPath, addr)
6464
resp, err := cli.Txn(context.Background()).If(lock.IsOwner()).Then(put).Commit()
6565
if err != nil {
6666
return nil, err

go/master/inmem_store.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import "sync"
44

55
// InMemStore is an in memory implementation of Store interface.
66
//
7-
// It does not tolerate the fault that casues the program to crash.
7+
// It does not tolerate the fault that causes the program to crash.
88
type InMemStore struct {
99
mu sync.Mutex
1010
buf []byte

go/master/service.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ func (s *Service) recover() (bool, error) {
160160

161161
// snapshot *must* be called with s.mu being held.
162162
func (s *Service) snapshot() error {
163-
// TOOD(helin): etcd request has a size limit, so the snapshot
163+
// TODO(helin): etcd request has a size limit, so the snapshot
164164
// size is limited by the max request size. We should either
165165
// divide the snapshot into smaller chunks and save under
166166
// different keys, or configure the request size to be big
@@ -289,7 +289,6 @@ func (s *Service) processFailedTask(t taskEntry, epoch int) {
289289

290290
log.Warningf("Task %v failed %d times, discard.", t.Task, t.NumFailure)
291291
s.taskQueues.Todo = append(s.taskQueues.Todo, t)
292-
return
293292
}
294293

295294
func (s *Service) checkTimeoutFunc(taskID int, epoch int) func() {

go/pserver/client/c/cclient.go

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ import (
3434
log "github.com/sirupsen/logrus"
3535
)
3636

37-
var nullPtr = unsafe.Pointer(uintptr(0))
3837
var mu sync.Mutex
3938
var handleMap = make(map[C.paddle_pserver_client]*client.Client)
4039
var curHandle C.paddle_pserver_client
@@ -63,7 +62,7 @@ func remove(client C.paddle_pserver_client) *client.Client {
6362
}
6463

6564
func cArrayToSlice(p unsafe.Pointer, len int) []byte {
66-
if p == nullPtr {
65+
if p == nil {
6766
return nil
6867
}
6968

@@ -101,11 +100,11 @@ func paddle_new_pserver_client(addrs *C.char, selected int) C.paddle_pserver_cli
101100
}
102101

103102
//export paddle_new_etcd_pserver_client
104-
func paddle_new_etcd_pserver_client(etcd_endpoints *C.char, selected int) C.paddle_pserver_client {
103+
func paddle_new_etcd_pserver_client(etcdEndpoints *C.char, selected int) C.paddle_pserver_client {
105104
// TODO(Longfei: use etcd lock to decide which trainer to initialize the parameters)
106-
addr := C.GoString(etcd_endpoints)
107-
etcd_client := client.NewEtcd(addr)
108-
c := client.NewClient(etcd_client, etcd_client.Desired(), selector(selected != 0))
105+
addr := C.GoString(etcdEndpoints)
106+
etcdClient := client.NewEtcd(addr)
107+
c := client.NewClient(etcdClient, etcdClient.Desired(), selector(selected != 0))
109108
return add(c)
110109
}
111110

@@ -124,20 +123,20 @@ func paddle_begin_init_params(client C.paddle_pserver_client) C.int {
124123
}
125124

126125
//export paddle_init_param
127-
func paddle_init_param(client C.paddle_pserver_client, param C.paddle_parameter, param_config unsafe.Pointer, config_len C.int) C.int {
126+
func paddle_init_param(client C.paddle_pserver_client, param C.paddle_parameter, paramConfig unsafe.Pointer, configLen C.int) C.int {
128127
et := pserver.ElementType(param.element_type)
129128
name := C.GoString(param.name)
130129
content := cArrayToSlice(unsafe.Pointer(param.content), int(param.content_len))
131130
pc := pserver.ParameterWithConfig{
132131
Param: pserver.Parameter{Name: name, ElementType: et, Content: content},
133-
Config: cArrayToSlice(param_config, int(config_len)),
132+
Config: cArrayToSlice(paramConfig, int(configLen)),
134133
}
135134
c := get(client)
136135
err := c.InitParam(pc)
137136

138137
if err != nil {
139138
if err.Error() == pserver.AlreadyInitialized {
140-
log.Warningf("parameter %s already initialized, treat paddle_init_param as sucessful.", name)
139+
log.Warningf("parameter %s already initialized, treat paddle_init_param as successful.", name)
141140
return C.PSERVER_OK
142141
}
143142
log.Errorln(err)
@@ -153,7 +152,7 @@ func paddle_finish_init_params(client C.paddle_pserver_client) C.int {
153152
err := c.FinishInitParams()
154153
if err != nil {
155154
if err.Error() == pserver.AlreadyInitialized {
156-
log.Warningln("parameters already initialized, treat paddle_finish_init_params as sucessful.")
155+
log.Warningln("parameters already initialized, treat paddle_finish_init_params as successful.")
157156
return C.PSERVER_OK
158157
}
159158

@@ -223,12 +222,12 @@ func paddle_get_params(client C.paddle_pserver_client, dst **C.paddle_parameter,
223222
p := ps[i]
224223
param := *(**C.paddle_parameter)(unsafe.Pointer((uintptr(unsafe.Pointer(dst)) + uintptr(i)*unsafe.Sizeof(*dst))))
225224

226-
if unsafe.Pointer(param) == nullPtr {
225+
if unsafe.Pointer(param) == nil {
227226
log.Errorln("must pre-allocate parameter.")
228227
return C.PSERVER_ERROR
229228
}
230229

231-
if unsafe.Pointer(param.content) != nullPtr {
230+
if unsafe.Pointer(param.content) != nil {
232231
if int(param.content_len) != len(p.Content) {
233232
log.Errorf("the pre-allocated content len does not match parameter content len. Pre-allocated len: %d, returned len: %d", param.content_len, len(p.Content))
234233
return C.PSERVER_ERROR

0 commit comments

Comments
 (0)