Skip to content

Commit 1f72968

Browse files
committed
Change name NPU_MAT to ASCEND_MAT
NPU is too generic and there are more than one NPU vendors. It's better to use ASCEND_MAT instead.
1 parent 981baad commit 1f72968

19 files changed

+328
-328
lines changed

modules/cannops/include/opencv2/cann.hpp

Lines changed: 52 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,16 @@ class AscendStream;
2828
//! @{
2929

3030
//===================================================================================
31-
// NpuMat
31+
// AscendMat
3232
//===================================================================================
3333

3434
/** @brief Base storage class for NPU memory with reference counting.
35-
* NpuMat class has a similar interface with Mat and NpuMat, and work on [Ascend
35+
* AscendMat class has a similar interface with Mat and AscendMat, and work on [Ascend
3636
* NPU](https://www.hiascend.com/) backend.
3737
* @sa Mat cuda::GpuMat
3838
*/
3939
class AscendStream;
40-
class CV_EXPORTS_W NpuMat
40+
class CV_EXPORTS_W AscendMat
4141
{
4242
public:
4343
class CV_EXPORTS_W Allocator
@@ -47,85 +47,85 @@ class CV_EXPORTS_W NpuMat
4747
// basic allocator
4848
virtual std::shared_ptr<uchar> allocate(size_t size) = 0;
4949
// allocator must fill data, step and refcount fields
50-
virtual bool allocate(NpuMat* mat, int rows, int cols, size_t elemSize) = 0;
50+
virtual bool allocate(AscendMat* mat, int rows, int cols, size_t elemSize) = 0;
5151
};
5252

5353
/**
54-
* @brief Create default allocator for NpuMat. This allocator alloc memory from device for
54+
* @brief Create default allocator for AscendMat. This allocator alloc memory from device for
5555
* specific size.
5656
*/
57-
CV_WRAP static NpuMat::Allocator* defaultAllocator();
57+
CV_WRAP static AscendMat::Allocator* defaultAllocator();
5858

5959
/**
60-
* @brief Set allocator for NpuMat.
60+
* @brief Set allocator for AscendMat.
6161
* @param allocator
6262
*/
63-
CV_WRAP static void setDefaultAllocator(NpuMat::Allocator* allocator);
63+
CV_WRAP static void setDefaultAllocator(AscendMat::Allocator* allocator);
6464

6565
//! default constructor
66-
CV_WRAP explicit NpuMat(NpuMat::Allocator* allocator_ = NpuMat::defaultAllocator());
66+
CV_WRAP explicit AscendMat(AscendMat::Allocator* allocator_ = AscendMat::defaultAllocator());
6767

68-
//! constructs NpuMat of the specified size and type
69-
CV_WRAP NpuMat(int rows, int cols, int type,
70-
NpuMat::Allocator* allocator = NpuMat::defaultAllocator());
71-
//! constructs NpuMat of the specified size and type
72-
CV_WRAP NpuMat(Size size, int type, NpuMat::Allocator* allocator = NpuMat::defaultAllocator());
68+
//! constructs AscendMat of the specified size and type
69+
CV_WRAP AscendMat(int rows, int cols, int type,
70+
AscendMat::Allocator* allocator = AscendMat::defaultAllocator());
71+
//! constructs AscendMat of the specified size and type
72+
CV_WRAP AscendMat(Size size, int type, AscendMat::Allocator* allocator = AscendMat::defaultAllocator());
7373

74-
//! constructs NpuMat and fills it with the specified value s
75-
CV_WRAP NpuMat(int rows, int cols, int type, Scalar& s,
76-
NpuMat::Allocator* allocator = NpuMat::defaultAllocator());
77-
//! constructs NpuMat and fills it with the specified value s
78-
CV_WRAP NpuMat(Size size, int type, Scalar& s,
79-
NpuMat::Allocator* allocator = NpuMat::defaultAllocator());
74+
//! constructs AscendMat and fills it with the specified value s
75+
CV_WRAP AscendMat(int rows, int cols, int type, Scalar& s,
76+
AscendMat::Allocator* allocator = AscendMat::defaultAllocator());
77+
//! constructs AscendMat and fills it with the specified value s
78+
CV_WRAP AscendMat(Size size, int type, Scalar& s,
79+
AscendMat::Allocator* allocator = AscendMat::defaultAllocator());
8080

8181
//! copy constructor
82-
CV_WRAP NpuMat(const NpuMat& m);
82+
CV_WRAP AscendMat(const AscendMat& m);
8383

84-
//! constructs NpuMat by crop a certain area from another
85-
CV_WRAP NpuMat(InputArray _m, const Rect& roi);
86-
CV_WRAP NpuMat(InputArray _m, const Rect& roi, AscendStream& stream);
84+
//! constructs AscendMat by crop a certain area from another
85+
CV_WRAP AscendMat(InputArray _m, const Rect& roi);
86+
CV_WRAP AscendMat(InputArray _m, const Rect& roi, AscendStream& stream);
8787

88-
//! builds NpuMat from host memory (Blocking call)
89-
CV_WRAP explicit NpuMat(InputArray arr, AscendStream& stream,
90-
NpuMat::Allocator* allocator = NpuMat::defaultAllocator());
88+
//! builds AscendMat from host memory (Blocking call)
89+
CV_WRAP explicit AscendMat(InputArray arr, AscendStream& stream,
90+
AscendMat::Allocator* allocator = AscendMat::defaultAllocator());
9191

9292
//! assignment operators
93-
NpuMat& operator=(const NpuMat& m);
93+
AscendMat& operator=(const AscendMat& m);
9494

95-
//! sets some of the NpuMat elements to s (Blocking call)
96-
CV_WRAP NpuMat& setTo(const Scalar& s);
97-
//! sets some of the NpuMat elements to s (Non-Blocking call)
98-
CV_WRAP NpuMat& setTo(const Scalar& s, AscendStream& stream);
95+
//! sets some of the AscendMat elements to s (Blocking call)
96+
CV_WRAP AscendMat& setTo(const Scalar& s);
97+
//! sets some of the AscendMat elements to s (Non-Blocking call)
98+
CV_WRAP AscendMat& setTo(const Scalar& s, AscendStream& stream);
9999

100-
//! sets all of the NpuMat elements to float (Blocking call)
101-
CV_WRAP NpuMat& setTo(float sc);
100+
//! sets all of the AscendMat elements to float (Blocking call)
101+
CV_WRAP AscendMat& setTo(float sc);
102102

103-
//! sets all of the NpuMat elements to float (Non-Blocking call)
104-
CV_WRAP NpuMat& setTo(float sc, AscendStream& stream);
103+
//! sets all of the AscendMat elements to float (Non-Blocking call)
104+
CV_WRAP AscendMat& setTo(float sc, AscendStream& stream);
105105

106106
//! swaps with other smart pointer
107-
CV_WRAP void swap(NpuMat& mat);
107+
CV_WRAP void swap(AscendMat& mat);
108108

109-
//! allocates new NpuMat data unless the NpuMat already has specified size and type
109+
//! allocates new AscendMat data unless the AscendMat already has specified size and type
110110
CV_WRAP void create(int rows, int cols, int type);
111111

112-
//! upload host memory data to NpuMat (Blocking call)
112+
//! upload host memory data to AscendMat (Blocking call)
113113
CV_WRAP void upload(InputArray arr);
114-
//! upload host memory data to NpuMat (Non-Blocking call)
114+
//! upload host memory data to AscendMat (Non-Blocking call)
115115
CV_WRAP void upload(InputArray arr, AscendStream& stream);
116116

117-
//! download data from NpuMat to host (Blocking call)
117+
//! download data from AscendMat to host (Blocking call)
118118
CV_WRAP void download(OutputArray dst) const;
119-
//! download data from NpuMat to host (Non-Blocking call)
119+
//! download data from AscendMat to host (Non-Blocking call)
120120
CV_WRAP void download(OutputArray dst, AscendStream& stream) const;
121121

122-
//! converts NpuMat to another datatype (Blocking call)
123-
CV_WRAP void convertTo(CV_OUT NpuMat& dst, int rtype) const;
122+
//! converts AscendMat to another datatype (Blocking call)
123+
CV_WRAP void convertTo(CV_OUT AscendMat& dst, int rtype) const;
124124

125-
//! converts NpuMat to another datatype (Non-Blocking call)
126-
CV_WRAP void convertTo(CV_OUT NpuMat& dst, int rtype, AscendStream& stream) const;
125+
//! converts AscendMat to another datatype (Non-Blocking call)
126+
CV_WRAP void convertTo(CV_OUT AscendMat& dst, int rtype, AscendStream& stream) const;
127127

128-
//! returns true iff the NpuMat data is continuous
128+
//! returns true iff the AscendMat data is continuous
129129
//! (i.e. when there are no gaps between successive rows)
130130
CV_WRAP bool isContinuous() const;
131131

@@ -147,10 +147,10 @@ class CV_EXPORTS_W NpuMat
147147
//! returns step/elemSize1()
148148
CV_WRAP size_t step1() const;
149149

150-
//! returns NpuMat size : width == number of columns, height == number of rows
150+
//! returns AscendMat size : width == number of columns, height == number of rows
151151
CV_WRAP Size size() const;
152152

153-
//! returns true if NpuMat data is NULL
153+
//! returns true if AscendMat data is NULL
154154
CV_WRAP bool empty() const;
155155

156156
//! internal use method: updates the continuity flag
@@ -279,13 +279,13 @@ CV_EXPORTS_W AscendStream wrapStream(size_t AscendStreamAddress);
279279
//! @{
280280

281281
//! Get Ascend matrix object from Input array, upload matrix memory if need. (Non-Blocking call)
282-
NpuMat getInputMat(InputArray src, AscendStream& stream);
282+
AscendMat getInputMat(InputArray src, AscendStream& stream);
283283

284284
//! Get Ascend matrix object from Output array, upload matrix memory if need.
285-
NpuMat getOutputMat(OutputArray dst, int rows, int cols, int type, AscendStream& stream);
285+
AscendMat getOutputMat(OutputArray dst, int rows, int cols, int type, AscendStream& stream);
286286

287287
//! Sync output matrix to Output array, download matrix memory if need.
288-
void syncOutput(const NpuMat& dst, OutputArray _dst, AscendStream& stream);
288+
void syncOutput(const AscendMat& dst, OutputArray _dst, AscendStream& stream);
289289

