Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
7386b06c
P
Paddle
项目概览
Crayon鑫
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
7386b06c
编写于
6月 23, 2017
作者:
D
dzhwinter
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
"add optimizer naive link option"
上级
eaed87b0
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
76 addition
and
194 deletion
+76
-194
go/pserver/cclient/test/CMakeLists.txt
go/pserver/cclient/test/CMakeLists.txt
+0
-4
go/pserver/cclient/test/main.c
go/pserver/cclient/test/main.c
+0
-104
go/pserver/cclient/test/test_cclient.c
go/pserver/cclient/test/test_cclient.c
+73
-86
go/pserver/optimizer.go
go/pserver/optimizer.go
+3
-0
未找到文件。
go/pserver/cclient/test/CMakeLists.txt
浏览文件 @
7386b06c
cmake_minimum_required
(
VERSION 3.0
)
cmake_minimum_required
(
VERSION 3.0
)
add_executable
(
main main.c
)
add_dependencies
(
main paddle_pserver_cclient
)
add_executable
(
test_cclient test_cclient.c
)
add_executable
(
test_cclient test_cclient.c
)
add_dependencies
(
test_cclient paddle_pserver_cclient
)
add_dependencies
(
test_cclient paddle_pserver_cclient
)
...
@@ -13,10 +11,8 @@ endif()
...
@@ -13,10 +11,8 @@ endif()
if
(
PROJ_ROOT
)
if
(
PROJ_ROOT
)
include_directories
(
${
CMAKE_CURRENT_BINARY_DIR
}
/..
)
include_directories
(
${
CMAKE_CURRENT_BINARY_DIR
}
/..
)
target_link_libraries
(
main
${
CMAKE_CURRENT_BINARY_DIR
}
/../libpaddle_pserver_cclient.a pthread
)
target_link_libraries
(
test_cclient
${
CMAKE_CURRENT_BINARY_DIR
}
/../libpaddle_pserver_cclient.a pthread
)
target_link_libraries
(
test_cclient
${
CMAKE_CURRENT_BINARY_DIR
}
/../libpaddle_pserver_cclient.a pthread
)
else
(
PROJ_ROOT
)
else
(
PROJ_ROOT
)
include_directories
(
${
CMAKE_BINARY_DIR
}
)
include_directories
(
${
CMAKE_BINARY_DIR
}
)
target_link_libraries
(
main
${
CMAKE_BINARY_DIR
}
/libpaddle_pserver_cclient.a pthread
)
target_link_libraries
(
test_cclient
${
CMAKE_BINARY_DIR
}
/libpaddle_pserver_cclient.a pthread
)
target_link_libraries
(
test_cclient
${
CMAKE_BINARY_DIR
}
/libpaddle_pserver_cclient.a pthread
)
endif
(
PROJ_ROOT
)
endif
(
PROJ_ROOT
)
go/pserver/cclient/test/main.c
已删除
100644 → 0
浏览文件 @
eaed87b0
#include <stdio.h>
#include <stdlib.h>
#include "libpaddle_pserver_cclient.h"
// TODO(helin): Fix: gtest using cmake is not working, using this
// hacky way for now.
#define fail() \
fprintf(stderr, "info: %s:%d: ", __FILE__, __LINE__); \
exit(-1);
void
sendGrads
(
paddle_pserver_client
c
)
{
unsigned
char
grad_a
[
2000
]
=
{
2
};
unsigned
char
grad_b
[
3000
]
=
{
3
};
paddle_gradient
grad1
=
{
"param_a"
,
PADDLE_ELEMENT_TYPE_FLOAT32
,
grad_a
,
2000
};
paddle_gradient
grad2
=
{
"param_b"
,
PADDLE_ELEMENT_TYPE_FLOAT32
,
grad_b
,
3000
};
paddle_gradient
*
grads
[
2
]
=
{
&
grad1
,
&
grad2
};
if
(
paddle_send_grads
(
c
,
grads
,
2
))
{
fail
();
}
}
void
getParams
(
paddle_pserver_client
c
)
{
paddle_parameter
param_a
;
paddle_parameter
param_b
;
char
name_a
[]
=
"param_a"
;
char
name_b
[]
=
"param_b"
;
// Must pre-allocate the prameter content before calling paddle_get_params.
unsigned
char
content_a
[
2000
]
=
{};
unsigned
char
content_b
[
3000
]
=
{};
param_a
.
element_type
=
PADDLE_ELEMENT_TYPE_FLOAT32
;
param_a
.
name
=
name_a
;
param_a
.
content
=
content_a
;
param_a
.
content_len
=
2000
;
param_b
.
element_type
=
PADDLE_ELEMENT_TYPE_FLOAT32
;
param_b
.
name
=
name_b
;
param_b
.
content
=
content_b
;
param_b
.
content_len
=
3000
;
paddle_parameter
*
params
[
2
]
=
{
&
param_a
,
&
param_b
};
if
(
paddle_get_params
(
c
,
params
,
2
))
{
fail
();
}
}
int
main
()
{
char
addr
[]
=
"localhost:3000"
;
paddle_pserver_client
c
=
paddle_new_pserver_client
(
addr
,
1
);
char
config_proto
[
1024
];
size_t
config_proto_len
=
0
;
ssize_t
nread
;
FILE
*
fp
=
fopen
(
"optimizer.pb.txt"
,
"r"
);
if
(
!
fp
)
{
fail
();
}
while
((
nread
=
getline
(
&
config_proto
,
&
config_proto_len
,
fp
))
!=
-
1
)
{
printf
(
"%s"
,
config_proto
);
}
fclose
(
fp
);
retry:
if
(
paddle_begin_init_params
(
c
))
{
paddle_parameter
param
;
char
name_a
[]
=
"param_a"
;
char
name_b
[]
=
"param_b"
;
unsigned
char
content_a
[
2000
]
=
{
1
};
unsigned
char
content_b
[
3000
]
=
{
0
};
param
.
element_type
=
PADDLE_ELEMENT_TYPE_FLOAT32
;
param
.
name
=
name_a
;
param
.
content
=
content_a
;
param
.
content_len
=
2000
;
int
error
=
paddle_init_param
(
c
,
param
,
config_proto
,
config_proto_len
);
if
(
error
!=
0
)
{
goto
retry
;
}
param
.
element_type
=
PADDLE_ELEMENT_TYPE_FLOAT32
;
param
.
name
=
name_b
;
param
.
content
=
content_b
;
param
.
content_len
=
3000
;
error
=
paddle_init_param
(
c
,
param
,
NULL
,
0
);
if
(
error
!=
0
)
{
goto
retry
;
}
error
=
paddle_finish_init_params
(
c
);
if
(
error
!=
0
)
{
goto
retry
;
}
}
int
i
;
for
(
i
=
0
;
i
<
100
;
i
++
)
{
sendGrads
(
c
);
getParams
(
c
);
}
if
(
paddle_save_model
(
c
,
"/tmp/"
))
{
fail
();
}
return
0
;
}
go/pserver/cclient/test/test_cclient.c
浏览文件 @
7386b06c
...
@@ -3,113 +3,100 @@
...
@@ -3,113 +3,100 @@
#include "libpaddle_pserver_cclient.h"
#include "libpaddle_pserver_cclient.h"
typedef
float
real
;
// TODO(helin): Fix: gtest using cmake is not working, using this
// hacky way for now.
void
fail
()
{
#define fail() \
// TODO(helin): fix: gtest using cmake is not working, using this
fprintf(stderr, "info: %s:%d: ", __FILE__, __LINE__); \
// hacky way for now.
printf
(
"test failed.
\n
"
);
exit(-1);
exit(-1);
void
sendGrads
(
paddle_pserver_client
c
)
{
unsigned
char
grad_a
[
2000
]
=
{
2
};
unsigned
char
grad_b
[
3000
]
=
{
3
};
paddle_gradient
grad1
=
{
"param_a"
,
PADDLE_ELEMENT_TYPE_FLOAT32
,
grad_a
,
2000
};
paddle_gradient
grad2
=
{
"param_b"
,
PADDLE_ELEMENT_TYPE_FLOAT32
,
grad_b
,
3000
};
paddle_gradient
*
grads
[
2
]
=
{
&
grad1
,
&
grad2
};
if
(
paddle_send_grads
(
c
,
grads
,
2
))
{
fail
();
}
}
}
void
print_parameter
(
paddle_gradient
*
param
)
{
void
getParams
(
paddle_pserver_client
c
)
{
if
(
param
==
NULL
)
{
paddle_parameter
param_a
;
printf
(
"param is NULL!!
\n
"
);
paddle_parameter
param_b
;
}
else
{
char
name_a
[]
=
"param_a"
;
printf
(
"==== parameter ====
\n
"
);
char
name_b
[]
=
"param_b"
;
printf
(
"name: %s
\n
"
,
param
->
name
);
// Must pre-allocate the prameter content before calling paddle_get_params.
printf
(
"content_len: %d
\n
"
,
param
->
content_len
);
unsigned
char
content_a
[
2000
]
=
{};
printf
(
"content_type: %d
\n
"
,
param
->
element_type
);
unsigned
char
content_b
[
3000
]
=
{};
int
i
;
param_a
.
element_type
=
PADDLE_ELEMENT_TYPE_FLOAT32
;
for
(
i
=
0
;
i
<
param
->
content_len
/
(
int
)
sizeof
(
real
);
++
i
)
{
param_a
.
name
=
name_a
;
printf
(
"%f "
,
((
float
*
)
param
->
content
)[
i
]);
param_a
.
content
=
content_a
;
}
param_a
.
content_len
=
2000
;
printf
(
"
\n\n
"
);
param_b
.
element_type
=
PADDLE_ELEMENT_TYPE_FLOAT32
;
param_b
.
name
=
name_b
;
param_b
.
content
=
content_b
;
param_b
.
content_len
=
3000
;
paddle_parameter
*
params
[
2
]
=
{
&
param_a
,
&
param_b
};
if
(
paddle_get_params
(
c
,
params
,
2
))
{
fail
();
}
}
}
}
int
main
()
{
int
main
()
{
char
addr
[]
=
"localhost:3000"
;
char
addr
[]
=
"localhost:3000"
;
paddle_pserver_client
c
=
paddle_new_pserver_client
(
addr
,
1
);
paddle_pserver_client
c
=
paddle_new_pserver_client
(
addr
,
1
);
char
config_proto
[
1024
];
char
*
names
[]
=
{
"param_a"
,
"param_b"
};
size_t
config_proto_len
=
0
;
ssize_t
nread
;
FILE
*
fp
=
fopen
(
"optimizer.pb.txt"
,
"r"
);
if
(
!
fp
)
{
fail
();
}
while
((
nread
=
getline
(
&
config_proto
,
&
config_proto_len
,
fp
))
!=
-
1
)
{
printf
(
"%s"
,
config_proto
);
}
fclose
(
fp
);
retry:
retry:
printf
(
"init parameter to pserver:
\n
"
);
real
param_content1
[]
=
{
0
.
1
,
0
.
2
,
0
.
3
};
real
param_content2
[]
=
{
0
.
4
,
0
.
5
,
0
.
6
};
paddle_parameter
**
params
=
(
paddle_parameter
**
)
malloc
(
sizeof
(
paddle_parameter
*
)
*
2
);
params
[
0
]
=
(
paddle_parameter
*
)
malloc
(
sizeof
(
paddle_parameter
));
params
[
0
]
->
name
=
names
[
0
];
params
[
0
]
->
content
=
(
unsigned
char
*
)
param_content1
;
params
[
0
]
->
content_len
=
3
*
sizeof
(
real
);
params
[
0
]
->
element_type
=
PADDLE_ELEMENT_TYPE_FLOAT32
;
params
[
1
]
=
(
paddle_parameter
*
)
malloc
(
sizeof
(
paddle_parameter
));
params
[
1
]
->
name
=
names
[
1
];
params
[
1
]
->
content
=
(
unsigned
char
*
)
param_content2
;
params
[
1
]
->
content_len
=
3
*
sizeof
(
real
);
params
[
1
]
->
element_type
=
PADDLE_ELEMENT_TYPE_INT32
;
if
(
paddle_begin_init_params
(
c
))
{
if
(
paddle_begin_init_params
(
c
))
{
if
(
paddle_init_param
(
c
,
*
params
[
0
],
NULL
,
0
)
!=
0
)
{
paddle_parameter
param
;
char
name_a
[]
=
"param_a"
;
char
name_b
[]
=
"param_b"
;
unsigned
char
content_a
[
2000
]
=
{
1
};
unsigned
char
content_b
[
3000
]
=
{
0
};
param
.
element_type
=
PADDLE_ELEMENT_TYPE_FLOAT32
;
param
.
name
=
name_a
;
param
.
content
=
content_a
;
param
.
content_len
=
2000
;
int
error
=
paddle_init_param
(
c
,
param
,
config_proto
,
config_proto_len
);
if
(
error
!=
0
)
{
goto
retry
;
goto
retry
;
}
}
if
(
paddle_init_param
(
c
,
*
params
[
1
],
NULL
,
0
)
!=
0
)
{
param
.
element_type
=
PADDLE_ELEMENT_TYPE_FLOAT32
;
param
.
name
=
name_b
;
param
.
content
=
content_b
;
param
.
content_len
=
3000
;
error
=
paddle_init_param
(
c
,
param
,
NULL
,
0
);
if
(
error
!=
0
)
{
goto
retry
;
goto
retry
;
}
}
if
(
paddle_finish_init_params
(
c
)
!=
0
)
{
error
=
paddle_finish_init_params
(
c
);
if
(
error
!=
0
)
{
goto
retry
;
goto
retry
;
}
}
}
else
{
fail
();
}
printf
(
"get inited parameters from pserver:
\n
"
);
// get parameters again by reusing the allocated parameter buffers.
if
(
paddle_get_params
(
c
,
params
,
2
)
!=
0
)
{
fail
();
}
print_parameter
(
params
[
0
]);
print_parameter
(
params
[
1
]);
printf
(
"send gradient to pserver:
\n
"
);
real
gradient_content1
[]
=
{
0
.
01
,
0
.
02
,
0
.
03
};
real
gradinet_content2
[]
=
{
0
.
04
,
0
.
05
,
0
.
06
};
paddle_gradient
**
grads
=
(
paddle_gradient
**
)
malloc
(
sizeof
(
paddle_gradient
*
)
*
2
);
grads
[
0
]
=
(
paddle_gradient
*
)
malloc
(
sizeof
(
paddle_gradient
));
grads
[
0
]
->
name
=
names
[
0
];
grads
[
0
]
->
content
=
(
unsigned
char
*
)
gradient_content1
;
grads
[
0
]
->
content_len
=
3
*
sizeof
(
real
);
grads
[
0
]
->
element_type
=
PADDLE_ELEMENT_TYPE_FLOAT32
;
grads
[
1
]
=
(
paddle_gradient
*
)
malloc
(
sizeof
(
paddle_gradient
));
grads
[
1
]
->
name
=
names
[
1
];
grads
[
1
]
->
content
=
(
unsigned
char
*
)
gradinet_content2
;
grads
[
1
]
->
content_len
=
3
*
sizeof
(
real
);
grads
[
1
]
->
element_type
=
PADDLE_ELEMENT_TYPE_INT32
;
printf
(
"print gradient sent to pserver:
\n
"
);
print_parameter
(
grads
[
0
]);
print_parameter
(
grads
[
1
]);
if
(
paddle_send_grads
(
c
,
grads
,
2
)
!=
0
)
{
fail
();
}
}
printf
(
"get updated parameters from pserver:
\n
"
)
;
int
i
;
// get parameters again by reusing the allocated parameter buffers.
for
(
i
=
0
;
i
<
100
;
i
++
)
{
if
(
paddle_get_params
(
c
,
params
,
2
)
!=
0
)
{
sendGrads
(
c
);
fail
(
);
getParams
(
c
);
}
}
print_parameter
(
params
[
0
]);
print_parameter
(
params
[
1
]);
if
(
paddle_save_model
(
c
,
"/tmp/"
)
!=
0
)
{
if
(
paddle_save_model
(
c
,
"/tmp/"
))
{
fail
();
fail
();
}
}
...
...
go/pserver/optimizer.go
浏览文件 @
7386b06c
package
pserver
package
pserver
/*
/*
// TODO(zhihong): move compile flags to cmake go_library
#cgo pkg-config: protobuf
#cgo CFLAGS: -I ../../
#cgo CFLAGS: -I ../../
#cgo LDFLAGS: ../../build/paddle/optimizer/libpaddle_optimizer.a ../../build/proto/libpaddle_proto.a ../../third_party/install/glog/lib/libglog.a ../../third_party/install/gtest/lib/libgtest.a ../../third_party/install/gflags/lib/libgflags.a ../../third_party/install/openblas/lib/libopenblas.a -I/usr/local/lib/ -lprotobuf
#include "paddle/optimizer/optimizer.h"
#include "paddle/optimizer/optimizer.h"
*/
*/
import
"C"
import
"C"
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录