提交 4d82a69b 编写于 作者: W wangjiawei04

modify variable name

Change-Id: Ic8bf6e4ebe23d23a5dfc670be2fe07a6f2352554
上级 b5fdf719
...@@ -32,7 +32,7 @@ if(WITH_GPU) ...@@ -32,7 +32,7 @@ if(WITH_GPU)
endif() endif()
target_link_libraries(serving opencv_imgcodecs target_link_libraries(serving opencv_imgcodecs
${opencv_depend_libs} -Wl,--whole-archive fluid_cpu_engine ${opencv_depend_libs} -Wl,--whole-archive fluid_cpu_engine
-Wl,--no-whole-archive pdserving paddle_fluid ${paddle_depend_libs} rocksdb_impl rocksdb -Wl,--no-whole-archive pdserving paddle_fluid ${paddle_depend_libs} kvdb rocksdb
${MKLML_LIB} ${MKLML_IOMP_LIB} -lpthread -lcrypto -lm -lrt -lssl -ldl -lz -lbz2) ${MKLML_LIB} ${MKLML_IOMP_LIB} -lpthread -lcrypto -lm -lrt -lssl -ldl -lz -lbz2)
install(TARGETS serving install(TARGETS serving
......
...@@ -8,8 +8,8 @@ set(SRC_LIST ${CMAKE_CURRENT_LIST_DIR}/src/test_rocksdb.cpp ...@@ -8,8 +8,8 @@ set(SRC_LIST ${CMAKE_CURRENT_LIST_DIR}/src/test_rocksdb.cpp
${CMAKE_CURRENT_LIST_DIR}/src/paddle_rocksdb.cpp ${CMAKE_CURRENT_LIST_DIR}/src/paddle_rocksdb.cpp
${CMAKE_CURRENT_LIST_DIR}/src/gtest_kvdb.cpp) ${CMAKE_CURRENT_LIST_DIR}/src/gtest_kvdb.cpp)
add_library(rocksdb_impl ${SRC_LIST}) add_library(kvdb ${SRC_LIST})
install(TARGETS rocksdb_impl ARCHIVE DESTINATION ${PADDLE_SERVING_INSTALL_DIR}/lib/) install(TARGETS kvdb ARCHIVE DESTINATION ${PADDLE_SERVING_INSTALL_DIR}/lib/)
add_executable(kvdb_test ${SRC_LIST}) add_executable(kvdb_test ${SRC_LIST})
add_dependencies(kvdb_test rocksdb) add_dependencies(kvdb_test rocksdb)
......
...@@ -45,7 +45,7 @@ public: ...@@ -45,7 +45,7 @@ public:
virtual std::string GetMD5() = 0; virtual std::string GetMD5() = 0;
virtual bool CheckDiff() = 0; virtual bool CheckDiff() = 0;
virtual std::chrono::system_clock::time_point GetTimeStamp() = 0; virtual std::chrono::system_clock::time_point GetTimeStamp() = 0;
virtual void Read(std::vector<std::string>&) = 0; virtual void Read(AbstractParamDict*) = 0;
virtual ~AbstractDictReader() = 0; virtual ~AbstractDictReader() = 0;
protected: protected:
std::string filename_; std::string filename_;
......
...@@ -30,18 +30,18 @@ public: ...@@ -30,18 +30,18 @@ public:
static int db_count; static int db_count;
}; };
class MockDictReader : public AbstractDictReader{ class RocksDBDictReader : public AbstractDictReader{
public: public:
std::string GetFileName(); std::string GetFileName();
void SetFileName(std::string); void SetFileName(std::string);
std::string GetMD5(); std::string GetMD5();
bool CheckDiff(); bool CheckDiff();
std::chrono::system_clock::time_point GetTimeStamp(); std::chrono::system_clock::time_point GetTimeStamp();
void Read(std::vector<std::string>&); void Read(AbstractParamDict*);
~MockDictReader(); ~RocksDBDictReader();
}; };
class MockParamDict : public AbstractParamDict{ class RocksDBParamDict : public AbstractParamDict{
public: public:
std::vector<AbsDictReaderPtr> GetDictReaderLst(); std::vector<AbsDictReaderPtr> GetDictReaderLst();
void SetDictReaderLst(std::vector<AbsDictReaderPtr>); void SetDictReaderLst(std::vector<AbsDictReaderPtr>);
...@@ -59,7 +59,7 @@ public: ...@@ -59,7 +59,7 @@ public:
void SetKVDB(std::pair<AbsKVDBPtr, AbsKVDBPtr>); void SetKVDB(std::pair<AbsKVDBPtr, AbsKVDBPtr>);
void CreateKVDB(); void CreateKVDB();
~MockParamDict(); ~RocksDBParamDict();
}; };
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#include "kvdb/mock_kvdb_impl.h" #include "kvdb/rocksdb_impl.h"
#include "kvdb/kvdb_impl.h" #include "kvdb/kvdb_impl.h"
#include "kvdb/paddle_rocksdb.h" #include "kvdb/paddle_rocksdb.h"
#include <gtest/gtest.h> #include <gtest/gtest.h>
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#include "kvdb/mock_kvdb_impl.h" #include "kvdb/rocksdb_impl.h"
#include "kvdb/kvdb_impl.h" #include "kvdb/kvdb_impl.h"
#include "kvdb/paddle_rocksdb.h" #include "kvdb/paddle_rocksdb.h"
#include <gtest/gtest.h> #include <gtest/gtest.h>
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#include "kvdb/mock_kvdb_impl.h" #include "kvdb/rocksdb_impl.h"
#include "kvdb/kvdb_impl.h" #include "kvdb/kvdb_impl.h"
#include "kvdb/paddle_rocksdb.h" #include "kvdb/paddle_rocksdb.h"
#include <gtest/gtest.h> #include <gtest/gtest.h>
...@@ -28,8 +28,8 @@ protected: ...@@ -28,8 +28,8 @@ protected:
static void SetUpTestCase() { static void SetUpTestCase() {
kvdb = std::make_shared<RocksKVDB>(); kvdb = std::make_shared<RocksKVDB>();
dict_reader = std::make_shared<MockDictReader>(); dict_reader = std::make_shared<RocksDBDictReader>();
param_dict = std::make_shared<MockParamDict>(); param_dict = std::make_shared<RocksDBParamDict>();
} }
static AbsKVDBPtr kvdb; static AbsKVDBPtr kvdb;
...@@ -81,7 +81,7 @@ TEST_F(KVDBTest, AbstractDictReader_Unit_Test) { ...@@ -81,7 +81,7 @@ TEST_F(KVDBTest, AbstractDictReader_Unit_Test) {
ASSERT_NE(timestamp_2, timestamp_3); ASSERT_NE(timestamp_2, timestamp_3);
} }
#include <cmath> #include <cmath>
TEST_F(KVDBTest, MockParamDict_Unit_Test) { TEST_F(KVDBTest, RocksDBParamDict_Unit_Test) {
std::string test_in_filename = "abs_dict_reader_test_in.txt"; std::string test_in_filename = "abs_dict_reader_test_in.txt";
param_dict->SetDictReaderLst({dict_reader}); param_dict->SetDictReaderLst({dict_reader});
param_dict->CreateKVDB(); param_dict->CreateKVDB();
......
...@@ -12,22 +12,22 @@ ...@@ -12,22 +12,22 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#include "kvdb/mock_kvdb_impl.h" #include "kvdb/rocksdb_impl.h"
#include <thread> #include <thread>
#include <iterator> #include <iterator>
#include <fstream> #include <fstream>
#include <sstream> #include <sstream>
std::string MockDictReader::GetFileName() { std::string RocksDBDictReader::GetFileName() {
return this->filename_; return this->filename_;
} }
void MockDictReader::SetFileName(std::string filename) { void RocksDBDictReader::SetFileName(std::string filename) {
this->filename_ = filename; this->filename_ = filename;
this->last_md5_val_ = this->GetMD5(); this->last_md5_val_ = this->GetMD5();
this->time_stamp_ = std::chrono::system_clock::now(); this->time_stamp_ = std::chrono::system_clock::now();
} }
std::string MockDictReader::GetMD5() { std::string RocksDBDictReader::GetMD5() {
auto getCmdOut = [] (std::string cmd) { auto getCmdOut = [] (std::string cmd) {
std::string data; std::string data;
FILE *stream = nullptr; FILE *stream = nullptr;
...@@ -50,40 +50,40 @@ std::string MockDictReader::GetMD5() { ...@@ -50,40 +50,40 @@ std::string MockDictReader::GetMD5() {
return md5val; return md5val;
} }
bool MockDictReader::CheckDiff() { bool RocksDBDictReader::CheckDiff() {
return this->GetMD5() == this->last_md5_val_; return this->GetMD5() == this->last_md5_val_;
} }
std::chrono::system_clock::time_point MockDictReader::GetTimeStamp() { std::chrono::system_clock::time_point RocksDBDictReader::GetTimeStamp() {
//TODO: Implement Get Time Stamp of dict file
return this->time_stamp_; return this->time_stamp_;
} }
void MockDictReader::Read(std::vector<std::string>& res) { void RocksDBDictReader::Read(AbstractParamDict* param_dict) {
std::string line; std::string line;
std::ifstream infile(this->filename_); std::ifstream infile(this->filename_);
if (infile.is_open()) { if (infile.is_open()) {
while (getline(infile, line)) { while (getline(infile, line)) {
res.push_back(line); //TODO: Write String Parse Here
// param_dict->InsertSparseValue();
} }
} }
infile.close(); infile.close();
} }
MockDictReader::~MockDictReader() { RocksDBDictReader::~RocksDBDictReader() {
//TODO: I imageine nothing to do here //TODO: I imageine nothing to do here
} }
std::vector<AbsDictReaderPtr> MockParamDict::GetDictReaderLst() { std::vector<AbsDictReaderPtr> RocksDBParamDict::GetDictReaderLst() {
return this->dict_reader_lst_; return this->dict_reader_lst_;
} }
void MockParamDict::SetDictReaderLst(std::vector<AbsDictReaderPtr> lst) { void RocksDBParamDict::SetDictReaderLst(std::vector<AbsDictReaderPtr> lst) {
this->dict_reader_lst_ = lst; this->dict_reader_lst_ = lst;
} }
std::vector<float> MockParamDict::GetSparseValue(std::string feasign, std::string slot) { std::vector<float> RocksDBParamDict::GetSparseValue(std::string feasign, std::string slot) {
auto BytesToFloat = [](uint8_t* byteArray){ auto BytesToFloat = [](uint8_t* byteArray){
return *((float*)byteArray); return *((float*)byteArray);
}; };
...@@ -100,15 +100,15 @@ std::vector<float> MockParamDict::GetSparseValue(std::string feasign, std::strin ...@@ -100,15 +100,15 @@ std::vector<float> MockParamDict::GetSparseValue(std::string feasign, std::strin
return value; return value;
} }
std::vector<float> MockParamDict::GetSparseValue(int64_t feasign, int64_t slot) { std::vector<float> RocksDBParamDict::GetSparseValue(int64_t feasign, int64_t slot) {
return this->GetSparseValue(std::to_string(feasign), std::to_string(slot)); return this->GetSparseValue(std::to_string(feasign), std::to_string(slot));
} }
bool MockParamDict::InsertSparseValue(int64_t feasign, int64_t slot, const std::vector<float>& values) { bool RocksDBParamDict::InsertSparseValue(int64_t feasign, int64_t slot, const std::vector<float>& values) {
return this->InsertSparseValue(std::to_string(feasign), std::to_string(slot), values); return this->InsertSparseValue(std::to_string(feasign), std::to_string(slot), values);
} }
bool MockParamDict::InsertSparseValue(std::string feasign, std::string slot, const std::vector<float>& values) { bool RocksDBParamDict::InsertSparseValue(std::string feasign, std::string slot, const std::vector<float>& values) {
auto FloatToBytes = [](float fvalue, uint8_t *arr){ auto FloatToBytes = [](float fvalue, uint8_t *arr){
unsigned char *pf = nullptr; unsigned char *pf = nullptr;
unsigned char *px = nullptr; unsigned char *px = nullptr;
...@@ -136,12 +136,12 @@ bool MockParamDict::InsertSparseValue(std::string feasign, std::string slot, con ...@@ -136,12 +136,12 @@ bool MockParamDict::InsertSparseValue(std::string feasign, std::string slot, con
return true; return true;
} }
void MockParamDict::UpdateBaseModel() { void RocksDBParamDict::UpdateBaseModel() {
std::thread t([&] () { std::thread t([&] () {
for (AbsDictReaderPtr dict_reader: this->dict_reader_lst_) { for (AbsDictReaderPtr dict_reader: this->dict_reader_lst_) {
if (dict_reader->CheckDiff()) { if (dict_reader->CheckDiff()) {
std::vector<std::string> strs; std::vector<std::string> strs;
dict_reader->Read(strs); dict_reader->Read(this);
for (const std::string& str: strs) { for (const std::string& str: strs) {
std::vector<std::string> arr; std::vector<std::string> arr;
std::istringstream in(str); std::istringstream in(str);
...@@ -162,27 +162,27 @@ void MockParamDict::UpdateBaseModel() { ...@@ -162,27 +162,27 @@ void MockParamDict::UpdateBaseModel() {
} }
void MockParamDict::UpdateDeltaModel() { void RocksDBParamDict::UpdateDeltaModel() {
UpdateBaseModel(); UpdateBaseModel();
} }
std::pair<AbsKVDBPtr, AbsKVDBPtr> MockParamDict::GetKVDB() { std::pair<AbsKVDBPtr, AbsKVDBPtr> RocksDBParamDict::GetKVDB() {
return {front_db, back_db}; return {front_db, back_db};
} }
void MockParamDict::SetKVDB(std::pair<AbsKVDBPtr, AbsKVDBPtr> kvdbs) { void RocksDBParamDict::SetKVDB(std::pair<AbsKVDBPtr, AbsKVDBPtr> kvdbs) {
this->front_db = kvdbs.first; this->front_db = kvdbs.first;
this->back_db = kvdbs.second; this->back_db = kvdbs.second;
} }
void MockParamDict::CreateKVDB() { void RocksDBParamDict::CreateKVDB() {
this->front_db = std::make_shared<RocksKVDB>(); this->front_db = std::make_shared<RocksKVDB>();
this->back_db = std::make_shared<RocksKVDB>(); this->back_db = std::make_shared<RocksKVDB>();
this->front_db->CreateDB(); this->front_db->CreateDB();
this->back_db->CreateDB(); this->back_db->CreateDB();
} }
MockParamDict::~MockParamDict() { RocksDBParamDict::~RocksDBParamDict() {
} }
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#include "kvdb/mock_kvdb_impl.h" #include "kvdb/rocksdb_impl.h"
int RocksKVDB::db_count; int RocksKVDB::db_count;
void RocksKVDB::CreateDB() { void RocksKVDB::CreateDB() {
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#include "kvdb/mock_kvdb_impl.h" #include "kvdb/rocksdb_impl.h"
#include "kvdb/paddle_rocksdb.h" #include "kvdb/paddle_rocksdb.h"
#include <iostream> #include <iostream>
void test_rockskvdb() { void test_rockskvdb() {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册