访问自定义OP的输入值时的segmenation故障
Segmenation fault when accessing input value of custom op
我只是按照说明进行操作,但是在尝试读取/gpu op上的输入值时,我总是最终会有一个segfault。如果我在CPU上执行相同的代码(然后使用不同的REGISTER_KERNEL_BUILDER
(,则可以按预期工作。不幸的是,gdb
的回溯没有给我进一步的信息,即使我使用Bazel的Debug Flag构建自定义OP。
这是我的代码
interface.cc
REGISTER_OP("Interface")
.Input("pointer_to_grid: int32")
.Output("current_grid_data: float32")
.SetShapeFn([](::tensorflow::shape_inference::InferenceContext* c) {
shape_inference::ShapeHandle input_shape;
TF_RETURN_IF_ERROR(c->WithRank(c->input(0), 0, &input_shape)); // allow only a 1D pointer address stored in an integer
return Status::OK();
});
class InterfaceGPU : public OpKernel {
public:
explicit InterfaceGPU(OpKernelConstruction* context) : OpKernel(context) {}
void Compute(OpKernelContext* context) override {
// Grab the input tensor
const Tensor& input_tensor = context->input(0);
const auto input = input_tensor.flat<int32>();
printf("This works %d n", input);
printf("This does not %d n", input(0)); //Segementation fault is here
//...
}
};
REGISTER_KERNEL_BUILDER(Name("GridPointerInterface").Device(DEVICE_GPU), InterfaceGPU);
runme.py
import tensorflow as tf
import numpy as np
import sys
op_interface = tf.load_op_library('~/tensorflow/bazel-bin/tensorflow/core/user_ops/interface.so')
with tf.device("/gpu:0"):
with tf.Session() as sess:
sess.run(op_interface.interface_gpu(12))
我已经用TF 1.6&amp;1.7。在我看来,TF正在跳过内存分配,不幸的是,我不确定如何强制这一点。
感谢您的建议
这是可以预期的,因为您正在尝试从CPU访问GPU上存储的值(因此您可以打印它(。
操纵GPU上的值的方法是通过特征。如果您查看TensorFlow中其他内核的实现,则会看到诸如output.flat<float32>().device(ctx->eigen_device<GPUDevice>()) = input.flat<float32>() + ....
之类的代码。这告诉eigen为您创建CUDA内核。
如果要直接操纵GPU上的值,则需要同步GPU流并将其复制到CPU内存,这很复杂。
相关文章:
- 分段故障(堆芯转储)矢量
- C++中的动态铸造故障
- 数组的指针从不分段故障
- vscode g++链路故障:体系结构x86_64的未定义符号
- 访问被拒绝后,c++中的故障保护代码
- Windows 10-使用gtkmm-3.0库和g++[包括再现]的分段故障
- 调试 CUDA MMU 故障
- Geeksforgeeks C 程序故障排除:IEE 754 表示法为十进制
- Arch Linux.AUR 包 mysql 不能用 makepkg 构建.错误:构建 () 中出现故障
- 正在处理故障(堆芯转储)
- 在 Boost::fiber 中引发的BOOST_ASSERT故障 Visual Studio "Debug" 构建
- 如何进行故障排除:未定义对"非虚拟 thunk to ..."的引用
- C++函数过载会导致 SEG 故障
- 分段故障 运行C++代码时出现 SIGSEGV
- 当新的故障时,是否有必要留出一些紧急内存?
- Python & C-C++ 扩展模块案例段故障
- 带升压的 SEG 故障::make_shared / 特征3 内存.h.
- 在 c++ 中,发生故障后是否需要 stream.clear()?
- 分段故障背包问题
- 访问自定义OP的输入值时的segmenation故障