11#ifndef __AXPY_H__
22#define __AXPY_H__
33
4- #include " ../../../utils.h"
54#include " ../../operator.h"
6- #include " ../../tensor.h"
7- #include " infiniop/ops/axpy.h"
5+ #include " info.h"
86
97#define DESCRIPTOR (NAMESPACE ) \
108 \
4846 }; \
4947 }
5048
51- class AxpyInfo {
52- private:
53- size_t _size;
54- ptrdiff_t _incx;
55- ptrdiff_t _incy;
56- infiniDtype_t _dtype;
57-
58- AxpyInfo (size_t size,
59- ptrdiff_t incx,
60- ptrdiff_t incy,
61- infiniDtype_t dtype)
62- : _size(size), _incx(incx), _incy(incy), _dtype(dtype) {}
63-
64- public:
65- inline size_t getSize () const { return _size; }
66- inline ptrdiff_t getIncx () const { return _incx; }
67- inline ptrdiff_t getIncy () const { return _incy; }
68- inline infiniDtype_t getDtype () const { return _dtype; }
69-
70- using ResultType = utils::Result<AxpyInfo>;
71-
72- static ResultType createAxpyInfo (
73- infiniopTensorDescriptor_t alpha_desc,
74- infiniopTensorDescriptor_t x_desc,
75- infiniopTensorDescriptor_t y_desc) {
76-
77- CHECK_OR_RETURN (alpha_desc != nullptr , INFINI_STATUS_NULL_POINTER );
78- CHECK_OR_RETURN (x_desc != nullptr , INFINI_STATUS_NULL_POINTER );
79- CHECK_OR_RETURN (y_desc != nullptr , INFINI_STATUS_NULL_POINTER );
80-
81- auto dtype = x_desc->dtype ();
82-
83- CHECK_OR_RETURN (alpha_desc->dtype () == dtype, INFINI_STATUS_BAD_TENSOR_DTYPE );
84- CHECK_OR_RETURN (x_desc->dtype () == dtype, INFINI_STATUS_BAD_TENSOR_DTYPE );
85- CHECK_DTYPE (dtype, INFINI_DTYPE_F16 , INFINI_DTYPE_BF16 , INFINI_DTYPE_F32 , INFINI_DTYPE_F64 );
86-
87- CHECK_OR_RETURN (alpha_desc->numel () == 1 , INFINI_STATUS_BAD_TENSOR_SHAPE );
88- CHECK_OR_RETURN (x_desc->ndim () == 1 , INFINI_STATUS_BAD_TENSOR_SHAPE );
89- CHECK_OR_RETURN (y_desc->ndim () == 1 , INFINI_STATUS_BAD_TENSOR_SHAPE );
90- CHECK_OR_RETURN (x_desc->numel () == y_desc->numel (), INFINI_STATUS_BAD_TENSOR_SHAPE );
91-
92- auto size = x_desc->numel ();
93- auto incx = x_desc->stride (0 );
94- auto incy = y_desc->stride (0 );
95-
96- AxpyInfo info (size, incx, incy, dtype);
97- return ResultType (std::move (info));
98- }
99- };
100-
10149#endif // __AXPY_H__
0 commit comments