|
| 1 | +#include "equal_metax.h" |
| 2 | + |
| 3 | +#include "../../../elementwise/metax/elementwise_metax.h" |
| 4 | + |
| 5 | +#include "../cuda/kernel.cuh" |
| 6 | + |
| 7 | +namespace op::equal::metax { |
| 8 | + |
| 9 | +Descriptor::~Descriptor() = default; |
| 10 | + |
| 11 | +infiniStatus_t Descriptor::create( |
| 12 | + infiniopHandle_t handle_, |
| 13 | + Descriptor **desc_ptr, |
| 14 | + infiniopTensorDescriptor_t out_desc, |
| 15 | + std::vector<infiniopTensorDescriptor_t> input_desc_vec) { |
| 16 | + |
| 17 | + auto handle = reinterpret_cast<device::metax::Handle *>(handle_); |
| 18 | + |
| 19 | + const auto &a_desc = input_desc_vec.at(0); |
| 20 | + const auto &b_desc = input_desc_vec.at(1); |
| 21 | + const auto &c_shape = out_desc->shape(); |
| 22 | + const auto &a_shape = a_desc->shape(); |
| 23 | + const auto &b_shape = b_desc->shape(); |
| 24 | + |
| 25 | + auto dtype = a_desc->dtype(); |
| 26 | + |
| 27 | + CHECK_DTYPE(dtype, INFINI_DTYPE_BOOL, INFINI_DTYPE_I8, INFINI_DTYPE_I16, INFINI_DTYPE_I32, INFINI_DTYPE_I64, INFINI_DTYPE_BF16, INFINI_DTYPE_F16, INFINI_DTYPE_F32, INFINI_DTYPE_F64); |
| 28 | + |
| 29 | + CHECK_SAME_SHAPE(c_shape, a_shape, b_shape); |
| 30 | + |
| 31 | + // create METAX elementwise descriptor |
| 32 | + CREATE_ELEMENTWISE_METAX_DESCRIPTOR(handle, dtype, out_desc, input_desc_vec) |
| 33 | + |
| 34 | + return INFINI_STATUS_SUCCESS; |
| 35 | +} |
| 36 | + |
| 37 | +infiniStatus_t Descriptor::calculate( |
| 38 | + void *workspace, |
| 39 | + size_t workspace_size, |
| 40 | + void *output, |
| 41 | + std::vector<const void *> inputs, |
| 42 | + void *stream) const { |
| 43 | + |
| 44 | + if (workspace_size < _workspace_size) { |
| 45 | + return INFINI_STATUS_INSUFFICIENT_WORKSPACE; |
| 46 | + } |
| 47 | + |
| 48 | + switch (_dtype) { |
| 49 | + case INFINI_DTYPE_BOOL: |
| 50 | + return _device_info->calculate<256, cuda::EqualOp, bool, bool, bool>(_info, workspace, output, inputs, stream); |
| 51 | + case INFINI_DTYPE_I8: |
| 52 | + return _device_info->calculate<256, cuda::EqualOp, bool, int8_t, int8_t>(_info, workspace, output, inputs, stream); |
| 53 | + case INFINI_DTYPE_I16: |
| 54 | + return _device_info->calculate<256, cuda::EqualOp, bool, int16_t, int16_t>(_info, workspace, output, inputs, stream); |
| 55 | + case INFINI_DTYPE_I32: |
| 56 | + return _device_info->calculate<256, cuda::EqualOp, bool, int32_t, int32_t>(_info, workspace, output, inputs, stream); |
| 57 | + case INFINI_DTYPE_I64: |
| 58 | + return _device_info->calculate<256, cuda::EqualOp, bool, int64_t, int64_t>(_info, workspace, output, inputs, stream); |
| 59 | + case INFINI_DTYPE_BF16: |
| 60 | + return _device_info->calculate<256, cuda::EqualOp, bool, cuda_bfloat16, cuda_bfloat16>(_info, workspace, output, inputs, stream); |
| 61 | + case INFINI_DTYPE_F16: |
| 62 | + return _device_info->calculate<256, cuda::EqualOp, bool, half, half>(_info, workspace, output, inputs, stream); |
| 63 | + case INFINI_DTYPE_F32: |
| 64 | + return _device_info->calculate<256, cuda::EqualOp, bool, float, float>(_info, workspace, output, inputs, stream); |
| 65 | + case INFINI_DTYPE_F64: |
| 66 | + return _device_info->calculate<256, cuda::EqualOp, bool, double, double>(_info, workspace, output, inputs, stream); |
| 67 | + default: |
| 68 | + return INFINI_STATUS_BAD_TENSOR_DTYPE; |
| 69 | + } |
| 70 | + |
| 71 | + return INFINI_STATUS_SUCCESS; |
| 72 | +} |
| 73 | +} // namespace op::equal::metax |
0 commit comments