|
| 1 | +#include "../../../elementwise/nvidia/elementwise_nvidia.cuh" |
| 2 | + |
| 3 | +#include "../cuda/kernel.cuh" |
| 4 | +#include "div_nvidia.cuh" |
| 5 | + |
| 6 | +namespace op::div::nvidia { |
| 7 | + |
| 8 | +Descriptor::~Descriptor() = default; |
| 9 | + |
| 10 | +infiniStatus_t Descriptor::create( |
| 11 | + infiniopHandle_t handle_, |
| 12 | + Descriptor **desc_ptr, |
| 13 | + infiniopTensorDescriptor_t out_desc, |
| 14 | + std::vector<infiniopTensorDescriptor_t> input_desc_vec) { |
| 15 | + |
| 16 | + auto handle = reinterpret_cast<device::nvidia::Handle *>(handle_); |
| 17 | + auto dtype = out_desc->dtype(); |
| 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 | + CHECK_DTYPE(dtype, INFINI_DTYPE_F16, INFINI_DTYPE_F32); |
| 26 | + |
| 27 | + CHECK_SAME_SHAPE(c_shape, a_shape, b_shape); |
| 28 | + |
| 29 | + // create CUDA elementwise descriptor |
| 30 | + CREATE_ELEMENTWISE_CUDA_DESCRIPTOR(handle, dtype, out_desc, input_desc_vec) |
| 31 | + |
| 32 | + return INFINI_STATUS_SUCCESS; |
| 33 | +} |
| 34 | + |
| 35 | +infiniStatus_t Descriptor::calculate( |
| 36 | + void *workspace, |
| 37 | + size_t workspace_size, |
| 38 | + void *output, |
| 39 | + std::vector<const void *> inputs, |
| 40 | + void *stream) const { |
| 41 | + |
| 42 | + if (workspace_size < _workspace_size) { |
| 43 | + return INFINI_STATUS_INSUFFICIENT_WORKSPACE; |
| 44 | + } |
| 45 | + |
| 46 | + switch (_dtype) { |
| 47 | + case INFINI_DTYPE_F16: |
| 48 | + return _device_info->calculate<256, cuda::DivOp, half>(_info, workspace, output, inputs, stream); |
| 49 | + case INFINI_DTYPE_F32: |
| 50 | + return _device_info->calculate<256, cuda::DivOp, float>(_info, workspace, output, inputs, stream); |
| 51 | + default: |
| 52 | + return INFINI_STATUS_BAD_TENSOR_DTYPE; |
| 53 | + } |
| 54 | + |
| 55 | + return INFINI_STATUS_SUCCESS; |
| 56 | +} |
| 57 | +} // namespace op::div::nvidia |
0 commit comments