Skip to content

Commit

Permalink
Change name NPU_MAT to ASCEND_MAT
Browse files Browse the repository at this point in the history
NPU is too generic and there are more than one NPU vendors. It's better
to use ASCEND_MAT instead.
  • Loading branch information
hipudding committed Sep 18, 2023
1 parent 47f56cd commit b882619
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 26 deletions.
2 changes: 1 addition & 1 deletion modules/core/include/opencv2/core/base.hpp
Expand Up @@ -629,7 +629,7 @@ namespace cudev

namespace cann
{
class CV_EXPORTS NpuMat;
class CV_EXPORTS AscendMat;
}

namespace ipp
Expand Down
8 changes: 4 additions & 4 deletions modules/core/include/opencv2/core/mat.hpp
Expand Up @@ -184,7 +184,7 @@ class CV_EXPORTS _InputArray
STD_ARRAY =14 << KIND_SHIFT, //!< removed: https://github.com/opencv/opencv/issues/18897
#endif
STD_ARRAY_MAT =15 << KIND_SHIFT,
NPU_MAT =16 << KIND_SHIFT
ASCEND_MAT =16 << KIND_SHIFT
};

_InputArray();
Expand All @@ -202,7 +202,7 @@ class CV_EXPORTS _InputArray
template<typename _Tp, int m, int n> _InputArray(const Matx<_Tp, m, n>& matx);
_InputArray(const double& val);
_InputArray(const cuda::GpuMat& d_mat);
_InputArray(const cann::NpuMat& n_mat);
_InputArray(const cann::AscendMat& a_mat);

_InputArray(const std::vector<cuda::GpuMat>& d_mat_array);
_InputArray(const ogl::Buffer& buf);
Expand Down Expand Up @@ -318,7 +318,7 @@ class CV_EXPORTS _OutputArray : public _InputArray
_OutputArray(Mat& m);
_OutputArray(std::vector<Mat>& vec);
_OutputArray(cuda::GpuMat& d_mat);
_OutputArray(cann::NpuMat& n_mat);
_OutputArray(cann::AscendMat& a_mat);
_OutputArray(std::vector<cuda::GpuMat>& d_mat);
_OutputArray(ogl::Buffer& buf);
_OutputArray(cuda::HostMem& cuda_mem);
Expand All @@ -337,7 +337,7 @@ class CV_EXPORTS _OutputArray : public _InputArray
_OutputArray(const Mat& m);
_OutputArray(const std::vector<Mat>& vec);
_OutputArray(const cuda::GpuMat& d_mat);
_OutputArray(const cann::NpuMat& n_mat);
_OutputArray(const cann::AscendMat& a_mat);
_OutputArray(const std::vector<cuda::GpuMat>& d_mat);
_OutputArray(const ogl::Buffer& buf);
_OutputArray(const cuda::HostMem& cuda_mem);
Expand Down
12 changes: 6 additions & 6 deletions modules/core/include/opencv2/core/mat.inl.hpp
Expand Up @@ -147,8 +147,8 @@ inline _InputArray::_InputArray(const double& val)
inline _InputArray::_InputArray(const cuda::GpuMat& d_mat)
{ init(CUDA_GPU_MAT + ACCESS_READ, &d_mat); }

inline _InputArray::_InputArray(const cann::NpuMat& n_mat)
{ init(NPU_MAT + ACCESS_READ, &n_mat); }
inline _InputArray::_InputArray(const cann::AscendMat& a_mat)
{ init(ASCEND_MAT + ACCESS_READ, &a_mat); }

inline _InputArray::_InputArray(const std::vector<cuda::GpuMat>& d_mat)
{ init(STD_VECTOR_CUDA_GPU_MAT + ACCESS_READ, &d_mat);}
Expand Down Expand Up @@ -274,8 +274,8 @@ _OutputArray::_OutputArray(const _Tp* vec, int n)
inline _OutputArray::_OutputArray(cuda::GpuMat& d_mat)
{ init(CUDA_GPU_MAT + ACCESS_WRITE, &d_mat); }

inline _OutputArray::_OutputArray(cann::NpuMat& n_mat)
{ init(NPU_MAT + ACCESS_WRITE, &n_mat); }
inline _OutputArray::_OutputArray(cann::AscendMat& a_mat)
{ init(ASCEND_MAT + ACCESS_WRITE, &a_mat); }

inline _OutputArray::_OutputArray(std::vector<cuda::GpuMat>& d_mat)
{ init(STD_VECTOR_CUDA_GPU_MAT + ACCESS_WRITE, &d_mat);}
Expand All @@ -301,8 +301,8 @@ inline _OutputArray::_OutputArray(const std::vector<UMat>& vec)
inline _OutputArray::_OutputArray(const cuda::GpuMat& d_mat)
{ init(FIXED_TYPE + FIXED_SIZE + CUDA_GPU_MAT + ACCESS_WRITE, &d_mat); }

inline _OutputArray::_OutputArray(const cann::NpuMat& n_mat)
{ init(FIXED_TYPE + FIXED_SIZE + NPU_MAT + ACCESS_WRITE, &n_mat); }
inline _OutputArray::_OutputArray(const cann::AscendMat& a_mat)
{ init(FIXED_TYPE + FIXED_SIZE + ASCEND_MAT + ACCESS_WRITE, &a_mat); }

