Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
jerrrrry
infinicore
Commits
60ca4508
Unverified
Commit
60ca4508
authored
Aug 08, 2025
by
PanZezhong1725
Committed by
GitHub
Aug 08, 2025
Browse files
Merge pull request #350 from InfiniTensor/p800-add
issue/349 P800 add
parents
72c4dc7c
c89f1b77
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
114 additions
and
0 deletions
+114
-0
src/infiniop/ops/add/kunlun/add_kunlun.h
src/infiniop/ops/add/kunlun/add_kunlun.h
+8
-0
src/infiniop/ops/add/kunlun/add_kunlun.xpu
src/infiniop/ops/add/kunlun/add_kunlun.xpu
+67
-0
src/infiniop/ops/add/kunlun/kernel.h
src/infiniop/ops/add/kunlun/kernel.h
+24
-0
src/infiniop/ops/add/operator.cc
src/infiniop/ops/add/operator.cc
+15
-0
No files found.
src/infiniop/ops/add/kunlun/add_kunlun.h
0 → 100644
View file @
60ca4508
#ifndef __ADD_KUNLUN_API_H__
#define __ADD_KUNLUN_API_H__
#include "../../../elementwise/kunlun/elementwise_kunlun_api.h"
ELEMENTWISE_DESCRIPTOR
(
add
,
kunlun
)
#endif // __ADD_KUNLUN_API_H__
src/infiniop/ops/add/kunlun/add_kunlun.xpu
0 → 100644
View file @
60ca4508
#include "../../../elementwise/kunlun/elementwise_kunlun.h"
#include "add_kunlun.h"
#include "kernel.h"
namespace op::elementwise::kunlun {
using AddOp = op::add::kunlun::AddOp;
INSTANTIATE_ELEMENTWISE_KERNEL(AddOp::num_inputs, AddOp, float);
INSTANTIATE_ELEMENTWISE_KERNEL(AddOp::num_inputs, AddOp, half);
INSTANTIATE_ELEMENTWISE_KERNEL(AddOp::num_inputs, AddOp, bfloat16_t);
} // namespace op::elementwise::kunlun
namespace op::add::kunlun {
Descriptor::~Descriptor() = default;
infiniStatus_t Descriptor::create(
infiniopHandle_t handle_,
Descriptor **desc_ptr,
infiniopTensorDescriptor_t out_desc,
std::vector<infiniopTensorDescriptor_t> input_desc_vec) {
auto handle = reinterpret_cast<device::kunlun::Handle *>(handle_);
auto dtype = out_desc->dtype();
const auto &a_desc = input_desc_vec.at(0);
const auto &b_desc = input_desc_vec.at(1);
const auto &c_shape = out_desc->shape();
const auto &a_shape = a_desc->shape();
const auto &b_shape = b_desc->shape();
CHECK_DTYPE(dtype, INFINI_DTYPE_F16, INFINI_DTYPE_F32, INFINI_DTYPE_BF16);
CHECK_SAME_SHAPE(c_shape, a_shape, b_shape);
// create KUNLUN elementwise descriptor
CREATE_ELEMENTWISE_KUNLUN_DESCRIPTOR(handle, dtype, out_desc, input_desc_vec)
return INFINI_STATUS_SUCCESS;
}
infiniStatus_t Descriptor::calculate(
void *workspace,
size_t workspace_size,
void *output,
std::vector<const void *> inputs,
void *stream) const {
if (workspace_size < _workspace_size) {
return INFINI_STATUS_INSUFFICIENT_WORKSPACE;
}
switch (_dtype) {
case INFINI_DTYPE_F16:
return _device_info->calculate<8, AddOp, half>(_info, workspace, output, inputs, stream);
case INFINI_DTYPE_BF16:
return _device_info->calculate<8, AddOp, bfloat16_t>(_info, workspace, output, inputs, stream);
case INFINI_DTYPE_F32:
return _device_info->calculate<8, AddOp, float>(_info, workspace, output, inputs, stream);
default:
return INFINI_STATUS_BAD_TENSOR_DTYPE;
}
return INFINI_STATUS_SUCCESS;
}
} // namespace op::add::kunlun
src/infiniop/ops/add/kunlun/kernel.h
0 → 100644
View file @
60ca4508
#ifndef __ADD_KUNLUN_KERNEL_H__
#define __ADD_KUNLUN_KERNEL_H__
namespace
op
::
add
::
kunlun
{
typedef
struct
AddOp
{
public:
static
constexpr
int
num_inputs
=
2
;
template
<
typename
T
>
inline
__device__
T
operator
()(
const
T
*
inputs
)
const
{
T
a
=
inputs
[
0
];
T
b
=
inputs
[
1
];
return
a
+
b
;
}
// bfloat16 特化版本(使用 float 计算精度)
inline
__device__
bfloat16_t
operator
()(
const
bfloat16_t
*
inputs
)
const
{
float
a_f
=
__bfloat162float
(
inputs
[
0
]);
float
b_f
=
__bfloat162float
(
inputs
[
1
]);
return
__float2bfloat16
(
a_f
+
b_f
);
}
}
AddOp
;
}
// namespace op::add::kunlun
#endif // __ADD_KUNLUN_KERNEL_H__
src/infiniop/ops/add/operator.cc
View file @
60ca4508
...
@@ -11,6 +11,9 @@
...
@@ -11,6 +11,9 @@
#ifdef ENABLE_METAX_API
#ifdef ENABLE_METAX_API
#include "metax/add_metax.h"
#include "metax/add_metax.h"
#endif
#endif
#ifdef ENABLE_KUNLUN_API
#include "kunlun/add_kunlun.h"
#endif
__C
infiniStatus_t
infiniopCreateAddDescriptor
(
__C
infiniStatus_t
infiniopCreateAddDescriptor
(
infiniopHandle_t
handle
,
infiniopHandle_t
handle
,
...
@@ -42,6 +45,9 @@ __C infiniStatus_t infiniopCreateAddDescriptor(
...
@@ -42,6 +45,9 @@ __C infiniStatus_t infiniopCreateAddDescriptor(
#ifdef ENABLE_METAX_API
#ifdef ENABLE_METAX_API
CREATE
(
INFINI_DEVICE_METAX
,
metax
);
CREATE
(
INFINI_DEVICE_METAX
,
metax
);
#endif
#endif
#ifdef ENABLE_KUNLUN_API
CREATE
(
INFINI_DEVICE_KUNLUN
,
kunlun
);
#endif
default:
default:
return
INFINI_STATUS_DEVICE_TYPE_NOT_SUPPORTED
;
return
INFINI_STATUS_DEVICE_TYPE_NOT_SUPPORTED
;
...
@@ -69,6 +75,9 @@ __C infiniStatus_t infiniopGetAddWorkspaceSize(infiniopAddDescriptor_t desc, siz
...
@@ -69,6 +75,9 @@ __C infiniStatus_t infiniopGetAddWorkspaceSize(infiniopAddDescriptor_t desc, siz
#endif
#endif
#ifdef ENABLE_METAX_API
#ifdef ENABLE_METAX_API
GET
(
INFINI_DEVICE_METAX
,
metax
);
GET
(
INFINI_DEVICE_METAX
,
metax
);
#endif
#ifdef ENABLE_KUNLUN_API
GET
(
INFINI_DEVICE_KUNLUN
,
kunlun
);
#endif
#endif
default:
default:
return
INFINI_STATUS_DEVICE_TYPE_NOT_SUPPORTED
;
return
INFINI_STATUS_DEVICE_TYPE_NOT_SUPPORTED
;
...
@@ -106,6 +115,9 @@ __C infiniStatus_t infiniopAdd(
...
@@ -106,6 +115,9 @@ __C infiniStatus_t infiniopAdd(
#ifdef ENABLE_METAX_API
#ifdef ENABLE_METAX_API
CALCULATE
(
INFINI_DEVICE_METAX
,
metax
);
CALCULATE
(
INFINI_DEVICE_METAX
,
metax
);
#endif
#endif
#ifdef ENABLE_KUNLUN_API
CALCULATE
(
INFINI_DEVICE_KUNLUN
,
kunlun
);
#endif
default:
default:
return
INFINI_STATUS_DEVICE_TYPE_NOT_SUPPORTED
;
return
INFINI_STATUS_DEVICE_TYPE_NOT_SUPPORTED
;
...
@@ -136,6 +148,9 @@ infiniopDestroyAddDescriptor(infiniopAddDescriptor_t desc) {
...
@@ -136,6 +148,9 @@ infiniopDestroyAddDescriptor(infiniopAddDescriptor_t desc) {
#ifdef ENABLE_METAX_API
#ifdef ENABLE_METAX_API
DELETE
(
INFINI_DEVICE_METAX
,
metax
);
DELETE
(
INFINI_DEVICE_METAX
,
metax
);
#endif
#endif
#ifdef ENABLE_KUNLUN_API
DELETE
(
INFINI_DEVICE_KUNLUN
,
kunlun
);
#endif
default:
default:
return
INFINI_STATUS_DEVICE_TYPE_NOT_SUPPORTED
;
return
INFINI_STATUS_DEVICE_TYPE_NOT_SUPPORTED
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment