Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
VisualDL
提交
efcd3587
V
VisualDL
项目概览
PaddlePaddle
/
VisualDL
1 年多 前同步成功
通知
88
Star
4655
Fork
642
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
10
列表
看板
标记
里程碑
合并请求
2
Wiki
5
Wiki
分析
仓库
DevOps
项目成员
Pages
V
VisualDL
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
10
Issue
10
列表
看板
标记
里程碑
合并请求
2
合并请求
2
Pages
分析
分析
仓库分析
DevOps
Wiki
5
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
efcd3587
编写于
11月 16, 2017
作者:
Q
Qiao Longfei
提交者:
GitHub
11月 16, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request
#21
from Superjom/feature/add_storage
feature/add storage
上级
4c949e69
e5c1ef4f
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
216 addition
and
0 deletion
+216
-0
CMakeLists.txt
CMakeLists.txt
+19
-0
visualdl/backend/storage/storage.cc
visualdl/backend/storage/storage.cc
+45
-0
visualdl/backend/storage/storage.h
visualdl/backend/storage/storage.h
+65
-0
visualdl/backend/storage/storage.proto
visualdl/backend/storage/storage.proto
+87
-0
未找到文件。
CMakeLists.txt
0 → 100644
浏览文件 @
efcd3587
cmake_minimum_required
(
VERSION 3.8
)
project
(
VisualDL
)
set
(
CMAKE_CXX_STANDARD 11
)
include_directories
(
${
CMAKE_CURRENT_SOURCE_DIR
}
)
include_directories
(
thirdparty/local/include
)
link_directories
(
thirdparty/local/lib
)
add_subdirectory
(
thirdparty/pybind11-2.2.1
)
set
(
SOURCE_FILES
visualdl/backend/storage/storage.cc visualdl/backend/storage/storage.h
visualdl/backend/storage/storage.pb.h
visualdl/backend/storage/storage.pb.cc
)
add_library
(
storage visualdl/backend/storage/storage.cc
visualdl/backend/storage/storage.pb.cc
)
add_executable
(
VisualDL
${
SOURCE_FILES
}
)
\ No newline at end of file
visualdl/backend/storage/storage.cc
0 → 100644
浏览文件 @
efcd3587
#include <fstream>
#include <glog/logging.h>
#include "visualdl/backend/storage/storage.h"
namespace
visualdl
{
storage
::
Tablet
*
Storage
::
Add
(
const
std
::
string
&
tag
)
{
return
&
proto_
.
mutable_tablets
()
->
at
(
tag
);
}
const
storage
::
Tablet
*
Storage
::
Find
(
const
std
::
string
&
tag
)
const
{
auto
it
=
proto_
.
tablets
().
find
(
tag
);
if
(
it
!=
proto_
.
tablets
().
end
())
{
return
&
it
->
second
;
}
return
nullptr
;
}
void
Storage
::
Save
(
const
std
::
string
&
path
)
const
{
std
::
ofstream
file
(
path
,
file
.
binary
|
file
.
out
);
CHECK
(
file
.
is_open
())
<<
"can't open path "
<<
path
;
auto
str
=
Serialize
();
file
.
write
(
str
.
c_str
(),
str
.
size
());
}
void
Storage
::
Load
(
const
std
::
string
&
path
)
{
std
::
ifstream
file
(
path
,
file
.
binary
);
CHECK
(
file
.
is_open
())
<<
"can't open path "
<<
path
;
size_t
size
=
file
.
tellg
();
std
::
string
buffer
(
size
,
' '
);
file
.
seekg
(
0
);
file
.
read
(
&
buffer
[
0
],
size
);
DeSerialize
(
buffer
);
}
std
::
string
Storage
::
Serialize
()
const
{
return
proto_
.
SerializeAsString
();
}
void
Storage
::
DeSerialize
(
const
std
::
string
&
data
)
{
proto_
.
ParseFromString
(
data
);
}
}
// namespace visualdl
visualdl/backend/storage/storage.h
0 → 100644
浏览文件 @
efcd3587
#ifndef VISUALDL_STORAGE_H
#define VISUALDL_STORAGE_H
#include <string>
#include <time.h>
#include "visualdl/backend/storage/storage.pb.h"
namespace
visualdl
{
class
Storage
final
{
public:
/*
* There should be only one Storage instance in memory.
*/
Storage
&
Global
()
{
static
Storage
*
instance
=
new
Storage
();
return
*
instance
;
}
/*
* Add a new tablet named `tag`, the newly added instance will be returned.
*/
storage
::
Tablet
*
Add
(
const
std
::
string
&
tag
);
/*
* Search the tablet named `tag`, if not exist, return nullptr.
*/
const
storage
::
Tablet
*
Find
(
const
std
::
string
&
tag
)
const
;
/*
* Serialize this object to string and save it to a file.
*/
void
Save
(
const
std
::
string
&
path
)
const
;
/*
* Load the Protobuf message from a file.
*/
void
Load
(
const
std
::
string
&
path
);
protected:
/*
* Serialize the Storage instance to string.
*/
std
::
string
Serialize
()
const
;
/*
* De-serialize from a string and update this Storage instance.
*/
void
DeSerialize
(
const
std
::
string
&
data
);
Storage
()
{
// set time stamp
time_t
time0
;
time
(
&
time0
);
proto_
.
set_timestamp
(
time0
);
}
private:
storage
::
Storage
proto_
;
};
}
// namespace visualdl
#endif //VISUALDL_STORAGE_H
visualdl/backend/storage/storage.proto
0 → 100644
浏览文件 @
efcd3587
syntax
=
"proto3"
;
package
storage
;
enum
DataType
{
// single entry
kInt32
=
0
;
kInt64
=
1
;
kFloat
=
2
;
kDouble
=
3
;
kString
=
4
;
kBool
=
5
;
// entrys
kInt64s
=
6
;
kFloats
=
7
;
kDoubles
=
8
;
kStrings
=
9
;
kInt32s
=
10
;
kBools
=
11
;
}
// A data array, which type is `type`.
message
Entry
{
// if all the entries in a record share the same data type, ignore this field
// and store type to `dtype` in `Record`.
DataType
dtype
=
1
;
// single element
int32
i32
=
2
;
int64
i64
=
3
;
string
s
=
4
;
float
f
=
5
;
double
d
=
6
;
bool
b
=
7
;
// array
repeated
int64
i64s
=
8
;
repeated
float
fs
=
9
;
repeated
double
ds
=
10
;
repeated
int32
i32s
=
11
;
repeated
bool
bs
=
12
;
}
message
Record
{
Entry
data
=
1
;
int64
timestamp
=
2
;
// store the count of writing operations to the tablet.
int64
id
=
3
;
DataType
dtype
=
4
;
// shape or some other meta infomation for this record, if all the records
// share the same meta, just store one copy of meta in `Storage`, or create
// a unique copy for each `Record`.
Entry
meta
=
5
;
}
/*
A Tablet stores the records of a component which type is `component` and indidates as `tag`.
The records will be saved in a file which name contains `tag`. During the running period,
`num_records` will be accumulated, and `num_samples` indicates the size of sample set the
reservoir sampling algorithm will collect.
*/
message
Tablet
{
// the kinds of the components that supported
enum
Type
{
kScalar
=
0
;
kHistogram
=
1
;
kGraph
=
2
;
}
// type of the component, different component should have different storage format.
Type
component
=
1
;
// records the total count of records, each Write operation should increate this value.
int64
num_records
=
2
;
// indicate the number of instances to sample, this should be a constant value.
int32
num_samples
=
3
;
repeated
Record
records
=
4
;
// store a meta infomation if all the records share.
Entry
meta
=
5
;
// the unique identification for this `Tablet`.
string
tag
=
6
;
}
/*
The Storage stores all the records.
*/
message
Storage
{
// tags to Tablet, should be thread safe if fix the keys after initialization.
map
<
string
,
Tablet
>
tablets
=
1
;
string
dir
=
2
;
int64
timestamp
=
3
;
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录