inline _OutputArray::_OutputArray(const ogl::Buffer& buf)
{ init(FIXED_TYPE + FIXED_SIZE + OPENGL_BUFFER + ACCESS_WRITE, &buf); }
Expand Down
14 changes: 7 additions & 7 deletions modules/python/src2/gen2.py
Expand Up @@ -234,7 +234,7 @@ class FormatStrings:
"cuda_Stream": ArgTypeInfo("cuda::Stream", FormatStrings.object, "cuda::Stream::Null()", True),
"cuda_GpuMat": ArgTypeInfo("cuda::GpuMat", FormatStrings.object, "cuda::GpuMat()", True),
"UMat": ArgTypeInfo("UMat", FormatStrings.object, 'UMat()', True), # FIXIT: switch to CV_EXPORTS_W_SIMPLE as UMat is already a some kind of smart pointer
"cann_NpuMat": ArgTypeInfo("cann::NpuMat", FormatStrings.object, "cann::NpuMat()", True),
"cann_AscendMat": ArgTypeInfo("cann::AscendMat", FormatStrings.object, "cann::AscendMat()", True),
}

# Set of reserved keywords for Python. Can be acquired via the following call
Expand Down Expand Up @@ -515,8 +515,8 @@ def isbig(self):
return self.tp in ["Mat", "vector_Mat",
"cuda::GpuMat", "cuda_GpuMat", "GpuMat",
"vector_GpuMat", "vector_cuda_GpuMat",
"UMat", "vector_UMat", "cann::NpuMat",
"NpuMat", "vector_NpuMat"] # or self.tp.startswith("vector")
"UMat", "vector_UMat", "cann::AscendMat",
"AscendMat", "vector_AscendMat"] # or self.tp.startswith("vector")

def crepr(self):
return "ArgInfo(\"%s\", %d)" % (self.name, self.outputarg)
Expand Down Expand Up @@ -929,9 +929,9 @@ def gen_code(self, codegen):
if "cuda::GpuMat" in tp:
if "Mat" in defval and "GpuMat" not in defval:
defval = defval.replace("Mat", "cuda::GpuMat")
if "cann::NpuMat" in tp:
if "Mat" in defval and "NpuMat" not in defval:
defval = defval.replace("Mat", "cann::NpuMat")
if "cann::AscendMat" in tp:
if "Mat" in defval and "AscendMat" not in defval:
defval = defval.replace("Mat", "cann::AscendMat")
# "tp arg = tp();" is equivalent to "tp arg;" in the case of complex types
if defval == tp + "()" and arg_type_info.format_str == FormatStrings.object:
defval = ""
Expand Down Expand Up @@ -1304,7 +1304,7 @@ def save_json(self, path, name, value):

def gen(self, srcfiles, output_path):
self.clear()
self.parser = hdr_parser.CppHeaderParser(generate_umat_decls=True, generate_gpumat_decls=True, generate_npumat_decls=True)
self.parser = hdr_parser.CppHeaderParser(generate_umat_decls=True, generate_gpumat_decls=True, generate_ascendmat_decls=True)

# step 1: scan the headers and build more descriptive maps of classes, consts, functions
for hdr in srcfiles:
Expand Down
16 changes: 8 additions & 8 deletions modules/python/src2/hdr_parser.py
Expand Up @@ -33,10 +33,10 @@

class CppHeaderParser(object):

def __init__(self, generate_umat_decls=False, generate_gpumat_decls=False, generate_npumat_decls=False):
def __init__(self, generate_umat_decls=False, generate_gpumat_decls=False, generate_ascendmat_decls=False):
self._generate_umat_decls = generate_umat_decls
self._generate_gpumat_decls = generate_gpumat_decls
self._generate_npumat_decls = generate_npumat_decls
self._generate_ascendmat_decls = generate_ascendmat_decls

self.BLOCK_TYPE = 0
self.BLOCK_NAME = 1
Expand Down Expand Up @@ -1014,15 +1014,15 @@ def parse(self, hname, wmode=True):
if umat_decl != decl:
decls.append(umat_decl)

if self._generate_npumat_decls and "cv.cann" in decl[0]:
if self._generate_ascendmat_decls and "cv.cann" in decl[0]:
# If function takes as one of arguments Mat or vector<Mat> - we want to create the
# same declaration working with NpuMat
# same declaration working with AscendMat
args = decl[3]
has_mat = len(list(filter(lambda x: x[0] in {"Mat", "vector_Mat"}, args))) > 0
if has_mat:
_, _, _, npumat_decl = self.parse_stmt(stmt, token, mat="cann::NpuMat", docstring=docstring)
if npumat_decl != decl:
decls.append(npumat_decl)
_, _, _, ascendmat_decl = self.parse_stmt(stmt, token, mat="cann::AscendMat", docstring=docstring)
if ascendmat_decl != decl:
decls.append(ascendmat_decl)

docstring = ""
if stmt_type == "namespace":
Expand Down Expand Up @@ -1066,7 +1066,7 @@ def print_decls(self, decls):
print()

if __name__ == '__main__':
parser = CppHeaderParser(generate_umat_decls=True, generate_gpumat_decls=True, generate_npumat_decls=True)
parser = CppHeaderParser(generate_umat_decls=True, generate_gpumat_decls=True, generate_ascendmat_decls=True)
decls = []
for hname in opencv_hdr_list:
decls += parser.parse(hname)
Expand Down

0 comments on commit b882619

Please sign in to comment.