提交 c2d418db 编写于 作者: Y Yu Yang 提交者: luotao1

Merge internal changes (#198)

* fix DataProvider create function args bug

Change-Id: I9e3a1c535c805bf30204a14aea8d5143ff534784

* remove PserverForPython.h which is not used

Change-Id: I2b27f1f3c11a42766a92fc689f0f5f1f73ee1d70

* add internal document script

Change-Id: Ia0fec79456caea0b271f9903cc13e8a3d32e0774
上级 43f7d7b7
...@@ -308,7 +308,8 @@ public: ...@@ -308,7 +308,8 @@ public:
/** /**
* @brief create only used for unittest. * @brief create only used for unittest.
*/ */
inline static DataProvider* create(const DataConfig &config, bool useGpu) { inline static DataProvider* create(const DataConfig &config,
bool useGpu = FLAGS_use_gpu) {
return create(config, ModelConfig(), useGpu); return create(config, ModelConfig(), useGpu);
} }
......
#!/bin/bash
# Copyright (c) 2016 Baidu, Inc. All Rights Reserved
cd `dirname $0`
# Add set -e, cd to directory.
set -e
mkdir -p $PWD/../../../build
cd $PWD/../../../build
# Compile Documentation only.
cmake .. -DCMAKE_BUILD_TYPE=Debug -DWITH_GPU=OFF -DWITH_DOC=ON
make paddle_docs paddle_docs_cn
# remove old docs. mv new docs in deeplearning.baidu.com
scp -r doc/html paddle_doc@yq01-idl-gpu-offline42.yq01.baidu.com:/home/paddle_doc/www/doc_new
ssh paddle_doc@yq01-idl-gpu-offline42.yq01.baidu.com "cd ~/www/ && rm -r doc && mv doc_new doc"
scp -r doc_cn/html paddle_doc@yq01-idl-gpu-offline42.yq01.baidu.com:/home/paddle_doc/www/doc_cn_new
ssh paddle_doc@yq01-idl-gpu-offline42.yq01.baidu.com "cd ~/www/ && rm -r doc_cn && mv doc_cn_new doc_cn"
/* Copyright (c) 2016 Baidu, Inc. All Rights Reserve.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
#pragma once
#include "paddle/pserver/ParameterClient.h"
#include "paddle/pserver/ParameterServer.h"
#include "paddle/parameter/Parameter.h"
#include <Python.h>
namespace paddle {
struct PyObjectDeleter {
void operator()(PyObject* obj) {
if (obj) {
Py_DECREF(obj);
}
}
};
class ParameterClientPy : public ParameterClient {
protected:
typedef std::unique_ptr<PyObject, PyObjectDeleter> PyObjectPtr;
std::vector<ParameterPtr> parameter_;
int initArgc_;
char** initArgv_;
public:
ParameterClientPy(std::vector<std::string> configs, int argc,
std::vector<std::string> argv, bool useGpu) {
initArgc_ = argc;
initArgv_ = new char* [argc];
for (int i = 0; i < argc; i++) {
initArgv_[i] = new char[argv[i].size()];
strcpy(initArgv_[i], // NOLINT
argv[i].c_str()); // NOLINT TODO(yuyang18): use snprintf instead.
}
ParameterConfig pyConfig;
ParameterPtr param;
for (auto& config : configs) {
pyConfig.ParseFromString(config);
param.reset(new Parameter(pyConfig, useGpu));
parameter_.push_back(param);
}
Py_Initialize();
CHECK(Py_IsInitialized());
}
~ParameterClientPy() {
delete initArgv_;
Py_Finalize();
}
Parameter getParameter(int idx) { return *(parameter_[idx].get()); }
void initClientPy() {
initMain(initArgc_, initArgv_);
CHECK(init(parameter_)) << "Init Client Failed.";
}
void setConfigPy(std::string config) {
OptimizationConfig optConfig;
optConfig.ParseFromString(config);
setConfig(optConfig);
}
bool inStatusPy(int status) { return inStatus(PServerStatus(status)); }
void setStatusPy(int status) { setStatus(PServerStatus(status)); }
void waitForStatusPy(int status) { waitForStatus(PServerStatus(status)); }
void sendParameterPy(int updateMode, int parameterType, int numSamples,
real cost, bool sendBackParameter) {
sendParameter(ParameterUpdateMode(updateMode), ParameterType(parameterType),
int64_t(numSamples), real(cost), sendBackParameter);
}
template <class ProtoIn, class ProtoOut>
std::string asyncCallPy(const char* serviceName, const char* funcName,
const std::string in) {
ProtoIn protoIn;
ProtoOut protoOut;
std::mutex waitLock;
std::string data;
protoIn.ParseFromString(in);
waitLock.lock();
auto callback = [&](ProtoOut* pOut, bool isSuccessful) {
if (isSuccessful) {
pOut->SerializeToString(&data);
} else {
LOG(INFO) << "Async Talk Failed.";
}
waitLock.unlock();
};
ubClient_.asyncCall<ProtoIn, ProtoOut>(serviceName, funcName, protoIn,
&protoOut, callback);
waitLock.lock();
protoOut.SerializeToString(&data);
return data;
}
};
} // namespace paddle
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册