|
| 1 | +#include "erf_cpu.h" |
| 2 | + |
| 3 | +namespace op::erf::cpu { |
| 4 | + |
| 5 | +Descriptor::~Descriptor() = default; |
| 6 | + |
| 7 | +infiniStatus_t Descriptor::create( |
| 8 | + infiniopHandle_t handle_, |
| 9 | + Descriptor **desc_ptr, |
| 10 | + infiniopTensorDescriptor_t out_desc, |
| 11 | + std::vector<infiniopTensorDescriptor_t> input_desc_vec) { |
| 12 | + |
| 13 | + auto handle = reinterpret_cast<device::cpu::Handle *>(handle_); |
| 14 | + auto dtype = out_desc->dtype(); |
| 15 | + |
| 16 | + const auto &input_desc = input_desc_vec.at(0); |
| 17 | + const auto &output_shape = out_desc->shape(); |
| 18 | + const auto &input_shape = input_desc->shape(); |
| 19 | + |
| 20 | + CHECK_DTYPE(dtype, INFINI_DTYPE_BF16, INFINI_DTYPE_F16, INFINI_DTYPE_F32, INFINI_DTYPE_F64); |
| 21 | + |
| 22 | + CHECK_SAME_SHAPE(output_shape, input_shape); |
| 23 | + |
| 24 | + CREATE_ELEMENTWISE_CPU_DESCRIPTOR(handle, dtype, out_desc, input_desc_vec); |
| 25 | + |
| 26 | + return INFINI_STATUS_SUCCESS; |
| 27 | +} |
| 28 | + |
| 29 | +infiniStatus_t Descriptor::calculate( |
| 30 | + void *workspace, |
| 31 | + size_t workspace_size, |
| 32 | + void *output, |
| 33 | + std::vector<const void *> inputs, |
| 34 | + void *stream) const { |
| 35 | + |
| 36 | + switch (_dtype) { |
| 37 | + case INFINI_DTYPE_BF16: |
| 38 | + return _device_info->calculate<ErfOp, bf16_t>(_info, output, inputs, stream); |
| 39 | + case INFINI_DTYPE_F16: |
| 40 | + return _device_info->calculate<ErfOp, fp16_t>(_info, output, inputs, stream); |
| 41 | + case INFINI_DTYPE_F32: |
| 42 | + return _device_info->calculate<ErfOp, float>(_info, output, inputs, stream); |
| 43 | + case INFINI_DTYPE_F64: |
| 44 | + return _device_info->calculate<ErfOp, double>(_info, output, inputs, stream); |
| 45 | + default: |
| 46 | + return INFINI_STATUS_BAD_TENSOR_DTYPE; |
| 47 | + } |
| 48 | + |
| 49 | + return INFINI_STATUS_SUCCESS; |
| 50 | +} |
| 51 | + |
| 52 | +} // namespace op::erf::cpu |
0 commit comments