forked from PaddlePaddle/Paddle
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CustomKernel] add custom kernel c api (PaddlePaddle#42986)
* [CustomKernel] add custom kernel c api * update * update * fix unable to export capi Co-authored-by: ronny1996 <524019753@qq.com>
- Loading branch information
Showing
40 changed files
with
3,910 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
add_subdirectory(lib) | ||
cc_library( | ||
phi_capi | ||
SRCS all.cc | ||
DEPS phi_c_data_type | ||
phi_c_device_context | ||
phi_c_int_array | ||
phi_c_kernel_context | ||
phi_c_kernel_factory | ||
phi_c_kernel_registry | ||
phi_c_place | ||
phi_c_scalar | ||
phi_c_tensor) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* 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. */ | ||
|
||
#include "paddle/phi/capi/all.h" | ||
|
||
namespace paddle { | ||
namespace capi {} // namespace capi | ||
} // namespace paddle |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright (c) 2022 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(_WIN32) && !defined(__APPLE__) | ||
|
||
#include "paddle/phi/capi/include/c_data_type.h" | ||
#include "paddle/phi/capi/include/c_device_context.h" | ||
#include "paddle/phi/capi/include/c_int_array.h" | ||
#include "paddle/phi/capi/include/c_kernel_context.h" | ||
#include "paddle/phi/capi/include/c_kernel_factory.h" | ||
#include "paddle/phi/capi/include/c_kernel_registry.h" | ||
#include "paddle/phi/capi/include/c_place.h" | ||
#include "paddle/phi/capi/include/c_scalar.h" | ||
#include "paddle/phi/capi/include/c_tensor.h" | ||
#include "paddle/phi/capi/include/data_type.h" | ||
#include "paddle/phi/capi/include/kernel_registry.h" | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright (c) 2022 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(_WIN32) && !defined(__APPLE__) | ||
|
||
#include "paddle/phi/capi/include/common.h" | ||
|
||
PD_DECLARE_CAPI(data_type); | ||
PD_DECLARE_CAPI(device_context); | ||
PD_DECLARE_CAPI(int_array); | ||
PD_DECLARE_CAPI(kernel_context); | ||
PD_DECLARE_CAPI(kernel_factory); | ||
PD_DECLARE_CAPI(kernel_registry); | ||
PD_DECLARE_CAPI(place); | ||
PD_DECLARE_CAPI(scalar); | ||
PD_DECLARE_CAPI(tensor); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Copyright (c) 2022 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(_WIN32) && !defined(__APPLE__) | ||
|
||
#include <cstdint> | ||
|
||
#include "paddle/phi/backends/device_ext.h" | ||
#include "paddle/phi/common/bfloat16.h" | ||
#include "paddle/phi/common/complex.h" | ||
#include "paddle/phi/common/float16.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
typedef C_Status PD_Status; | ||
|
||
typedef C_DataType PD_DataType; | ||
|
||
typedef C_DataLayout PD_DataLayout; | ||
|
||
typedef struct { | ||
size_t size; | ||
void *data; | ||
} PD_List; | ||
|
||
void PD_DeletePointerList(PD_List list); | ||
|
||
void PD_DeleteUInt8List(PD_List list); | ||
|
||
void PD_DeleteInt64List(PD_List list); | ||
|
||
void PD_DeleteInt32List(PD_List list); | ||
|
||
void PD_DeleteFloat64List(PD_List list); | ||
|
||
void PD_DeleteFloat32List(PD_List list); | ||
|
||
#ifdef __cplusplus | ||
} // extern "C" | ||
#endif | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright (c) 2022 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(_WIN32) && !defined(__APPLE__) | ||
|
||
#include "paddle/phi/capi/include/c_data_type.h" | ||
#include "paddle/phi/capi/include/c_tensor.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
typedef struct PD_DeviceContext PD_DeviceContext; | ||
|
||
typedef C_Stream PD_Stream; | ||
|
||
PD_Stream PD_DeviceContextGetStream(const PD_DeviceContext *ctx, | ||
PD_Status *status); | ||
|
||
void *PD_DeviceContextAllocateTensor(const PD_DeviceContext *ctx, | ||
PD_Tensor *tensor, | ||
size_t size, | ||
PD_DataType dtype, | ||
PD_Status *status); | ||
|
||
#ifdef __cplusplus | ||
} // extern "C" | ||
#endif | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright (c) 2022 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(_WIN32) && !defined(__APPLE__) | ||
|
||
#include "paddle/phi/capi/include/c_data_type.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
typedef struct PD_IntArray PD_IntArray; | ||
|
||
PD_List PD_IntArrayGetDataPointer(PD_IntArray *int_array); | ||
|
||
size_t PD_IntArrayGetElementCount(PD_IntArray *int_array); | ||
|
||
#ifdef __cplusplus | ||
} // extern "C" | ||
#endif | ||
#endif |
Oops, something went wrong.