-
Notifications
You must be signed in to change notification settings - Fork 5.9k
【Hackathon 5th No.112】move read_file to phi - part #59359
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
44de899
23d72c0
fd5f811
04f8301
2b3ff33
e4f06a2
ad30999
a349d33
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3402,6 +3402,10 @@ | |
outputs : | ||
out : Out | ||
|
||
- op: read_file | ||
outputs : | ||
out : Out | ||
|
||
- op: recv_v2 | ||
outputs : | ||
out : Out | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
||
|
||
- op : real | ||
args : (Tensor x) | ||
output : Tensor (out) | ||
|
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); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这个看起来只有cpu的kernel,建议按照phi规范将该文件挪到phi/kernels/cpu目录下 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
read_file不加到这个list里是会编译报错吗?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
好像不会,这就删掉