python - tensorflow tf.slice 会导致分配和/或内存复制吗?
问题描述
做
b = tf.slice(a, [...], [...])
分配一个新的内存缓冲区然后从a的缓冲区复制?还是 a 和 b 共享同一个缓冲区?
而且,怎么样
... = tf.nn.convolution(tf.slice(a, [...], [...]), ...)
在这种情况下,切片没有被命名。这会导致分配和复制吗?
一般来说,是否有一些资源可以学习这些内存管理细节?
谢谢!
解决方案
我对此也很好奇,并进入了tf.slice
.
唯一不分配内存的情况是切片是标识切片(因此没有更改),并且切片是维度 0 对齐的。
if (is_identity) {
VLOG(1) << "Slice identity";
context->set_output(0, input);
*done = true;
return;
}
if (slice_dim0 &&
IsDim0SliceAligned<T>(input.shape(), (*begin)[0], (*size)[0])) {
VLOG(1) << "Slice dim 0: " << input.shape().DebugString();
CHECK_GE(input.dims(), 1); // Otherwise, is_identity should be true.
context->set_output(0, input.Slice((*begin)[0], (*begin)[0] + (*size)[0]));
*done = true;
return;
}
否则将调用以下内容
OP_REQUIRES_OK(context, context->allocate_output(0, *output_shape, result));
推荐阅读
- python - Python Dataframe 计算元素列表的最小值和最大值
- jquery - 试图从另一个函数访问数组
- javascript - 如何将 txt 文件中的数据转换为 Node 中的对象数组
- flutter - 在蜂巢颤动中保存对象列表
- go - How do I import annotations into proto?
- visual-studio-code - How can I solve this yeoman generator code error
- python - 使用python从oracle数据库中的多个表中获取数据并将这些数据插入到另一个表中
- c# - 仅当存在时如何检查linq中数组的第二个元素
- php - How to proxy Headless Wordpress WPGraphQL Plugin Endpoint with NGINX?
- json - Flutter - Pass variable to another screen for URL GET JSON