Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
weixin_51669992
tensorflow
提交
1cb42505
T
tensorflow
项目概览
weixin_51669992
/
tensorflow
与 Fork 源项目一致
从无法访问的项目Fork
通知
16
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
tensorflow
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
1cb42505
编写于
8月 12, 2019
作者:
Z
Zhuo Peng
提交者:
TensorFlower Gardener
8月 12, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Made the Tensor constructor that takes a TensorBuffer public.
PiperOrigin-RevId: 262940594
上级
5daa70bf
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
50 addition
and
50 deletion
+50
-50
tensorflow/core/framework/tensor.h
tensorflow/core/framework/tensor.h
+50
-50
未找到文件。
tensorflow/core/framework/tensor.h
浏览文件 @
1cb42505
...
...
@@ -54,6 +54,44 @@ Status MaybeMoveSliceToElement(Tensor* parent, Tensor* element, int64 index);
}
// namespace batch_util
/// @ingroup core
/// Interface to access the raw ref-counted data buffer.
class
TensorBuffer
:
public
core
::
RefCounted
{
public:
explicit
TensorBuffer
(
void
*
data_ptr
)
:
data_
(
data_ptr
)
{}
~
TensorBuffer
()
override
{}
/// \brief data() points to a memory region of size() bytes.
///
/// NOTE(mrry): The `data()` method is not virtual for performance reasons.
/// It can be called multiple times when the contents of a `Tensor` are
/// accessed, and so making it non-virtual allows the body to be inlined.
void
*
data
()
const
{
return
data_
;
}
/// \brief Size (in bytes) of the buffer.
virtual
size_t
size
()
const
=
0
;
/// \brief If this TensorBuffer is sub-buffer of another TensorBuffer,
/// returns that TensorBuffer. Otherwise, returns this.
virtual
TensorBuffer
*
root_buffer
()
=
0
;
/// \brief Fills metadata about the allocation into the proto.
virtual
void
FillAllocationDescription
(
AllocationDescription
*
proto
)
const
=
0
;
/// \brief Helper method to reinterpret the buffer as an array of `T`.
template
<
typename
T
>
T
*
base
()
const
{
return
reinterpret_cast
<
T
*>
(
data
());
}
/// \brief Whether this TensorBuffer owns the underlying memory.
virtual
bool
OwnsMemory
()
const
{
return
true
;
}
private:
void
*
const
data_
;
};
/// Represents an n-dimensional array of values.
class
Tensor
{
public:
...
...
@@ -108,6 +146,11 @@ class Tensor {
Tensor
(
Allocator
*
a
,
DataType
type
,
const
TensorShape
&
shape
,
const
AllocationAttributes
&
allocation_attr
);
/// \brief Creates a tensor with the input datatype, shape and buf.
///
/// Acquires a ref on buf that belongs to this Tensor.
Tensor
(
DataType
type
,
const
TensorShape
&
shape
,
TensorBuffer
*
buf
);
/// \brief Creates an empty Tensor of the given data type.
///
/// Like Tensor(), returns a 1-dimensional, 0-element Tensor with
...
...
@@ -606,20 +649,16 @@ class Tensor {
TensorShape
shape_
;
TensorBuffer
*
buf_
;
friend
class
DMAHelper
;
friend
class
TensorCApi
;
friend
class
TensorCord
;
// For access to buf_
friend
class
TensorReference
;
// For access to buf_
friend
class
VariableOp
;
// For access to set_shape
friend
class
AutoReloadVariableOp
;
// For access to set_shape
friend
class
TensorTestHelper
;
// For access to set_shape
friend
class
CastOpBase
;
// For access to set_dtype;
friend
class
DMAHelper
;
// For access to buf_.
friend
class
TensorCApi
;
// For access to buf_.
friend
class
TensorReference
;
// For access to buf_.
friend
class
VariableOp
;
// For access to set_shape.
friend
class
AutoReloadVariableOp
;
// For access to set_shape.
friend
class
TensorTestHelper
;
// For access to set_shape.
friend
class
CastOpBase
;
// For access to set_dtype.
friend
class
OpKernelContext
;
// For access to RefCountIsOne().
friend
class
ScopedAllocator
;
// For access to buf_.
friend
class
XlaTensor
;
// For access to RefCountIsOne().
friend
class
XlaTensorBuffer
;
// For access to the private constructor taking
// the buffer
friend
class
Var
;
template
<
typename
Device
,
typename
T
>
friend
class
AssignVariableOp
;
// For access to RefCountIsOne().
template
<
typename
Device
,
typename
T
>
...
...
@@ -636,11 +675,6 @@ class Tensor {
Tensor
*
parent
,
Tensor
*
element
,
int64
index
);
// For access to RefCountIsOne().
// Creates a tensor with the input datatype, shape and buf.
//
// Acquires a ref on buf that belongs to this Tensor.
Tensor
(
DataType
type
,
const
TensorShape
&
shape
,
TensorBuffer
*
buf
);
bool
CanUseDMA
()
const
;
// Only needed by variable op to set the shape of an uninitialized
...
...
@@ -673,40 +707,6 @@ class Tensor {
// START_SKIP_DOXYGEN
// Interface to access the raw ref-counted data buffer.
class
TensorBuffer
:
public
core
::
RefCounted
{
public:
explicit
TensorBuffer
(
void
*
data_ptr
)
:
data_
(
data_ptr
)
{}
~
TensorBuffer
()
override
{}
// data() points to a memory region of size() bytes.
//
// NOTE(mrry): The `data()` method is not virtual for performance reasons.
// It can be called multiple times when the contents of a `Tensor` are
// accessed, and so making it non-virtual allows the body to be inlined.
void
*
data
()
const
{
return
data_
;
}
virtual
size_t
size
()
const
=
0
;
// If this TensorBuffer is sub-buffer of another TensorBuffer,
// returns that TensorBuffer. Otherwise, returns this.
virtual
TensorBuffer
*
root_buffer
()
=
0
;
// Fill metadata about the allocation into the proto.
virtual
void
FillAllocationDescription
(
AllocationDescription
*
proto
)
const
=
0
;
template
<
typename
T
>
T
*
base
()
const
{
return
reinterpret_cast
<
T
*>
(
data
());
}
// Whether this TensorBuffer owns the underlying memory.
virtual
bool
OwnsMemory
()
const
{
return
true
;
}
private:
void
*
const
data_
;
};
template
<
typename
T
>
T
*
Tensor
::
base
()
const
{
return
buf_
==
nullptr
?
nullptr
:
buf_
->
base
<
T
>
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录