Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 0 additions & 96 deletions paddle/fluid/operators/read_file_op.cc

This file was deleted.

1 change: 1 addition & 0 deletions paddle/fluid/pir/dialect/op_generator/ops_api_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
'layer_norm_act_xpu',
'multi_encoder_xpu',
'multihead_matmul',
'read_file',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

read_file不加到这个list里是会编译报错吗?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

好像不会,这就删掉

'squeeze_excitation_block',
'yolo_box_xpu',
'fusion_gru',
Expand Down
4 changes: 4 additions & 0 deletions paddle/phi/api/yaml/op_compat.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3402,6 +3402,10 @@
outputs :
out : Out

- op: read_file
outputs :
out : Out

- op: recv_v2
outputs :
out : Out
Expand Down
12 changes: 12 additions & 0 deletions paddle/phi/api/yaml/ops.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2056,6 +2056,18 @@
func : qr
backward : qr_grad

- op : read_file
args : (str filename = "", DataType dtype = DataType::UINT8, Place place = CPUPlace())
output : Tensor(out)
infer_meta :
func : ReadFileInferMeta
param : [filename, dtype]
kernel :
func : read_file
param : [filename, dtype]
data_type : dtype
backend : place

Copy link
Contributor Author

@zeroRains zeroRains Nov 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个算子参数很少,只有一个filename的attr和一个输出out,cmake要求必须含有dtype和place两个参数才能编译。感觉我这样写应该没有问题,但是在进行单测时,竟然不进到read_file_kernel里。。。

这个Segmentation Fault应该是没找到这个kernel才导致越界的,参数这么简单的kernel不应该找不到啊。

可以麻烦老师看看是哪里写得不合理么~

a9929edd184eb53b1ffa9b1e0f76af2

- op : real
args : (Tensor x)
output : Tensor (out)
Expand Down
8 changes: 8 additions & 0 deletions paddle/phi/infermeta/nullary.cc
Original file line number Diff line number Diff line change
Expand Up @@ -312,4 +312,12 @@ void TriuIndicesInferMeta(
out->set_dims(out_dims);
out->set_dtype(dtype);
}

void ReadFileInferMeta(const std::string& filename,
DataType dtype,
MetaTensor* out) {
auto out_dims = std::vector<int>(1, -1);
out->set_dims(phi::make_ddim(out_dims));
}

} // namespace phi
5 changes: 5 additions & 0 deletions paddle/phi/infermeta/nullary.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,9 @@ void TrilIndicesInferMeta(

void TriuIndicesInferMeta(
int row, int col, int offset, DataType dtype, MetaTensor* out);

void ReadFileInferMeta(const std::string& filename,
DataType dtype,
MetaTensor* out);

} // namespace phi
48 changes: 48 additions & 0 deletions paddle/phi/kernels/read_file_kernel.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright (c) 2023 PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include <fstream>
#include <string>
#include <vector>

#include "paddle/phi/core/errors.h"
#include "paddle/phi/core/generator.h"
#include "paddle/phi/core/kernel_registry.h"

namespace phi {

template <typename T, typename Context>
void ReadFileKernel(const Context& dev_ctx,
const std::string& filename,
DataType dtype UNUSED,
DenseTensor* out) {
std::cout << "_______________________________________________________________"
"_______________"
<< std::endl;
std::ifstream input(filename.c_str(),
std::ios::in | std::ios::binary | std::ios::ate);
std::streamsize file_size = input.tellg();

input.seekg(0, std::ios::beg);

out->Resize({file_size});
std::cout << file_size << "__________________" << std::endl;
uint8_t* data = dev_ctx.template Alloc<T>(out);
input.read(reinterpret_cast<char*>(data), file_size);
}
} // namespace phi

PD_REGISTER_KERNEL(read_file, CPU, ALL_LAYOUT, phi::ReadFileKernel, uint8_t) {
kernel->OutputAt(0).SetDataType(phi::DataType::UINT8);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个看起来只有cpu的kernel,建议按照phi规范将该文件挪到phi/kernels/cpu目录下

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done