290290
/**
291291
* @brief Choose Ascend npu device.

modules/cannops/include/opencv2/cann.inl.hpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,52 +11,52 @@ namespace cv
1111
{
1212
namespace cann
1313
{
14-
inline NpuMat::NpuMat(NpuMat::Allocator* allocator_)
14+
inline AscendMat::AscendMat(AscendMat::Allocator* allocator_)
1515
: flags(0), rows(0), cols(0), step(0), datastart(0), dataend(0),
1616
allocator(allocator_)
1717
{
1818
}
1919

20-
inline NpuMat::NpuMat(int rows_, int cols_, int type_, NpuMat::Allocator* allocator_)
20+
inline AscendMat::AscendMat(int rows_, int cols_, int type_, AscendMat::Allocator* allocator_)
2121
: flags(0), rows(0), cols(0), step(0), datastart(0), dataend(0),
2222
allocator(allocator_)
2323
{
2424
if (rows_ > 0 && cols_ > 0)
2525
create(rows_, cols_, type_);
2626
}
2727

28-
inline NpuMat::NpuMat(Size size_, int type_, NpuMat::Allocator* allocator_)
28+
inline AscendMat::AscendMat(Size size_, int type_, AscendMat::Allocator* allocator_)
2929
: flags(0), rows(0), cols(0), step(0), datastart(0), dataend(0),
3030
allocator(allocator_)
3131
{
3232
if (size_.height > 0 && size_.width > 0)
3333
create(size_.height, size_.width, type_);
3434
}
3535

36-
inline NpuMat::NpuMat(InputArray arr, AscendStream& stream, NpuMat::Allocator* allocator_)
36+
inline AscendMat::AscendMat(InputArray arr, AscendStream& stream, AscendMat::Allocator* allocator_)
3737
: flags(0), rows(0), cols(0), step(0), datastart(0), dataend(0),
3838
allocator(allocator_)
3939
{
4040
upload(arr, stream);
4141
}
4242

43-
inline NpuMat::NpuMat(const NpuMat& m)
43+
inline AscendMat::AscendMat(const AscendMat& m)
4444
: flags(m.flags), rows(m.rows), cols(m.cols), step(m.step), data(m.data),
4545
datastart(m.datastart), dataend(m.dataend), allocator(m.allocator)
4646
{}
4747

48-
inline NpuMat& NpuMat::operator=(const NpuMat& m)
48+
inline AscendMat& AscendMat::operator=(const AscendMat& m)
4949
{
5050
if (this != &m)
5151
{
52-
NpuMat temp(m);
52+
AscendMat temp(m);
5353
swap(temp);
5454
}
5555

5656
return *this;
5757
}
5858

59-
inline void NpuMat::swap(NpuMat& b)
59+
inline void AscendMat::swap(AscendMat& b)
6060
{
6161
std::swap(flags, b.flags);
6262
std::swap(rows, b.rows);
@@ -68,23 +68,23 @@ inline void NpuMat::swap(NpuMat& b)
6868
std::swap(allocator, b.allocator);
6969
}
7070

71-
inline bool NpuMat::isContinuous() const { return (flags & Mat::CONTINUOUS_FLAG) != 0; }
71+
inline bool AscendMat::isContinuous() const { return (flags & Mat::CONTINUOUS_FLAG) != 0; }
7272

73-
inline size_t NpuMat::elemSize() const { return CV_ELEM_SIZE(flags); }
73+
inline size_t AscendMat::elemSize() const { return CV_ELEM_SIZE(flags); }
7474

75-
inline size_t NpuMat::elemSize1() const { return CV_ELEM_SIZE1(flags); }
75+
inline size_t AscendMat::elemSize1() const { return CV_ELEM_SIZE1(flags); }
7676

77-
inline int NpuMat::type() const { return CV_MAT_TYPE(flags); }
77+
inline int AscendMat::type() const { return CV_MAT_TYPE(flags); }
7878

79-
inline int NpuMat::depth() const { return CV_MAT_DEPTH(flags); }
79+
inline int AscendMat::depth() const { return CV_MAT_DEPTH(flags); }
8080

81-
inline int NpuMat::channels() const { return CV_MAT_CN(flags); }
81+
inline int AscendMat::channels() const { return CV_MAT_CN(flags); }
8282

83-
inline size_t NpuMat::step1() const { return step / elemSize1(); }
83+
inline size_t AscendMat::step1() const { return step / elemSize1(); }
8484

85-
inline Size NpuMat::size() const { return Size(cols, rows); }
85+
inline Size AscendMat::size() const { return Size(cols, rows); }
8686

87-
inline bool NpuMat::empty() const { return data == 0; }
87+
inline bool AscendMat::empty() const { return data == 0; }
8888

8989
inline AscendStream::AscendStream(const Ptr<AscendStream::Impl>& impl) : impl_(impl) {}
9090

modules/cannops/include/opencv2/cann_call.hpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ struct AscendTensor
9191
aclDataType _dtype, std::string _name = "", aclFormat _format = ACL_FORMAT_ND)
9292
: name(_name), data(_data), dataSize(_dataSize), dims(_dims), dtype(_dtype),
9393
format(_format){};
94-
AscendTensor(const NpuMat& npuMat, std::string _name = "", aclFormat format = ACL_FORMAT_ND);
94+
AscendTensor(const AscendMat& ascendMat, std::string _name = "", aclFormat format = ACL_FORMAT_ND);
9595
};
9696
void aclrtMallocWarpper(void** data, size_t size);
9797
void aclrtFreeWarpper(void* data);
@@ -116,18 +116,18 @@ static std::vector<AclAttribute*> emptyattr;
116116
void callAscendOperator(const char* op, std::vector<AscendTensor>& srcs,
117117
std::vector<AscendTensor>& dsts, AscendStream& stream,
118118
std::vector<AclAttribute*>& attrs = emptyattr);
119-
void callAscendOperator(const NpuMat& src, NpuMat& dst, const char* op, AscendStream& stream,
119+
void callAscendOperator(const AscendMat& src, AscendMat& dst, const char* op, AscendStream& stream,
120120
std::vector<AclAttribute*>& attrs = emptyattr);
121-
void callAscendOperator(const NpuMat& src1, const NpuMat& src2, NpuMat& dst, const char* op,
121+
void callAscendOperator(const AscendMat& src1, const AscendMat& src2, AscendMat& dst, const char* op,
122122
AscendStream& stream, std::vector<AclAttribute*>& attrs = emptyattr);
123-
void callAscendOperator(const NpuMat* srcs, size_t srcCount, NpuMat& dst, const char* op,
123+
void callAscendOperator(const AscendMat* srcs, size_t srcCount, AscendMat& dst, const char* op,
124124
AscendStream& stream, std::vector<AclAttribute*>& attrs = emptyattr);
125-
void callAscendOperator(const NpuMat& src, const Scalar& sc, bool inv, NpuMat& dst, const char* op,
125+
void callAscendOperator(const AscendMat& src, const Scalar& sc, bool inv, AscendMat& dst, const char* op,
126126
AscendStream& stream, std::vector<AclAttribute*>& attrs = emptyattr);
127-
void callAscendOperator(const NpuMat& src, NpuMat* dsts, const size_t dstCount, const char* op,
127+
void callAscendOperator(const AscendMat& src, AscendMat* dsts, const size_t dstCount, const char* op,
128128
AscendStream& stream, std::vector<AclAttribute*>& attrs = emptyattr);
129129
std::shared_ptr<uchar> mallocAndUpload(void* data, size_t size, AscendStream& stream,
130-
NpuMat::Allocator* allocator = NpuMat::defaultAllocator());
130+
AscendMat::Allocator* allocator = AscendMat::defaultAllocator());
131131
} // namespace cann
132132
} // namespace cv
133133

modules/cannops/include/opencv2/cann_interface.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,10 +246,10 @@ CV_EXPORTS_W double threshold(InputArray src, OutputArray dst, double thresh, do
246246
247247
@sa cv::merge cv::cuda::merge
248248
*/
249-
CV_EXPORTS void merge(const NpuMat* src, size_t n, OutputArray dst,
249+
CV_EXPORTS void merge(const AscendMat* src, size_t n, OutputArray dst,
250250
AscendStream& stream = AscendStream::Null());
251251
/** @overload */
252-
CV_EXPORTS_W void merge(const std::vector<NpuMat>& src, OutputArray dst,
252+
CV_EXPORTS_W void merge(const std::vector<AscendMat>& src, OutputArray dst,
253253
AscendStream& stream = AscendStream::Null());
254254

255255
/** @brief Copies each plane of a multi-channel matrix into an array.
@@ -260,9 +260,9 @@ CV_EXPORTS_W void merge(const std::vector<NpuMat>& src, OutputArray dst,
260260
261261
@sa cv::split cv::cuda::split
262262
*/
263-
CV_EXPORTS void split(InputArray src, NpuMat* dst, AscendStream& stream = AscendStream::Null());
263+
CV_EXPORTS void split(InputArray src, AscendMat* dst, AscendStream& stream = AscendStream::Null());
264264
/** @overload */
265-
CV_EXPORTS_W void split(InputArray src, CV_OUT std::vector<NpuMat>& dst,
265+
CV_EXPORTS_W void split(InputArray src, CV_OUT std::vector<AscendMat>& dst,
266266
AscendStream& stream = AscendStream::Null());
267267

268268
/** @brief Transposes a matrix.

modules/cannops/include/opencv2/cann_private.hpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ namespace cv
1010
{
1111
namespace cann
1212
{
13-
void adds(const NpuMat& arr, float scalar, NpuMat& dst, AscendStream& stream);
14-
void muls(const NpuMat& arr, float scalar, NpuMat& dst, AscendStream& stream);
15-
void transData(const NpuMat& src, NpuMat& dst, const char* from, const char* to,
13+
void adds(const AscendMat& arr, float scalar, AscendMat& dst, AscendStream& stream);
14+
void muls(const AscendMat& arr, float scalar, AscendMat& dst, AscendStream& stream);
15+
void transData(const AscendMat& src, AscendMat& dst, const char* from, const char* to,
1616
AscendStream& stream);
17-
void transpose(const NpuMat& src, int64_t* perm, NpuMat& dst, AscendStream& stream);
18-
void flip(const NpuMat& src, std::vector<int32_t>& asixs, NpuMat& dst, AscendStream& stream);
19-
void merge(const NpuMat* src, size_t n, NpuMat& dst, AscendStream& stream);
20-
void split(const NpuMat& src, NpuMat* dst, AscendStream& stream);
17+
void transpose(const AscendMat& src, int64_t* perm, AscendMat& dst, AscendStream& stream);
18+
void flip(const AscendMat& src, std::vector<int32_t>& asixs, AscendMat& dst, AscendStream& stream);
19+
void merge(const AscendMat* src, size_t n, AscendMat& dst, AscendStream& stream);
20+
void split(const AscendMat& src, AscendMat* dst, AscendStream& stream);
2121

22-
double threshold(NpuMat& src, NpuMat& dst, double thresh, double maxval, int type,
22+
double threshold(AscendMat& src, AscendMat& dst, double thresh, double maxval, int type,
2323
AscendStream& stream);
2424
} // namespace cann
2525
} // namespace cv

modules/cannops/misc/python/pyopencv_cann.hpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,19 @@
99

1010
#include "opencv2/cann.hpp"
1111

12-
typedef std::vector<cann::NpuMat> vector_NpuMat;
13-
typedef cann::NpuMat::Allocator NpuMat_Allocator;
12+
typedef std::vector<cann::AscendMat> vector_AscendMat;
13+
typedef cann::AscendMat::Allocator AscendMat_Allocator;
1414

15-
CV_PY_TO_CLASS(cann::NpuMat);
15+
CV_PY_TO_CLASS(cann::AscendMat);
1616
CV_PY_TO_CLASS(cann::AscendStream);
1717

18-
CV_PY_TO_CLASS_PTR(cann::NpuMat);
19-
CV_PY_TO_CLASS_PTR(cann::NpuMat::Allocator);
18+
CV_PY_TO_CLASS_PTR(cann::AscendMat);
19+
CV_PY_TO_CLASS_PTR(cann::AscendMat::Allocator);
2020

21-
CV_PY_FROM_CLASS(cann::NpuMat);
21+
CV_PY_FROM_CLASS(cann::AscendMat);
2222
CV_PY_FROM_CLASS(cann::AscendStream);
2323

24-
CV_PY_FROM_CLASS_PTR(cann::NpuMat::Allocator);
24+
CV_PY_FROM_CLASS_PTR(cann::AscendMat::Allocator);
2525

2626
#endif // HAVE_OPENCV_CORE
2727

0 commit comments

Comments
 (0)