Skip to content
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

[Custom Op] New custom operator extension mechanism #30690

Merged
merged 39 commits into from
Feb 10, 2021
Merged
Show file tree
Hide file tree
Changes from 37 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
654b1c6
initial commit: simple demo
chenwhql Jan 25, 2021
de4914f
polish copyright format
chenwhql Jan 25, 2021
fdbe86b
add grap op simple demo
chenwhql Jan 26, 2021
870cf63
adapt uncertain number of argument
chenwhql Jan 27, 2021
9f80d3c
change trait marco name
chenwhql Jan 28, 2021
8395c28
add place & dtype support for add kernel
chenwhql Jan 28, 2021
0cd74f9
add dispath and infershape func
chenwhql Feb 2, 2021
976e70a
poish code & add notes
chenwhql Feb 2, 2021
5f355fc
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
chenwhql Feb 2, 2021
d1d0ba7
add dynamic_loader dep for paddle_framework
chenwhql Feb 2, 2021
7d6a187
add new custom op test dir
chenwhql Feb 3, 2021
b085762
Merge branch 'extension/new_custom_op' of https://github.com/chenwhql…
chenwhql Feb 3, 2021
a38b373
polish impl details
chenwhql Feb 3, 2021
44878a4
merge develop, resolve conflict
chenwhql Feb 3, 2021
ef52fb1
add unittest for new custom op
chenwhql Feb 3, 2021
9d4c964
fix failed unittest
chenwhql Feb 4, 2021
15a86da
Costum op (#1)
JiabinYang Feb 4, 2021
4b6649f
Remove ShareData from user && Change CustomTensor to Tensor && Suppor…
JiabinYang Feb 5, 2021
ffdb824
refactor register design & add test
chenwhql Feb 7, 2021
41aadfe
change op_funtion to op_meta_info
chenwhql Feb 7, 2021
82bfa1b
split op meta info into .h and .cc
chenwhql Feb 7, 2021
005f928
move get methods into friend class
chenwhql Feb 7, 2021
0859385
move OpMetaInfoHelper into framework space
chenwhql Feb 7, 2021
780c56a
move CustomTensorUtils into framework space
chenwhql Feb 7, 2021
9bcc048
change pybind api name
chenwhql Feb 7, 2021
8f6452f
move PD C API into op meta info
chenwhql Feb 7, 2021
cf20f1d
add register custom op api
chenwhql Feb 8, 2021
6892ef5
remove inference cmake change
chenwhql Feb 8, 2021
f5c639d
refactor copy to api && change Reshape to lowercase && support more d…
JiabinYang Feb 8, 2021
3ea5ca0
Merge branch 'extension/new_custom_op' of https://github.com/chenwhql…
chenwhql Feb 8, 2021
8dc6c94
polish detail & error message
chenwhql Feb 8, 2021
c174345
polish test details
chenwhql Feb 8, 2021
e5cc53b
Add cast api && Change copy related api to copy_to && add more test (#4)
JiabinYang Feb 8, 2021
222ad9c
resolve conflict
chenwhql Feb 8, 2021
44811a0
fix uint8 type error
chenwhql Feb 8, 2021
85d7b2c
fix lost uint8 type error
chenwhql Feb 8, 2021
0c90069
add test for coverage
chenwhql Feb 9, 2021
e24aba2
polish details by reviewer comments
chenwhql Feb 9, 2021
5d0088d
add prefix for DISABLE_COPY_AND_ASSIGN
chenwhql Feb 9, 2021
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
18 changes: 18 additions & 0 deletions paddle/extension.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/* Copyright (c) 2021 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. */

#pragma once

// All paddle apis in C++ frontend
#include "paddle/fluid/extension/include/all.h"
Copy link
Contributor

Choose a reason for hiding this comment

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

这个头文件看起来会引用一些 platform 的内部头文件,在预测发布时,需要评估下这样暴露头文件是否会有问题

Copy link
Contributor Author

Choose a reason for hiding this comment

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

这里暴露的头文件是paddle底层的数据类型,包括:

#include "paddle/fluid/platform/bfloat16.h"
#include "paddle/fluid/platform/complex128.h"
#include "paddle/fluid/platform/complex64.h"
#include "paddle/fluid/platform/float16.h"

为了支持完备的自定义Op,Op支持的数据类型是需要暴露的

如线下讨论的,这里可以按如下两种方式解决:

  1. 预测接入这几个底层头文件,但这几个底层头文件也需要明确,不能再include其他框架内的上层头文件了(可以保证);
  2. 预测通过宏控制暂时不支持这些数据类型,仅在训练时使用。

Copy link
Contributor

Choose a reason for hiding this comment

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

25 changes: 25 additions & 0 deletions paddle/fluid/extension/include/all.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/* Copyright (c) 2021 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. */

#pragma once

#if !defined(_MSC_VER) && __cplusplus < 199711L
#error C++11 or later compatible compiler is required to use Paddle.
#endif

#include "paddle/fluid/extension/include/dispatch.h"
#include "paddle/fluid/extension/include/dtype.h"
#include "paddle/fluid/extension/include/op_meta_info.h"
#include "paddle/fluid/extension/include/place.h"
#include "paddle/fluid/extension/include/tensor.h"
46 changes: 46 additions & 0 deletions paddle/fluid/extension/include/dispatch.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/* Copyright (c) 2021 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. */

#pragma once

#include "paddle/fluid/extension/include/dtype.h"

namespace paddle {

#define PD_PRIVATE_CASE_TYPE_USING_HINT(NAME, enum_type, type, HINT, ...) \
case enum_type: { \
using HINT = type; \
__VA_ARGS__(); \
break; \
}

#define PD_PRIVATE_CASE_TYPE(NAME, enum_type, type, ...) \
PD_PRIVATE_CASE_TYPE_USING_HINT(NAME, enum_type, type, data_t, __VA_ARGS__)

#define PD_DISPATCH_FLOATING_TYPES(TYPE, NAME, ...) \
[&] { \
const auto& dtype = TYPE; \
switch (dtype) { \
PD_PRIVATE_CASE_TYPE(NAME, ::paddle::DataType::FLOAT32, float, \
__VA_ARGS__) \
PD_PRIVATE_CASE_TYPE(NAME, ::paddle::DataType::FLOAT64, double, \
__VA_ARGS__) \
default: \
throw std::runtime_error("function not implemented for this type."); \
} \
}()

// TODD(chenweihang): implement other DISPATH macros in next PR

} // namespace paddle
39 changes: 39 additions & 0 deletions paddle/fluid/extension/include/dtype.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/* Copyright (c) 2021 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. */

#pragma once
#include "paddle/fluid/platform/bfloat16.h"
#include "paddle/fluid/platform/complex128.h"
#include "paddle/fluid/platform/complex64.h"
#include "paddle/fluid/platform/float16.h"

namespace paddle {

enum DataType {
FLOAT32,
FLOAT64,
BFLOAT16,
COMPLEX128,
COMPLEX64,
FLOAT16,
INT64,
INT32,
INT16,
UINT8,
INT8,
BOOL,
// TODO(JiabinYang) support more data types if needed.
};

} // namespace paddle
Loading