update version

This commit is contained in:
luoliang
2022-10-10 16:49:04 +08:00
parent be79c3e5c3
commit 83d85cc751
31 changed files with 3739 additions and 3850 deletions

View File

@@ -1,9 +1,9 @@
#if(NOT HAVE_ACL)
# ocv_module_disable(acl)
# return()
#endif()
# if(NOT HAVE_ACL)
# ocv_module_disable(acl)
# return()
# endif()
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" "-DENABLE_DVPP_INTERFACE")
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" "-DENABLE_DVPP_INTERFACE")
set(acl_lib "/usr/local/Ascend/ascend-toolkit/latest/acllib/lib64/stub/")
set(acl_lib "/usr/local/Ascend/ascend-toolkit/latest/fwkacllib/lib64/stub/")

View File

@@ -1,8 +1,9 @@
/*M///////////////////////////////////////////////////////////////////////////////////////
/* M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// By downloading, copying, installing or using the software you agree to this
license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
@@ -10,28 +11,35 @@
// License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2010-2012, Institute Of Software Chinese Academy Of Science, all rights reserved.
// Copyright (C) 2010-2012, Institute Of Software Chinese Academy Of Science,
all rights reserved.
// Copyright (C) 2010-2012, Advanced Micro Devices, Inc., all rights reserved.
// Copyright (C) 2010-2012, Multicoreware, Inc., all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// Redistribution and use in source and binary forms, with or without
modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// * Redistribution's in binary form must reproduce the above copyright
notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of the copyright holders may not be used to endorse or promote products
// * The name of the copyright holders may not be used to endorse or promote
products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// This software is provided by the copyright holders and contributors "as is"
and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// warranties of merchantability and fitness for a particular purpose are
disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any
direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
@@ -39,19 +47,19 @@
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
//M */
#ifndef OPENCV_ACL_HPP
#define OPENCV_ACL_HPP
#include "acl_type.hpp"
#include "acl_init.hpp"
#include "acl_mat.hpp"
#include "operator_desc.hpp"
#include "acl_type.hpp"
#include "gemm.hpp"
#include "init_core.hpp"
#include "mat_core.hpp"
#include "mathfuncs.hpp"
#include "matrices.hpp"
#include "gemm.hpp"
#include "mat_core.hpp"
#include "init_core.hpp"
#include "operator_desc.hpp"
#endif

View File

@@ -4,55 +4,52 @@
#include <memory>
#include <vector>
#include "opencv2/core.hpp"
#include "acl_type.hpp"
#include "opencv2/core.hpp"
using namespace std;
namespace cv {
namespace acl {
CV_EXPORTS Mutex &getInitMutex();
//////////////////////////////// aclEnv ////////////////////////////////
class CV_EXPORTS aclEnv {
public:
aclEnv();
aclEnv(const char *config_path);
static aclEnv *get_acl_env(const char *config_path);
int get_device_count();
int *refcount;
~aclEnv();
namespace cv
{
namespace acl
{
CV_EXPORTS Mutex &getInitMutex();
//////////////////////////////// aclEnv ////////////////////////////////
class CV_EXPORTS aclEnv
{
public:
aclEnv();
aclEnv(const char* config_path);
static aclEnv* get_acl_env(const char* config_path);
int get_device_count();
int *refcount;
~aclEnv();
private:
uint32_t _device_count;
};
private:
uint32_t _device_count;
};
//////////////////////////////// aclCxt ////////////////////////////////
class CV_EXPORTS aclCxt
{
public:
aclCxt();
aclCxt(int device_id);
//////////////////////////////// aclCxt ////////////////////////////////
class CV_EXPORTS aclCxt {
public:
aclCxt();
aclCxt(int device_id);
aclrtContext* get_context();
void set_current_context();
aclrtContext *get_context();
void set_current_context();
void create_stream(int count = 1);
aclStream get_stream(const size_t index = 0);
~aclCxt();
private:
int32_t _device_id;
aclrtContext* _context;
std::vector<aclStream> _acl_streams;
};
void create_stream(int count = 1);
aclStream get_stream(const size_t index = 0);
~aclCxt();
CV_EXPORTS void wait_stream(aclCxt* context, const int stream_id = 0);
//////////////////////////////// device ////////////////////////////////
CV_EXPORTS aclCxt *set_device(const char* config_path, int device_id = 0, int stream_count = 1);
CV_EXPORTS void release_device(aclCxt* context);
private:
int32_t _device_id;
aclrtContext *_context;
std::vector<aclStream> _acl_streams;
};
} /* end of namespace acl */
CV_EXPORTS void wait_stream(aclCxt *context, const int stream_id = 0);
//////////////////////////////// device ////////////////////////////////
CV_EXPORTS aclCxt *set_device(const char *config_path, int device_id = 0,
int stream_count = 1);
CV_EXPORTS void release_device(aclCxt *context);
} /* end of namespace acl */
} /* end of namespace cv */

View File

@@ -2,172 +2,185 @@
#define OPENCV_ACL_MAT_HPP
#include "acl/acl.h"
#include "opencv2/core.hpp"
#include "acl_type.hpp"
#include "acl_init.hpp"
#include "acl_type.hpp"
#include "opencv2/core.hpp"
namespace cv {
namespace acl {
//////////////////////////////// aclMat ////////////////////////////////
class CV_EXPORTS aclMat {
public:
//! default constructor
aclMat();
//! constructs aclMatrix of the specified size and type (_type is CV_8UC1,
//! CV_16FC1 etc.)
aclMat(int rows, int cols, int type, aclCxt *acl_context,
ALIGNMENT config = MEMORY_UNALIGNED,
MemMallocPolicy policy = MALLOC_NORMAL_ONLY);
aclMat(Size size, int type, aclCxt *acl_context,
ALIGNMENT config = MEMORY_UNALIGNED,
MemMallocPolicy policy = MALLOC_NORMAL_ONLY);
//! copy constructor
aclMat(const aclMat &m);
//! constructor for aclMatrix headers pointing to user-allocated data
aclMat(int rows, int cols, int type, void *data, aclCxt *acl_context,
ALIGNMENT config = MEMORY_UNALIGNED, size_t step = Mat::AUTO_STEP);
aclMat(Size size, int type, void *data, aclCxt *acl_context,
ALIGNMENT config = MEMORY_UNALIGNED, size_t step = Mat::AUTO_STEP);
//! creates a matrix header for a part of the bigger matrix
aclMat(const aclMat &m, const Range &rowRange,
const Range &colRange = Range::all());
aclMat(const aclMat &m, const Rect &roi);
//! builds aclMat from Mat. Perfom blocking upload to device.
aclMat(const Mat &m, aclCxt *acl_context, ALIGNMENT config = MEMORY_UNALIGNED,
MemMallocPolicy policy = MALLOC_NORMAL_ONLY);
//! destructor - calls release()
~aclMat();
namespace cv
{
namespace acl
{
//////////////////////////////// aclMat ////////////////////////////////
class CV_EXPORTS aclMat
{
public:
//! default constructor
aclMat();
//! constructs aclMatrix of the specified size and type (_type is CV_8UC1, CV_16FC1 etc.)
aclMat(int rows, int cols, int type, aclCxt *acl_context, ALIGNMENT config = MEMORY_UNALIGNED, MemMallocPolicy policy = MALLOC_NORMAL_ONLY);
aclMat(Size size, int type, aclCxt *acl_context, ALIGNMENT config = MEMORY_UNALIGNED, MemMallocPolicy policy = MALLOC_NORMAL_ONLY);
//! copy constructor
aclMat(const aclMat &m);
//! constructor for aclMatrix headers pointing to user-allocated data
aclMat(int rows, int cols, int type, void *data, aclCxt* acl_context, ALIGNMENT config = MEMORY_UNALIGNED, size_t step = Mat::AUTO_STEP);
aclMat(Size size, int type, void *data, aclCxt* acl_context, ALIGNMENT config = MEMORY_UNALIGNED, size_t step = Mat::AUTO_STEP);
//! creates a matrix header for a part of the bigger matrix
aclMat(const aclMat &m, const Range &rowRange, const Range &colRange = Range::all());
aclMat(const aclMat &m, const Rect &roi);
//! builds aclMat from Mat. Perfom blocking upload to device.
aclMat (const Mat &m, aclCxt* acl_context, ALIGNMENT config = MEMORY_UNALIGNED, MemMallocPolicy policy = MALLOC_NORMAL_ONLY);
//! destructor - calls release()
~aclMat();
//! assignment operators shallow copy
aclMat &operator=(const aclMat &m);
//! assignment operator. Perfom blocking upload to device.
aclMat &operator=(const Mat &m);
//! assignment operators shallow copy
aclMat &operator=(const aclMat &m);
//! assignment operator. Perfom blocking upload to device.
aclMat &operator=(const Mat &m);
//! pefroms blocking upload data to aclMat.
void upload(const Mat &m, ALIGNMENT config = MEMORY_UNALIGNED);
void upload(const Mat &m, aclStream stream, ALIGNMENT config = MEMORY_UNALIGNED);
//! downloads data from device to host memory. Blocking calls.
void download(Mat &m, ALIGNMENT config = MEMORY_UNALIGNED) const;
void download(Mat &m, aclStream stream, ALIGNMENT config = MEMORY_UNALIGNED) const;
operator Mat() const;
aclMat clone() const;
void copyTo(aclMat& dest) const;
//! pefroms blocking upload data to aclMat.
void upload(const Mat &m, ALIGNMENT config = MEMORY_UNALIGNED);
void upload(const Mat &m, aclStream stream,
ALIGNMENT config = MEMORY_UNALIGNED);
//! downloads data from device to host memory. Blocking calls.
void download(Mat &m, ALIGNMENT config = MEMORY_UNALIGNED) const;
void download(Mat &m, aclStream stream,
ALIGNMENT config = MEMORY_UNALIGNED) const;
//! returns a new aclMatrix header for the specified row
aclMat row(int y) const;
//! returns a new aclMatrix header for the specified column
aclMat col(int x) const;
//! ... for the specified row span
aclMat rowRange(int startrow, int endrow) const;
aclMat rowRange(const Range &r) const;
//! ... for the specified column span
aclMat colRange(int startcol, int endcol) const;
aclMat colRange(const Range &r) const;
operator Mat() const;
aclMat clone() const;
void copyTo(aclMat &dest) const;
//! locates aclMatrix header within a parent aclMatrix. See below
void locateROI(Size &wholeSize, Point &ofs) const;
//! moves/resizes the current aclMatrix ROI inside the parent aclMatrix.
aclMat &adjustROI(int dtop, int dbottom, int dleft, int dright);
//! returns a new aclMatrix header for the specified row
aclMat row(int y) const;
//! returns a new aclMatrix header for the specified column
aclMat col(int x) const;
//! ... for the specified row span
aclMat rowRange(int startrow, int endrow) const;
aclMat rowRange(const Range &r) const;
//! ... for the specified column span
aclMat colRange(int startcol, int endcol) const;
aclMat colRange(const Range &r) const;
//! allocates new aclMatrix data unless the aclMatrix already has specified size and type.
// previous data is unreferenced if needed.
void create(int rows, int cols, int type, ALIGNMENT config = MEMORY_UNALIGNED, MemMallocPolicy policy = MALLOC_NORMAL_ONLY);
void create(Size size, int type, ALIGNMENT config = MEMORY_UNALIGNED, MemMallocPolicy policy = MALLOC_NORMAL_ONLY);
//! locates aclMatrix header within a parent aclMatrix. See below
void locateROI(Size &wholeSize, Point &ofs) const;
//! moves/resizes the current aclMatrix ROI inside the parent aclMatrix.
aclMat &adjustROI(int dtop, int dbottom, int dleft, int dright);
//! allocates new aclMatrix with specified device memory type.
void createEx(int rows, int cols, int type, ALIGNMENT config = MEMORY_UNALIGNED, MemMallocPolicy policy = MALLOC_NORMAL_ONLY);
void createEx(Size size, int type, ALIGNMENT config = MEMORY_UNALIGNED, MemMallocPolicy policy = MALLOC_NORMAL_ONLY);
//! allocates new aclMatrix data unless the aclMatrix already has specified
//! size and type.
// previous data is unreferenced if needed.
void create(int rows, int cols, int type, ALIGNMENT config = MEMORY_UNALIGNED,
MemMallocPolicy policy = MALLOC_NORMAL_ONLY);
void create(Size size, int type, ALIGNMENT config = MEMORY_UNALIGNED,
MemMallocPolicy policy = MALLOC_NORMAL_ONLY);
//! decreases reference counter;
// deallocate the data when reference counter reaches 0.
void release();
//! allocates new aclMatrix with specified device memory type.
void createEx(int rows, int cols, int type,
ALIGNMENT config = MEMORY_UNALIGNED,
MemMallocPolicy policy = MALLOC_NORMAL_ONLY);
void createEx(Size size, int type, ALIGNMENT config = MEMORY_UNALIGNED,
MemMallocPolicy policy = MALLOC_NORMAL_ONLY);
//! swaps with other smart pointer
void swap(aclMat &mat);
//! decreases reference counter;
// deallocate the data when reference counter reaches 0.
void release();
//! extracts a rectangular sub-aclMatrix
// (this is a generalized form of row, rowRange etc.)
aclMat operator()( Range rowRange, Range colRange ) const;
aclMat operator()( const Rect &roi ) const;
//! swaps with other smart pointer
void swap(aclMat &mat);
aclMat& operator+=( const aclMat& m );
aclMat& operator-=( const aclMat& m );
aclMat& operator/=( const aclMat& m );
aclMat& operator*=( const aclMat& m );
//! returns true if the aclMatrix data is continuous
// (i.e. when there are no gaps between successive rows).
// similar to CV_IS_aclMat_CONT(cvaclMat->type)
bool isContinuous() const;
//! extracts a rectangular sub-aclMatrix
// (this is a generalized form of row, rowRange etc.)
aclMat operator()(Range rowRange, Range colRange) const;
aclMat operator()(const Rect &roi) const;
//! returns element size in bytes,
// similar to CV_ELEM_SIZE(cvMat->type)
size_t elemSize() const;
//! returns the size of element channel in bytes.
size_t elemSize1() const;
aclMat &operator+=(const aclMat &m);
aclMat &operator-=(const aclMat &m);
aclMat &operator/=(const aclMat &m);
aclMat &operator*=(const aclMat &m);
//! returns element type, similar to CV_MAT_TYPE(cvMat->type)
int type() const;
//! returns element type, i.e. 8UC3 returns 8UC4 because in acl
//! 3 channels element actually use 4 channel space
int acltype() const;
//! returns element type, similar to CV_MAT_DEPTH(cvMat->type)
int depth() const;
//! returns true if the aclMatrix data is continuous
// (i.e. when there are no gaps between successive rows).
// similar to CV_IS_aclMat_CONT(cvaclMat->type)
bool isContinuous() const;
//! returns element type, similar to CV_MAT_CN(cvMat->type)
int channels() const;
//! returns element type, return 4 for 3 channels element,
//!becuase 3 channels element actually use 4 channel space
int aclchannels() const;
//! returns element size in bytes,
// similar to CV_ELEM_SIZE(cvMat->type)
size_t elemSize() const;
//! returns the size of element channel in bytes.
size_t elemSize1() const;
//! returns step/elemSize1()
size_t step1() const;
//! returns aclMatrix size:
// width == number of columns, height == number of rows
Size size() const;
//! returns true if aclMatrix data is NULL
bool empty() const;
//! returns element type, similar to CV_MAT_TYPE(cvMat->type)
int type() const;
//! returns element type, i.e. 8UC3 returns 8UC4 because in acl
//! 3 channels element actually use 4 channel space
int acltype() const;
//! returns element type, similar to CV_MAT_DEPTH(cvMat->type)
int depth() const;
friend void swap(aclMat &a, aclMat &b);
friend void ensureSizeIsEnough(int rows, int cols, int type, aclMat &m, ALIGNMENT config = MEMORY_UNALIGNED);
friend void ensureSizeIsEnough(Size size, int type, aclMat &m, ALIGNMENT config = MEMORY_UNALIGNED);
//! returns element type, similar to CV_MAT_CN(cvMat->type)
int channels() const;
//! returns element type, return 4 for 3 channels element,
//! becuase 3 channels element actually use 4 channel space
int aclchannels() const;
/*! includes several bit-fields:
- the magic signature
- continuity flag
- depth
- number of channels
*/
int flags;
//! the number of rows and columns
int rows, cols;
//! a distance between successive rows in bytes; includes the gap if any
size_t step;
//! pointer to the data(ACL memory object)
//uchar *data;
//! returns step/elemSize1()
size_t step1() const;
//! returns aclMatrix size:
// width == number of columns, height == number of rows
Size size() const;
//! returns true if aclMatrix data is NULL
bool empty() const;
//! OpenCL context associated with the aclMat object.
void *data; // TODO
friend void swap(aclMat &a, aclMat &b);
friend void ensureSizeIsEnough(int rows, int cols, int type, aclMat &m,
ALIGNMENT config = MEMORY_UNALIGNED);
friend void ensureSizeIsEnough(Size size, int type, aclMat &m,
ALIGNMENT config = MEMORY_UNALIGNED);
//! pointer to the reference counter;
// when aclMatrix points to user-allocated data, the pointer is NULL
int *refcount;
/*! includes several bit-fields:
- the magic signature
- continuity flag
- depth
- number of channels
*/
int flags;
//! the number of rows and columns
int rows, cols;
//! a distance between successive rows in bytes; includes the gap if any
size_t step;
//! pointer to the data(ACL memory object)
// uchar *data;
//! helper fields used in locateROI and adjustROI
//datastart and dataend are not used in current version
uchar *datastart;
uchar *dataend;
//! OpenCL context associated with the aclMat object.
void *data; // TODO
//add offset for handle ROI, calculated in byte
int offset;
//add wholerows and wholecols for the whole matrix, datastart and dataend are no longer used
int wholerows;
int wholecols;
//! pointer to the reference counter;
// when aclMatrix points to user-allocated data, the pointer is NULL
int *refcount;
aclCxt *acl_context;
size_t totalSize;
//! helper fields used in locateROI and adjustROI
// datastart and dataend are not used in current version
uchar *datastart;
uchar *dataend;
};
} /* end of namespace acl */
// add offset for handle ROI, calculated in byte
int offset;
// add wholerows and wholecols for the whole matrix, datastart and dataend are
// no longer used
int wholerows;
int wholecols;
aclCxt *acl_context;
size_t totalSize;
};
} /* end of namespace acl */
} /* end of namespace cv */
#endif

View File

@@ -1,8 +1,9 @@
/*M///////////////////////////////////////////////////////////////////////////////////////
/* M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// By downloading, copying, installing or using the software you agree to this
license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
@@ -10,28 +11,35 @@
// License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2010-2012, Institute Of Software Chinese Academy Of Science, all rights reserved.
// Copyright (C) 2010-2012, Institute Of Software Chinese Academy Of Science,
all rights reserved.
// Copyright (C) 2010-2012, Advanced Micro Devices, Inc., all rights reserved.
// Copyright (C) 2010-2012, Multicoreware, Inc., all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// Redistribution and use in source and binary forms, with or without
modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// * Redistribution's in binary form must reproduce the above copyright
notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of the copyright holders may not be used to endorse or promote products
// * The name of the copyright holders may not be used to endorse or promote
products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// This software is provided by the copyright holders and contributors "as is"
and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// warranties of merchantability and fitness for a particular purpose are
disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any
direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
@@ -39,7 +47,7 @@
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
//M */
#ifndef OPENCV_ACL_TYPE_HPP
#define OPENCV_ACL_TYPE_HPP
@@ -48,110 +56,102 @@
#define AclVerifyCall(expr) __aclSafeCall(res, __FILE__, __LINE__, __func__)
#include <iostream>
#include "opencv2/core.hpp"
#include "acl/acl.h"
#include "opencv2/core.hpp"
namespace cv
{
namespace acl
{
/**
* An error is reported if the expression value is not 0
*/
static inline void __aclSafeCall(int err, const char* file, const int line, const char *func="")
{
if(0 != err)
{
const char* function = func ? func : "unknown function";
std::cerr << "Acl Called Error: " << "file " << file << ", func " << function << ", line " << line << " errorCode: " << err << std::endl;
std::cerr.flush();
}
}
namespace cv {
namespace acl {
/**
* An error is reported if the expression value is not 0
*/
static inline void __aclSafeCall(int err, const char *file, const int line,
const char *func = "") {
if (0 != err) {
const char *function = func ? func : "unknown function";
std::cerr << "Acl Called Error: "
<< "file " << file << ", func " << function << ", line " << line
<< " errorCode: " << err << std::endl;
std::cerr.flush();
}
}
/* Memory alignment */
enum ALIGNMENT { MEMORY_UNALIGNED = 0, MEMORY_ALIGN = 1};
/* Memory alignment */
enum ALIGNMENT { MEMORY_UNALIGNED = 0, MEMORY_ALIGN = 1 };
enum { MAGIC_VAL = 0x42FF0000, AUTO_STEP = 0, CONTINUOUS_FLAG = CV_MAT_CONT_FLAG, SUBMATRIX_FLAG = CV_SUBMAT_FLAG };
enum { MAGIC_MASK = 0xFFFF0000, TYPE_MASK = 0x00000FFF, DEPTH_MASK = 7 };
enum {
MAGIC_VAL = 0x42FF0000,
AUTO_STEP = 0,
CONTINUOUS_FLAG = CV_MAT_CONT_FLAG,
SUBMATRIX_FLAG = CV_SUBMAT_FLAG
};
enum { MAGIC_MASK = 0xFFFF0000, TYPE_MASK = 0x00000FFF, DEPTH_MASK = 7 };
typedef aclrtStream aclStream;
typedef aclrtStream aclStream;
typedef enum Opdims { TWO_DIMS = 1, FOUR_DIMS } Opdims;
typedef enum Opdims { TWO_DIMS = 1, FOUR_DIMS } Opdims;
enum DeviceType
{
ACL_DEVICE_TYPE_DEFAULT = (1 << 0),
ACL_DEVICE_TYPE_200 = (1 << 1),
ACL_DEVICE_TYPE_ACCELERATOR = (1 << 3),
};
enum DeviceType {
ACL_DEVICE_TYPE_DEFAULT = (1 << 0),
ACL_DEVICE_TYPE_200 = (1 << 1),
ACL_DEVICE_TYPE_ACCELERATOR = (1 << 3),
};
enum AttrType
{
OP_BOOL = 1,
OP_INT,
OP_FLOAT,
OP_STRING
};
enum AttrType { OP_BOOL = 1, OP_INT, OP_FLOAT, OP_STRING };
typedef enum MemMallocPolicy
{
MALLOC_HUGE_FIRST = 1,
MALLOC_HUGE_ONLY,
MALLOC_NORMAL_ONLY,
MALLOC_HUGE_FIRST_P2P,
MALLOC_HUGE_ONLY_P2P,
MALLOC_NORMAL_ONLY_P2P
} MemMallocPolicy;
typedef enum MemMallocPolicy {
MALLOC_HUGE_FIRST = 1,
MALLOC_HUGE_ONLY,
MALLOC_NORMAL_ONLY,
MALLOC_HUGE_FIRST_P2P,
MALLOC_HUGE_ONLY_P2P,
MALLOC_NORMAL_ONLY_P2P
} MemMallocPolicy;
CV_EXPORTS aclDataType type_transition(int depth);
CV_EXPORTS aclrtMemMallocPolicy type_transition(MemMallocPolicy type);
CV_EXPORTS aclDataType type_transition(int depth);
CV_EXPORTS aclrtMemMallocPolicy type_transition(MemMallocPolicy type);
inline aclDataType type_transition(int depth) {
switch (depth) {
case CV_8U:
return ACL_UINT8;
case CV_8S:
return ACL_INT8;
case CV_16U:
return ACL_UINT16;
case CV_16S:
return ACL_INT16;
case CV_16F:
return ACL_FLOAT16;
case CV_32S:
return ACL_INT32;
case CV_32F:
return ACL_FLOAT;
case CV_64F:
return ACL_DOUBLE;
}
return ACL_DT_UNDEFINED;
}
inline aclDataType type_transition(int depth)
{
switch (depth)
{
case CV_8U:
return ACL_UINT8;
case CV_8S:
return ACL_INT8;
case CV_16U:
return ACL_UINT16;
case CV_16S:
return ACL_INT16;
case CV_16F:
return ACL_FLOAT16;
case CV_32S:
return ACL_INT32;
case CV_32F:
return ACL_FLOAT;
case CV_64F:
return ACL_DOUBLE;
}
return ACL_DT_UNDEFINED;
}
inline aclrtMemMallocPolicy type_transition(MemMallocPolicy type) {
switch (type) {
case MALLOC_HUGE_FIRST:
return ACL_MEM_MALLOC_HUGE_FIRST;
case MALLOC_HUGE_ONLY:
return ACL_MEM_MALLOC_HUGE_ONLY;
case MALLOC_NORMAL_ONLY:
return ACL_MEM_MALLOC_NORMAL_ONLY;
case MALLOC_HUGE_FIRST_P2P:
return ACL_MEM_MALLOC_HUGE_FIRST_P2P;
case MALLOC_HUGE_ONLY_P2P:
return ACL_MEM_MALLOC_HUGE_ONLY_P2P;
case MALLOC_NORMAL_ONLY_P2P:
return ACL_MEM_MALLOC_NORMAL_ONLY_P2P;
}
return ACL_MEM_MALLOC_HUGE_FIRST;
}
inline aclrtMemMallocPolicy type_transition(MemMallocPolicy type)
{
switch (type)
{
case MALLOC_HUGE_FIRST:
return ACL_MEM_MALLOC_HUGE_FIRST;
case MALLOC_HUGE_ONLY:
return ACL_MEM_MALLOC_HUGE_ONLY;
case MALLOC_NORMAL_ONLY:
return ACL_MEM_MALLOC_NORMAL_ONLY;
case MALLOC_HUGE_FIRST_P2P:
return ACL_MEM_MALLOC_HUGE_FIRST_P2P;
case MALLOC_HUGE_ONLY_P2P:
return ACL_MEM_MALLOC_HUGE_ONLY_P2P;
case MALLOC_NORMAL_ONLY_P2P:
return ACL_MEM_MALLOC_NORMAL_ONLY_P2P;
}
return ACL_MEM_MALLOC_HUGE_FIRST;
}
} /* end of namespace acl */
} /* end of namespace acl */
} /* end of namespace cv */

View File

@@ -3,19 +3,20 @@
#include "acl_mat.hpp"
namespace cv
{
namespace acl
{
// matrix multiplication
CV_EXPORTS void MatMul(const aclMat& src1, const aclMat& src2, aclMat& dest, int stream_id = 0);
// convolution
CV_EXPORTS void Convolution(const aclMat& src, const aclMat& kernel, aclMat& dest, \
const vector<int64_t>& stridesList = vector<int64_t> {1, 1, 1, 1}, const vector<int64_t>& padsList = vector<int64_t> {0, 0, 0, 0}, int stream_id = 0);
namespace cv {
namespace acl {
// matrix multiplication
CV_EXPORTS void MatMul(const aclMat &src1, const aclMat &src2, aclMat &dest,
int stream_id = 0);
// convolution
CV_EXPORTS void Convolution(
const aclMat &src, const aclMat &kernel, aclMat &dest,
const std::vector<int64_t> &stridesList = std::vector<int64_t>{1, 1, 1, 1},
const std::vector<int64_t> &padsList = std::vector<int64_t>{0, 0, 0, 0},
int stream_id = 0);
} /* end of namespace acl */
} /* end of namespace acl */
} /* end of namespace cv */
#endif
#endif

View File

@@ -3,115 +3,96 @@
#include "acl_init.hpp"
namespace cv
{
namespace acl
{
///////////////////////////aclEnv//////////////////////////////////
/**
* acl init
*/
inline aclEnv::aclEnv()
{}
namespace cv {
namespace acl {
///////////////////////////aclEnv//////////////////////////////////
/**
* acl init
*/
inline aclEnv::aclEnv() {}
inline aclEnv::aclEnv(const char* config_path)
{
uint32_t device_count;
inline aclEnv::aclEnv(const char *config_path) {
uint32_t device_count;
AclSafeCall(aclInit(config_path));
AclSafeCall(aclrtGetDeviceCount(&device_count));
AclSafeCall(aclInit(config_path));
_device_count = device_count;
// Reference Counting
refcount = static_cast<int *>(fastMalloc(sizeof(*refcount)));
*refcount = 0;
clog << "aclInit() is success" << endl;
}
AclSafeCall(aclrtGetDeviceCount(&device_count));
inline int aclEnv::get_device_count()
{
return _device_count;
}
_device_count = device_count;
// Reference Counting
refcount = static_cast<int *>(fastMalloc(sizeof(*refcount)));
*refcount = 0;
inline aclEnv::~aclEnv()
{
AclSafeCall(aclFinalize());
clog << "aclFinalize() is success" << endl;
}
std::clog << "aclInit() is success" << std::endl;
}
/////////////////////////////////////////aclCxt////////////////////////////
inline aclCxt::aclCxt() {};
inline int aclEnv::get_device_count() { return _device_count; }
inline aclCxt::aclCxt(int device_id) : _device_id(device_id)
{
_context = static_cast<aclrtContext *>(fastMalloc(sizeof(*_context)));
AclSafeCall(aclrtCreateContext(_context, _device_id));
inline aclEnv::~aclEnv() {
AclSafeCall(aclFinalize());
std::clog << "aclFinalize() is success" << std::endl;
}
clog << "aclrtCreateContext() is success" << endl;
}
/////////////////////////////////////////aclCxt////////////////////////////
inline aclCxt::aclCxt(){};
inline aclrtContext* aclCxt::get_context()
{
return _context;
}
inline aclCxt::aclCxt(int device_id) : _device_id(device_id) {
_context = static_cast<aclrtContext *>(fastMalloc(sizeof(*_context)));
AclSafeCall(aclrtCreateContext(_context, _device_id));
/**
* set current context
*/
inline void aclCxt::set_current_context()
{
AclSafeCall(aclrtSetCurrentContext(*_context));
}
std::clog << "aclrtCreateContext() is success" << std::endl;
}
inline void aclCxt::create_stream(int count)
{
CV_Assert(count > 0);
inline aclrtContext *aclCxt::get_context() { return _context; }
int i;
for(i = 0; i <count; i++)
{
aclStream stream;
AclSafeCall(aclrtCreateStream(&stream));
/**
* set current context
*/
inline void aclCxt::set_current_context() {
AclSafeCall(aclrtSetCurrentContext(*_context));
}
_acl_streams.push_back(stream);
}
inline void aclCxt::create_stream(int count) {
CV_Assert(count > 0);
clog << "aclrtCreateStream() is success" << endl;
}
int i;
for (i = 0; i < count; i++) {
aclStream stream;
AclSafeCall(aclrtCreateStream(&stream));
inline aclrtStream aclCxt::get_stream(const size_t index)
{
CV_Assert(index < _acl_streams.size());
return _acl_streams[index];
}
_acl_streams.push_back(stream);
}
/**
* destroy stream and context
*/
inline aclCxt::~aclCxt()
{
size_t i = 0;
AclSafeCall(aclrtSetCurrentContext(*_context));
for (i = 0; i < _acl_streams.size(); i++)
{
aclStream acl_stream = _acl_streams[i];
AclSafeCall(aclrtDestroyStream(acl_stream));
}
std::clog << "aclrtCreateStream() is success" << std::endl;
}
clog << "aclrtDestroyStream() is success" << endl;
inline aclrtStream aclCxt::get_stream(const size_t index) {
CV_Assert(index < _acl_streams.size());
return _acl_streams[index];
}
// empty vector
std::vector<aclrtStream>().swap(_acl_streams);
AclSafeCall(aclrtDestroyContext(*_context));
/**
* destroy stream and context
*/
inline aclCxt::~aclCxt() {
size_t i = 0;
clog << "aclrtDestroyContext() is success" << endl;
}
AclSafeCall(aclrtSetCurrentContext(*_context));
for (i = 0; i < _acl_streams.size(); i++) {
aclStream acl_stream = _acl_streams[i];
AclSafeCall(aclrtDestroyStream(acl_stream));
}
} /* end of namespace acl */
std::clog << "aclrtDestroyStream() is success" << std::endl;
// empty vector
std::vector<aclrtStream>().swap(_acl_streams);
AclSafeCall(aclrtDestroyContext(*_context));
std::clog << "aclrtDestroyContext() is success" << std::endl;
}
} /* end of namespace acl */
} /* end of namespace cv */

View File

@@ -3,384 +3,410 @@
#include "acl_type.hpp"
namespace cv
{
namespace acl
{
////////////////////////////////////////////////////////////////////////
//////////////////////////////// aclMat ////////////////////////////////
////////////////////////////////////////////////////////////////////////
namespace cv {
namespace acl {
//////////////////////////////// aclMat ////////////////////////////////
inline aclMat::aclMat()
: flags(0),
rows(0),
cols(0),
step(0),
data(nullptr),
refcount(nullptr),
datastart(nullptr),
dataend(nullptr),
offset(0),
wholerows(0),
wholecols(0),
acl_context(0),
totalSize(0) {}
inline aclMat::aclMat()
: flags(0), rows(0), cols(0), step(0), data(nullptr), refcount(nullptr),
datastart(nullptr), dataend(nullptr), offset(0), wholerows(0), wholecols(0), acl_context(0), totalSize(0)
{
}
/**
* @param [in] _acl_context: Acl context
* @param [in] config: Byte aligned or not, Default MEMORY_UNALIGNED
* @param [in] policy: Acl Memory Application mode, Default
* ACL_MEM_MALLOC_NORMAL_ONLY
*/
inline aclMat::aclMat(int _rows, int _cols, int _type, aclCxt *_acl_context,
ALIGNMENT config, MemMallocPolicy policy)
: flags(0),
rows(0),
cols(0),
step(0),
data(nullptr),
refcount(nullptr),
datastart(nullptr),
dataend(nullptr),
offset(0),
wholerows(0),
wholecols(0),
acl_context(_acl_context),
totalSize(0) {
if (_rows > 0 && _cols > 0) create(_rows, _cols, _type, config, policy);
}
/**
* @param [in] _acl_context: Acl context
* @param [in] config: Byte aligned or not, Default MEMORY_UNALIGNED
* @param [in] policy: Acl Memory Application mode, Default ACL_MEM_MALLOC_NORMAL_ONLY
*/
inline aclMat::aclMat(int _rows, int _cols, int _type, aclCxt *_acl_context, ALIGNMENT config, MemMallocPolicy policy)
: flags(0), rows(0), cols(0), step(0), data(nullptr), refcount(nullptr), datastart(nullptr),
dataend(nullptr), offset(0), wholerows(0), wholecols(0), acl_context(_acl_context), totalSize(0)
{
if (_rows > 0 && _cols > 0)
create(_rows, _cols, _type, config, policy);
}
inline aclMat::aclMat(Size _size, int _type, aclCxt *_acl_context,
ALIGNMENT config, MemMallocPolicy policy)
: flags(0),
rows(0),
cols(0),
step(0),
data(nullptr),
refcount(nullptr),
datastart(nullptr),
dataend(nullptr),
offset(0),
wholerows(0),
wholecols(0),
acl_context(_acl_context),
totalSize(0) {
if (_size.height > 0 && _size.width > 0) create(_size, _type, config, policy);
}
inline aclMat::aclMat(Size _size, int _type, aclCxt *_acl_context, ALIGNMENT config, MemMallocPolicy policy)
: flags(0), rows(0), cols(0), step(0), data(nullptr), refcount(nullptr), datastart(nullptr),
dataend(nullptr), offset(0), wholerows(0), wholecols(0), acl_context(_acl_context), totalSize(0)
{
if (_size.height > 0 && _size.width > 0)
create(_size, _type, config, policy);
}
inline aclMat::aclMat(const aclMat &m)
: flags(m.flags),
rows(m.rows),
cols(m.cols),
step(m.step),
data(m.data),
refcount(m.refcount),
datastart(m.datastart),
dataend(m.dataend),
offset(m.offset),
wholerows(m.wholerows),
wholecols(m.wholecols),
acl_context(m.acl_context),
totalSize(m.totalSize) {
if (refcount) CV_XADD(refcount, 1);
}
inline aclMat::aclMat(const aclMat &m)
: flags(m.flags), rows(m.rows), cols(m.cols), step(m.step), data(m.data), refcount(m.refcount),
datastart(m.datastart), dataend(m.dataend), offset(m.offset), wholerows(m.wholerows), wholecols(m.wholecols),
acl_context(m.acl_context), totalSize(m.totalSize)
{
if (refcount)
CV_XADD(refcount, 1);
}
inline aclMat::aclMat(int _rows, int _cols, int _type, void *_data,
aclCxt *_acl_context, ALIGNMENT config, size_t _step)
: flags(0),
rows(0),
cols(0),
step(0),
data(nullptr),
refcount(nullptr),
datastart(nullptr),
dataend(nullptr),
offset(0),
wholerows(0),
wholecols(0),
acl_context(_acl_context),
totalSize(0) {
cv::Mat m(_rows, _cols, _type, _data, _step);
if (m.rows > 0 && m.cols > 0) create(m.rows, m.cols, m.type(), config);
upload(m, config);
}
inline aclMat::aclMat(int _rows, int _cols, int _type, void *_data, aclCxt *_acl_context, ALIGNMENT config, size_t _step)
: flags(0), rows(0), cols(0), step(0), data(nullptr), refcount(nullptr), datastart(nullptr),
dataend(nullptr), offset(0), wholerows(0), wholecols(0), acl_context(_acl_context), totalSize(0)
{
cv::Mat m(_rows, _cols, _type, _data, _step);
if (m.rows > 0 && m.cols > 0)
create(m.rows, m.cols, m.type(), config);
upload(m, config);
}
inline aclMat::aclMat(Size _size, int _type, void *_data, aclCxt *_acl_context,
ALIGNMENT config, size_t _step)
: flags(0),
rows(0),
cols(0),
step(0),
data(nullptr),
refcount(nullptr),
datastart(nullptr),
dataend(nullptr),
offset(0),
wholerows(0),
wholecols(0),
acl_context(_acl_context),
totalSize(0) {
cv::Mat m(_size, _type, _data, _step);
if (m.rows > 0 && m.cols > 0) create(m.rows, m.cols, m.type(), config);
upload(m, config);
}
inline aclMat::aclMat(Size _size, int _type, void *_data, aclCxt *_acl_context, ALIGNMENT config, size_t _step)
: flags(0), rows(0), cols(0), step(0), data(nullptr), refcount(nullptr), datastart(nullptr),
dataend(nullptr), offset(0), wholerows(0), wholecols(0), acl_context(_acl_context), totalSize(0)
{
cv::Mat m(_size, _type, _data, _step);
if (m.rows > 0 && m.cols > 0)
create(m.rows, m.cols, m.type(), config);
upload(m, config);
}
/**
* @param [in] rRange: rows begin to end, Range(start, end)
* @param [in] cRange: cols begin to end, Range(start, end)
*/
inline aclMat::aclMat(const aclMat &m, const Range &rRange, const Range &cRange)
: flags(m.flags),
step(m.step),
refcount(m.refcount),
datastart(m.datastart),
dataend(m.dataend),
offset(m.offset),
wholerows(m.wholerows),
wholecols(m.wholecols),
acl_context(m.acl_context),
totalSize(m.totalSize) {
if (rRange == Range::all())
rows = m.rows;
else {
CV_Assert(0 <= rRange.start && rRange.start <= rRange.end &&
rRange.end <= m.rows);
rows = rRange.size();
offset += step * rRange.start;
}
/**
* @param [in] rRange: rows begin to end, Range(start, end)
* @param [in] cRange: cols begin to end, Range(start, end)
*/
inline aclMat::aclMat(const aclMat &m, const Range &rRange, const Range &cRange)
: flags(m.flags), step(m.step), refcount(m.refcount), datastart(m.datastart), dataend(m.dataend),
offset(m.offset), wholerows(m.wholerows), wholecols(m.wholecols), acl_context(m.acl_context), totalSize(m.totalSize)
{
if (rRange == Range::all())
rows = m.rows;
else
{
CV_Assert(0 <= rRange.start && rRange.start <= rRange.end && rRange.end <= m.rows);
rows = rRange.size();
offset += step * rRange.start;
}
if (cRange == Range::all())
cols = m.cols;
else {
CV_Assert(0 <= cRange.start && cRange.start <= cRange.end &&
cRange.end <= m.cols);
cols = cRange.size();
offset += cRange.start * elemSize();
flags &= cols < m.cols ? ~Mat::CONTINUOUS_FLAG : -1;
}
if (cRange == Range::all())
cols = m.cols;
else
{
CV_Assert(0 <= cRange.start && cRange.start <= cRange.end && cRange.end <= m.cols);
cols = cRange.size();
offset += cRange.start * elemSize();
flags &= cols < m.cols ? ~Mat::CONTINUOUS_FLAG : -1;
}
if (rows == 1) flags |= Mat::CONTINUOUS_FLAG;
if (rows == 1)
flags |= Mat::CONTINUOUS_FLAG;
if (refcount) CV_XADD(refcount, 1);
if (rows <= 0 || cols <= 0) rows = cols = 0;
if (refcount)
CV_XADD(refcount, 1);
if (rows <= 0 || cols <= 0)
rows = cols = 0;
data = static_cast<void *>((static_cast<uchar *>(m.data) + offset));
}
data = static_cast<void *>((static_cast<uchar *>(m.data) + offset));
}
/**
* @param [in] roi: Matrix position, Rect(x, y, width, height)
*
*/
inline aclMat::aclMat(const aclMat &m, const Rect &roi)
: flags(m.flags),
rows(roi.height),
cols(roi.width),
step(m.step),
refcount(m.refcount),
datastart(m.datastart),
dataend(m.dataend),
offset(m.offset),
wholerows(m.wholerows),
wholecols(m.wholecols),
acl_context(m.acl_context),
totalSize(m.totalSize) {
flags &= roi.width < m.cols ? ~Mat::CONTINUOUS_FLAG : -1;
offset += roi.y * step + roi.x * elemSize();
CV_Assert(0 <= roi.x && 0 <= roi.width && roi.x + roi.width <= m.wholecols &&
0 <= roi.y && 0 <= roi.height && roi.y + roi.height <= m.wholerows);
if (refcount) CV_XADD(refcount, 1);
if (rows <= 0 || cols <= 0) rows = cols = 0;
/**
* @param [in] roi: Matrix position, Rect(x, y, width, height)
*
*/
inline aclMat::aclMat(const aclMat &m, const Rect &roi)
: flags(m.flags), rows(roi.height), cols(roi.width), step(m.step), refcount(m.refcount), datastart(m.datastart),
dataend(m.dataend), offset(m.offset), wholerows(m.wholerows), wholecols(m.wholecols), acl_context(m.acl_context),
totalSize(m.totalSize)
{
flags &= roi.width < m.cols ? ~Mat::CONTINUOUS_FLAG : -1;
offset += roi.y * step + roi.x * elemSize();
CV_Assert(0 <= roi.x && 0 <= roi.width && roi.x + roi.width <= m.wholecols &&
0 <= roi.y && 0 <= roi.height && roi.y + roi.height <= m.wholerows);
if (refcount)
CV_XADD(refcount, 1);
if (rows <= 0 || cols <= 0)
rows = cols = 0;
data = static_cast<void *>((static_cast<uchar *>(m.data) + offset));
}
data = static_cast<void *>((static_cast<uchar *>(m.data) + offset));
}
inline aclMat::aclMat(const Mat &m, aclCxt *_acl_context, ALIGNMENT config,
MemMallocPolicy policy)
: flags(0),
rows(m.rows),
cols(m.cols),
step(0),
data(nullptr),
refcount(nullptr),
datastart(nullptr),
dataend(nullptr),
offset(0),
wholerows(0),
wholecols(0),
acl_context(_acl_context),
totalSize(0) {
if (m.rows > 0 && m.cols > 0)
create(m.rows, m.cols, m.type(), config, policy);
upload(m, config);
}
inline aclMat::aclMat(const Mat &m, aclCxt *_acl_context, ALIGNMENT config, MemMallocPolicy policy)
: flags(0), rows(m.rows), cols(m.cols), step(0), data(nullptr), refcount(nullptr), datastart(nullptr),
dataend(nullptr), offset(0), wholerows(0), wholecols(0), acl_context(_acl_context), totalSize(0)
{
if (m.rows > 0 && m.cols > 0)
create(m.rows, m.cols, m.type(), config, policy);
upload(m, config);
}
inline aclMat::~aclMat() {
if (refcount) release();
}
inline aclMat::~aclMat()
{
if (refcount)
release();
}
inline aclMat &aclMat::operator=(const aclMat &m) {
if (this != &m) {
if (refcount) release();
flags = m.flags;
rows = m.rows;
cols = m.cols;
step = m.step;
datastart = m.datastart;
dataend = m.dataend;
offset = m.offset;
wholerows = m.wholerows;
wholecols = m.wholecols;
refcount = m.refcount;
acl_context = m.acl_context;
totalSize = m.totalSize;
data = m.data;
if (m.refcount) CV_XADD(m.refcount, 1);
}
return *this;
}
inline aclMat &aclMat::operator=(const aclMat &m)
{
if (this != &m)
{
if (refcount)
release();
flags = m.flags;
rows = m.rows;
cols = m.cols;
step = m.step;
datastart = m.datastart;
dataend = m.dataend;
offset = m.offset;
wholerows = m.wholerows;
wholecols = m.wholecols;
refcount = m.refcount;
acl_context = m.acl_context;
totalSize = m.totalSize;
data = m.data;
if (m.refcount)
CV_XADD(m.refcount, 1);
}
return *this;
}
inline aclMat &aclMat::operator=(const Mat &m) {
upload(m);
return *this;
}
inline aclMat& aclMat::operator=(const Mat &m)
{
upload(m);
return *this;
}
inline aclMat::operator Mat() const {
Mat m(rows, cols, type());
download(m);
return m;
}
inline aclMat::operator Mat() const
{
Mat m(rows, cols, type());
download(m);
return m;
}
inline aclMat aclMat::clone() const {
aclMat m;
copyTo(m);
return m;
}
inline aclMat aclMat::clone() const
{
aclMat m;
copyTo(m);
return m;
}
inline void aclMat::copyTo(aclMat &dest) const {
if (this != &dest) {
dest.rows = rows;
dest.cols = cols;
dest.step = step;
dest.wholerows = wholerows;
dest.wholecols = wholecols;
dest.refcount = refcount;
dest.acl_context = acl_context;
dest.totalSize = totalSize;
inline void aclMat::copyTo(aclMat& dest) const
{
if (this != &dest)
{
dest.rows = rows;
dest.cols = cols;
dest.step = step;
dest.wholerows = wholerows;
dest.wholecols = wholecols;
dest.refcount = refcount;
dest.acl_context = acl_context;
dest.totalSize = totalSize;
void *dev_ptr;
AclSafeCall(
aclrtMalloc(&dev_ptr, totalSize, type_transition(MALLOC_NORMAL_ONLY)));
AclSafeCall(aclrtMemcpy(dev_ptr, totalSize, data, totalSize,
ACL_MEMCPY_DEVICE_TO_DEVICE));
void *dev_ptr;
AclSafeCall(aclrtMalloc(&dev_ptr, totalSize, type_transition(MALLOC_NORMAL_ONLY)));
AclSafeCall(aclrtMemcpy(dev_ptr, totalSize, data, totalSize, ACL_MEMCPY_DEVICE_TO_DEVICE));
dest.data = dev_ptr;
dest.datastart = static_cast<uchar *>(data);
dest.dataend = static_cast<uchar *>(data) + totalSize;
dest.refcount = static_cast<int *>(fastMalloc(sizeof(*refcount)));
*refcount = 0;
CV_XADD(refcount, 1);
dest.flags |= Mat::CONTINUOUS_FLAG;
}
}
dest.data = dev_ptr;
dest.datastart = static_cast<uchar *>(data);
dest.dataend = static_cast<uchar *>(data) + totalSize;
dest.refcount = static_cast<int *>(fastMalloc(sizeof(*refcount)));
*refcount = 0;
CV_XADD(refcount, 1);
dest.flags |= Mat::CONTINUOUS_FLAG;
}
}
inline aclMat aclMat::row(int y) const {
return aclMat(*this, Range(y, y + 1), Range::all());
}
inline aclMat aclMat::row(int y) const
{
return aclMat(*this, Range(y, y + 1), Range::all());
}
inline aclMat aclMat::col(int x) const {
return aclMat(*this, Range::all(), Range(x, x + 1));
}
inline aclMat aclMat::col(int x) const
{
return aclMat(*this, Range::all(), Range(x, x + 1));
}
inline aclMat aclMat::rowRange(int startrow, int endrow) const {
return aclMat(*this, Range(startrow, endrow), Range::all());
}
inline aclMat aclMat::rowRange(int startrow, int endrow) const
{
return aclMat(*this, Range(startrow, endrow), Range::all());
}
inline aclMat aclMat::rowRange(const Range &r) const {
return aclMat(*this, r, Range::all());
}
inline aclMat aclMat::rowRange(const Range &r) const
{
return aclMat(*this, r, Range::all());
}
inline aclMat aclMat::colRange(int startcol, int endcol) const {
return aclMat(*this, Range::all(), Range(startcol, endcol));
}
inline aclMat aclMat::colRange(int startcol, int endcol) const
{
return aclMat(*this, Range::all(), Range(startcol, endcol));
}
inline aclMat aclMat::colRange(const Range &r) const {
return aclMat(*this, Range::all(), r);
}
inline aclMat aclMat::colRange(const Range &r) const
{
return aclMat(*this, Range::all(), r);
}
inline void aclMat::locateROI(Size &wholeSize, Point &ofs) const {
size_t esz = elemSize();
CV_DbgAssert(step > 0);
if (offset == 0)
ofs.x = ofs.y = 0;
else {
ofs.y = (int)(offset / step);
ofs.x = (int)((offset - step * ofs.y) / esz);
CV_DbgAssert(data == (datastart + ofs.y * step + ofs.x * esz));
}
wholeSize.height = wholerows;
wholeSize.width = wholecols;
}
inline void aclMat::locateROI( Size &wholeSize, Point &ofs ) const
{
size_t esz = elemSize();
CV_DbgAssert(step > 0);
if(offset == 0)
ofs.x = ofs.y = 0;
else
{
ofs.y = (int)(offset / step);
ofs.x = (int)((offset - step * ofs.y) / esz);
CV_DbgAssert(data == (datastart + ofs.y * step + ofs.x * esz));
}
wholeSize.height = wholerows;
wholeSize.width = wholecols;
}
inline aclMat &aclMat::adjustROI(int dtop, int dbottom, int dleft, int dright) {
Size wholeSize;
Point ofs;
size_t esz = elemSize();
locateROI(wholeSize, ofs);
int row1 = std::max(ofs.y - dtop, 0),
row2 = std::min(ofs.y + rows + dbottom, wholeSize.height);
int col1 = std::max(ofs.x - dleft, 0),
col2 = std::min(ofs.x + cols + dright, wholeSize.width);
offset += (row1 - ofs.y) * step + (col1 - ofs.x) * esz;
rows = row2 - row1;
cols = col2 - col1;
if (esz * cols == step || rows == 1)
flags |= Mat::CONTINUOUS_FLAG;
else
flags &= ~Mat::CONTINUOUS_FLAG;
inline aclMat &aclMat::adjustROI( int dtop, int dbottom, int dleft, int dright )
{
Size wholeSize;
Point ofs;
size_t esz = elemSize();
locateROI( wholeSize, ofs );
int row1 = std::max(ofs.y - dtop, 0), row2 = std::min(ofs.y + rows + dbottom, wholeSize.height);
int col1 = std::max(ofs.x - dleft, 0), col2 = std::min(ofs.x + cols + dright, wholeSize.width);
offset += (row1 - ofs.y) * step + (col1 - ofs.x) * esz;
rows = row2 - row1;
cols = col2 - col1;
if( esz * cols == step || rows == 1 )
flags |= Mat::CONTINUOUS_FLAG;
else
flags &= ~Mat::CONTINUOUS_FLAG;
data = static_cast<void *>((static_cast<uchar *>(datastart) + offset));
return *this;
}
data = static_cast<void *>((static_cast<uchar *>(datastart) + offset));
return *this;
}
inline void aclMat::swap(aclMat &b)
{
std::swap( flags, b.flags );
std::swap( rows, b.rows );
std::swap( cols, b.cols );
std::swap( step, b.step );
std::swap( data, b.data );
std::swap( datastart, b.datastart );
std::swap( dataend, b.dataend );
std::swap( refcount, b.refcount );
std::swap( offset, b.offset );
std::swap( wholerows, b.wholerows );
std::swap( wholecols, b.wholecols );
std::swap( acl_context, b.acl_context);
std::swap( totalSize, b.totalSize);
}
inline void aclMat::swap(aclMat &b) {
std::swap(flags, b.flags);
std::swap(rows, b.rows);
std::swap(cols, b.cols);
std::swap(step, b.step);
std::swap(data, b.data);
std::swap(datastart, b.datastart);
std::swap(dataend, b.dataend);
std::swap(refcount, b.refcount);
std::swap(offset, b.offset);
std::swap(wholerows, b.wholerows);
std::swap(wholecols, b.wholecols);
std::swap(acl_context, b.acl_context);
std::swap(totalSize, b.totalSize);
}
inline aclMat aclMat::operator()( Range rRange, Range cRange ) const
{
return aclMat(*this, rRange, cRange);
}
inline aclMat aclMat::operator()(Range rRange, Range cRange) const {
return aclMat(*this, rRange, cRange);
}
inline aclMat aclMat::operator()( const Rect &roi ) const
{
return aclMat(*this, roi);
}
inline aclMat aclMat::operator()(const Rect &roi) const {
return aclMat(*this, roi);
}
inline bool aclMat::isContinuous() const
{
return (flags & Mat::CONTINUOUS_FLAG) != 0;
}
inline bool aclMat::isContinuous() const {
return (flags & Mat::CONTINUOUS_FLAG) != 0;
}
inline size_t aclMat::elemSize() const
{
return CV_ELEM_SIZE((CV_MAKE_TYPE(type(), channels())));
}
inline size_t aclMat::elemSize() const {
return CV_ELEM_SIZE((CV_MAKE_TYPE(type(), channels())));
}
inline size_t aclMat::elemSize1() const
{
return CV_ELEM_SIZE1(flags);
}
inline size_t aclMat::elemSize1() const { return CV_ELEM_SIZE1(flags); }
inline int aclMat::type() const
{
return CV_MAT_TYPE(flags);
}
inline int aclMat::type() const { return CV_MAT_TYPE(flags); }
inline int aclMat::acltype() const
{
return CV_MAKE_TYPE(depth(), aclchannels());
}
inline int aclMat::acltype() const {
return CV_MAKE_TYPE(depth(), aclchannels());
}
inline int aclMat::depth() const
{
return CV_MAT_DEPTH(flags);
}
inline int aclMat::depth() const { return CV_MAT_DEPTH(flags); }
inline int aclMat::channels() const
{
return CV_MAT_CN(flags);
}
inline int aclMat::channels() const { return CV_MAT_CN(flags); }
inline int aclMat::aclchannels() const
{
return (CV_MAT_CN(flags)) == 3 ? 4 : (CV_MAT_CN(flags));
}
inline int aclMat::aclchannels() const {
return (CV_MAT_CN(flags)) == 3 ? 4 : (CV_MAT_CN(flags));
}
inline size_t aclMat::step1() const
{
return step / elemSize1();
}
inline size_t aclMat::step1() const { return step / elemSize1(); }
inline Size aclMat::size() const
{
return Size(cols, rows);
}
inline Size aclMat::size() const { return Size(cols, rows); }
inline bool aclMat::empty() const
{
return data == 0;
}
inline bool aclMat::empty() const { return data == 0; }
inline void swap( aclMat &a, aclMat &b )
{
a.swap(b);
}
inline void swap(aclMat &a, aclMat &b) { a.swap(b); }
inline void ensureSizeIsEnough(int rows, int cols, int type, aclMat &m, ALIGNMENT config)
{
if (m.type() == type && m.rows >= rows && m.cols >= cols)
m = m(Rect(0, 0, cols, rows));
else
m.create(rows, cols, type, config);
}
inline void ensureSizeIsEnough(int rows, int cols, int type, aclMat &m,
ALIGNMENT config) {
if (m.type() == type && m.rows >= rows && m.cols >= cols)
m = m(Rect(0, 0, cols, rows));
else
m.create(rows, cols, type, config);
}
inline void ensureSizeIsEnough(Size size, int type, ALIGNMENT config, aclMat &m)
{
ensureSizeIsEnough(size.height, size.width, type, m, config);
}
inline void ensureSizeIsEnough(Size size, int type, ALIGNMENT config,
aclMat &m) {
ensureSizeIsEnough(size.height, size.width, type, m, config);
}
} /* end of namespace acl */
} /* end of namespace acl */
} /* end of namespace cv */

View File

@@ -1,4 +1,4 @@
#ifndef OPENCV_MATHFUNCS_HPP
#ifndef OPENCV_MATHFUNCS_HPP
#define OPENCV_MATHFUNCS_HPP
#include "acl_mat.hpp"
@@ -7,20 +7,23 @@
* mathfunctions;
*/
namespace cv
{
namespace acl
{
CV_EXPORTS aclMat abs(const aclMat &src, int stream_id = 0);
CV_EXPORTS void pow(const aclMat &src, double power, aclMat &dest, int stream_id = 0);
CV_EXPORTS void sqrt(const aclMat &src, aclMat &dest, int stream_id = 0);
CV_EXPORTS void add(const aclMat &src, const aclMat &other_src, aclMat &dest, int stream_id = 0);
CV_EXPORTS void divide(const aclMat &src, const aclMat &other_src, aclMat &dest, int stream_id = 0);
CV_EXPORTS void exp(const aclMat &src, aclMat &dest, int stream_id = 0);
CV_EXPORTS void log(const aclMat &src, aclMat &dest, int stream_id = 0);
CV_EXPORTS void max(const aclMat &src, const aclMat &other_src, aclMat &dest, int stream_id = 0);
CV_EXPORTS void min(const aclMat &src, const aclMat &other_src, aclMat &dest, int stream_id = 0);
} /* end of namespace acl */
namespace cv {
namespace acl {
CV_EXPORTS aclMat abs(const aclMat &src, int stream_id = 0);
CV_EXPORTS void pow(const aclMat &src, double power, aclMat &dest,
int stream_id = 0);
CV_EXPORTS void sqrt(const aclMat &src, aclMat &dest, int stream_id = 0);
CV_EXPORTS void add(const aclMat &src, const aclMat &other_src, aclMat &dest,
int stream_id = 0);
CV_EXPORTS void divide(const aclMat &src, const aclMat &other_src, aclMat &dest,
int stream_id = 0);
CV_EXPORTS void exp(const aclMat &src, aclMat &dest, int stream_id = 0);
CV_EXPORTS void log(const aclMat &src, aclMat &dest, int stream_id = 0);
CV_EXPORTS void max(const aclMat &src, const aclMat &other_src, aclMat &dest,
int stream_id = 0);
CV_EXPORTS void min(const aclMat &src, const aclMat &other_src, aclMat &dest,
int stream_id = 0);
} /* end of namespace acl */
} /* end of namespace cv */

View File

@@ -1,22 +1,19 @@
#ifndef OPENCV_MATRICES_HPP
#ifndef OPENCV_MATRICES_HPP
#define OPENCV_MATRICES_HPP
#include "acl_mat.hpp"
namespace cv
{
namespace acl
{
// Matrix lookup table
//CV_EXPORTS void lookUpTable(const aclMat& src, const aclMat& lut, aclMat& dst);
// Multiple channel merge
CV_EXPORTS void merge(const vector<aclMat>& mv, aclMat& dst, int stream_id = 0);
// Split into channels
CV_EXPORTS void split(const aclMat& src, vector<aclMat>& mv, int stream_id = 0);
// Matrix transpose
CV_EXPORTS void transpose(const aclMat& src, aclMat& dest, int stream_id = 0);
CV_EXPORTS void flip(const aclMat& src, aclMat& dest, int flipCode = 0, int stream_id = 0);
} /* end of namespace acl */
namespace cv {
namespace acl {
// Multiple channel merge
CV_EXPORTS void merge(const std::vector<aclMat> &mv, aclMat &dst, int stream_id = 0);
// Split into channels
CV_EXPORTS void split(const aclMat &src, std::vector<aclMat> &mv, int stream_id = 0);
// Matrix transpose
CV_EXPORTS void transpose(const aclMat &src, aclMat &dest, int stream_id = 0);
CV_EXPORTS void flip(const aclMat &src, aclMat &dest, int flipCode = 0,
int stream_id = 0);
} /* end of namespace acl */
} /* end of namespace cv */

View File

@@ -4,90 +4,96 @@
#include <string>
#include <vector>
#include "acl_type.hpp"
#include "acl/acl.h"
#include "acl_init.hpp"
#include "acl_mat.hpp"
#include "acl/acl.h"
#include "acl_type.hpp"
namespace cv
{
namespace acl
{
class CV_EXPORTS OperatorDesc
{
public:
/**
* Constructor
* @param [in] opType: op type
*/
OperatorDesc(std::string opType);
namespace cv {
namespace acl {
class CV_EXPORTS OperatorDesc {
public:
/**
* Constructor
* @param [in] opType: op type
*/
OperatorDesc(std::string opType);
/**
* Destructor
*/
virtual ~OperatorDesc();
/**
* Destructor
*/
virtual ~OperatorDesc();
/**
* Add an input tensor description
* @param [in] dataType: data type
* @param [in] numDims: number of dims
* @param [in] dims: dims
* @param [in] format: format
* @return OperatorDesc
*/
OperatorDesc &AddInputTensorDesc(aclDataType dataType, int numDims, const int64_t *dims, aclFormat format);
/**
* Add an input tensor description
* @param [in] dataType: data type
* @param [in] numDims: number of dims
* @param [in] dims: dims
* @param [in] format: format
* @return OperatorDesc
*/
OperatorDesc &AddInputTensorDesc(aclDataType dataType, int numDims,
const int64_t *dims, aclFormat format);
/**
* Add an output tensor description
* @param [in] dataType: data type
* @param [in] numDims: number of dims
* @param [in] dims: dims
* @param [in] format: format
* @return OperatorDesc
*/
OperatorDesc &AddOutputTensorDesc(aclDataType dataType, int numDims, const int64_t *dims, aclFormat format);
/**
* Add an output tensor description
* @param [in] dataType: data type
* @param [in] numDims: number of dims
* @param [in] dims: dims
* @param [in] format: format
* @return OperatorDesc
*/
OperatorDesc &AddOutputTensorDesc(aclDataType dataType, int numDims,
const int64_t *dims, aclFormat format);
template <typename T>
bool AddTensorAttr(const char *attrName, AttrType type, T vaule)
{
if (opAttr == nullptr)
return false;
switch (type)
{
case OP_BOOL:
aclopSetAttrBool(opAttr, attrName, vaule);
break;
case OP_INT:
aclopSetAttrInt(opAttr, attrName, vaule);
break;
case OP_FLOAT:
aclopSetAttrFloat(opAttr, attrName, vaule);
break;
default:
break;
}
return true;
}
std::string opType;
std::vector<aclTensorDesc *> inputDesc;
std::vector<aclTensorDesc *> outputDesc;
aclopAttr *opAttr;
};
template <typename T>
bool AddTensorAttr(const char *attrName, AttrType type, T vaule) {
if (opAttr == nullptr) return false;
switch (type) {
case OP_BOOL:
aclopSetAttrBool(opAttr, attrName, vaule);
break;
case OP_INT:
aclopSetAttrInt(opAttr, attrName, vaule);
break;
case OP_FLOAT:
aclopSetAttrFloat(opAttr, attrName, vaule);
break;
default:
break;
}
return true;
}
std::string opType;
std::vector<aclTensorDesc *> inputDesc;
std::vector<aclTensorDesc *> outputDesc;
aclopAttr *opAttr;
};
// Create operator description
CV_EXPORTS OperatorDesc CreateOpDesc(const string opType, const vector<aclMat> &input_Mat, vector<aclMat> &output_Mat, aclFormat format = ACL_FORMAT_NHWC, Opdims config = FOUR_DIMS);
// Compile and run the operator
CV_EXPORTS void compileAndRunop(OperatorDesc &opDesc, vector<aclDataBuffer *> &inputBuffers_, vector<aclDataBuffer *> &outputBuffers_, aclCxt *acl_context, int stream_id);
// Suitable for one input and one output
CV_EXPORTS void OneInAndOneOut(const aclMat &input, aclMat &output, const string opType, int stream_id = 0);
// Suitable for tow input and one output
CV_EXPORTS void TwoInAndOneOut(const aclMat &inputMat, const aclMat &inputMatOther, aclMat &outputMat, const string opType, int stream_id = 0);
// run the operator
CV_EXPORTS void Runop(vector<aclMat> &input, vector<aclMat> &output, OperatorDesc &opDesc, int stream_id);
// Create operator description
CV_EXPORTS OperatorDesc CreateOpDesc(const std::string opType,
const std::vector<aclMat> &input_Mat,
std::vector<aclMat> &output_Mat,
aclFormat format = ACL_FORMAT_NHWC,
Opdims config = FOUR_DIMS);
// Compile and run the operator
CV_EXPORTS void compileAndRunop(OperatorDesc &opDesc,
std::vector<aclDataBuffer *> &inputBuffers_,
std::vector<aclDataBuffer *> &outputBuffers_,
aclCxt *acl_context, int stream_id);
// Suitable for one input and one output
CV_EXPORTS void OneInAndOneOut(const aclMat &input, aclMat &output,
const std::string opType, int stream_id = 0);
// Suitable for tow input and one output
CV_EXPORTS void TwoInAndOneOut(const aclMat &inputMat,
const aclMat &inputMatOther, aclMat &outputMat,
const std::string opType, int stream_id = 0);
// run the operator
CV_EXPORTS void Runop(std::vector<aclMat> &input, std::vector<aclMat> &output,
OperatorDesc &opDesc, int stream_id);
} /* end of namespace acl */
} /* end of namespace acl */
} /* end of namespace cv */
#endif // OPERATOR_DESC_HPP
#endif // OPERATOR_DESC_HPP

View File

@@ -1,8 +1,9 @@
/*M///////////////////////////////////////////////////////////////////////////////////////
/* M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// By downloading, copying, installing or using the software you agree to this
license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
@@ -10,28 +11,35 @@
// License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2010-2012, Institute Of Software Chinese Academy Of Science, all rights reserved.
// Copyright (C) 2010-2012, Institute Of Software Chinese Academy Of Science,
all rights reserved.
// Copyright (C) 2010-2012, Advanced Micro Devices, Inc., all rights reserved.
// Copyright (C) 2010-2012, Multicoreware, Inc., all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// Redistribution and use in source and binary forms, with or without
modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// * Redistribution's in binary form must reproduce the above copyright
notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of the copyright holders may not be used to endorse or promote products
// * The name of the copyright holders may not be used to endorse or promote
products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// This software is provided by the copyright holders and contributors "as is"
and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// warranties of merchantability and fitness for a particular purpose are
disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any
direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
@@ -39,85 +47,74 @@
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
//M */
#include "precomp.hpp"
using namespace std;
using namespace cv;
using namespace cv::acl;
namespace cv {
namespace acl {
///////////////////////////aclEnv//////////////////////////////////
static Mutex *__initmutex = NULL;
Mutex &getInitMutex() {
if (__initmutex == NULL) __initmutex = new Mutex();
return *__initmutex;
}
aclEnv *global_aclenv = nullptr;
aclEnv *aclEnv::get_acl_env(const char *config_path) {
if (nullptr == global_aclenv) {
AutoLock lock(getInitMutex());
if (nullptr == global_aclenv) global_aclenv = new aclEnv(config_path);
}
return global_aclenv;
}
namespace cv
{
namespace acl
{
///////////////////////////aclEnv//////////////////////////////////
static Mutex *__initmutex = NULL;
Mutex &getInitMutex()
{
if (__initmutex == NULL)
__initmutex = new Mutex();
return *__initmutex;
}
void wait_stream(aclCxt *acl_context, const int stream_id) {
aclrtSynchronizeStream(acl_context->get_stream(stream_id));
}
aclEnv *global_aclenv = nullptr;
aclEnv* aclEnv::get_acl_env(const char* config_path)
{
if (nullptr == global_aclenv)
{
AutoLock lock(getInitMutex());
if (nullptr == global_aclenv)
global_aclenv = new aclEnv(config_path);
}
return global_aclenv;
}
/////////////////////////create acl context////////////////////////
/**
* @brief: set device and stream
* @param [in] config_path: ajson path
* @param [in] device_id: device id
* @param [in] stream_count: stream count
*/
aclCxt *set_device(const char *config_path, int device_id, int stream_count) {
aclEnv *acl_env = aclEnv::get_acl_env(config_path);
if (global_aclenv->refcount) {
AutoLock lock(getInitMutex());
CV_XADD(global_aclenv->refcount, 1);
}
int device_count = acl_env->get_device_count();
CV_Assert(device_id < device_count);
void wait_stream(aclCxt * acl_context, const int stream_id)
{
aclrtSynchronizeStream(acl_context->get_stream(stream_id));
}
aclCxt *acl_context = new aclCxt(device_id);
acl_context->set_current_context();
acl_context->create_stream(stream_count);
/////////////////////////create acl context////////////////////////
/**
* @brief: set device and stream
* @param [in] config_path: ajson path
* @param [in] device_id: device id
* @param [in] stream_count: stream count
*/
aclCxt *set_device(const char* config_path, int device_id, int stream_count)
{
aclEnv *acl_env = aclEnv::get_acl_env(config_path);
if (global_aclenv->refcount) {
AutoLock lock(getInitMutex());
CV_XADD(global_aclenv->refcount, 1);
}
int device_count = acl_env->get_device_count();
CV_Assert(device_id < device_count);
clog << "set_device() is success" << endl;
return acl_context;
}
aclCxt *acl_context = new aclCxt(device_id);
acl_context->set_current_context();
acl_context->create_stream(stream_count);
void release_device(aclCxt *context) {
CV_Assert(context);
delete context;
context = nullptr;
if (global_aclenv->refcount) {
AutoLock lock(getInitMutex());
CV_XADD(global_aclenv->refcount, -1);
clog << "set_device() is success" << endl;
return acl_context;
}
if (*(global_aclenv->refcount) == 0) {
delete global_aclenv;
global_aclenv = nullptr;
}
}
clog << "release_device() is success" << endl;
}
void release_device(aclCxt* context)
{
CV_Assert(context);
delete context;
context = nullptr;
if (global_aclenv->refcount)
{
AutoLock lock(getInitMutex());
CV_XADD(global_aclenv->refcount, -1);
if (*(global_aclenv->refcount) == 0)
{
delete global_aclenv;
global_aclenv = nullptr;
}
}
clog << "release_device() is success" << endl;
}
} /* end of namespace acl */
} /* end of namespace acl */
} /* end of namespace cv */

View File

@@ -1,216 +1,213 @@
#include "precomp.hpp"
#define ALIGN 64
namespace cv
{
namespace acl
{
/* Memory alignment */
static inline size_t alignSize(size_t sz, int n = ALIGN);
void aclMat::upload(const Mat &m, ALIGNMENT config)
{
CV_Assert((config == ALIGNMENT::MEMORY_ALIGN) || (config == ALIGNMENT::MEMORY_UNALIGNED));
if (config == ALIGNMENT::MEMORY_UNALIGNED)
{
CV_Assert(m.data && (this->step == m.step) && (this->rows == m.rows) && (this->cols == m.cols) && (this->type() == m.type()));
aclrtMemcpy((void *)this->data, (m.step * m.rows), (void *)m.data, (m.step * m.rows), ACL_MEMCPY_HOST_TO_DEVICE);
}
else if (config == ALIGNMENT::MEMORY_ALIGN)
{
CV_Assert(m.data && (this->rows == m.rows) && (this->cols == m.cols) && (this->type() == m.type()));
aclrtMemcpy2d((void *)this->data, this->step, (void *)m.data, m.step, m.cols * m.elemSize(), m.rows, ACL_MEMCPY_HOST_TO_DEVICE);
}
}
using namespace std;
using namespace cv;
using namespace cv::acl;
namespace cv {
namespace acl {
/* Memory alignment */
static inline size_t alignSize(size_t sz, int n = ALIGN);
void aclMat::upload(const Mat &m, aclStream stream, ALIGNMENT config)
{
CV_Assert((config == ALIGNMENT::MEMORY_ALIGN) || (config == ALIGNMENT::MEMORY_UNALIGNED));
if (config == ALIGNMENT::MEMORY_UNALIGNED)
{
CV_Assert(m.data && (this->step == m.step) && (this->rows == m.rows) && (this->cols == m.cols) && (this->type() == m.type()));
aclrtMemcpyAsync((void *)this->data, this->totalSize, (void *)m.data, (m.step * m.rows), ACL_MEMCPY_HOST_TO_DEVICE, stream);
}
else if (config == ALIGNMENT::MEMORY_ALIGN)
{
CV_Assert(m.data && (this->rows == m.rows) && (this->cols == m.cols) && (this->type() == m.type()));
aclrtMemcpy2dAsync((void *)this->data, this->step, (void *)m.data, m.step, m.cols * m.elemSize(), m.rows, ACL_MEMCPY_HOST_TO_DEVICE, stream);
}
AclSafeCall(aclrtSynchronizeStream(stream));
}
void aclMat::upload(const Mat &m, ALIGNMENT config) {
CV_Assert((config == ALIGNMENT::MEMORY_ALIGN) ||
(config == ALIGNMENT::MEMORY_UNALIGNED));
if (config == ALIGNMENT::MEMORY_UNALIGNED) {
CV_Assert(m.data && (this->step == m.step) && (this->rows == m.rows) &&
(this->cols == m.cols) && (this->type() == m.type()));
aclrtMemcpy((void *)this->data, (m.step * m.rows), (void *)m.data,
(m.step * m.rows), ACL_MEMCPY_HOST_TO_DEVICE);
} else if (config == ALIGNMENT::MEMORY_ALIGN) {
CV_Assert(m.data && (this->rows == m.rows) && (this->cols == m.cols) &&
(this->type() == m.type()));
aclrtMemcpy2d((void *)this->data, this->step, (void *)m.data, m.step,
m.cols * m.elemSize(), m.rows, ACL_MEMCPY_HOST_TO_DEVICE);
}
}
void aclMat::upload(const Mat &m, aclStream stream, ALIGNMENT config) {
CV_Assert((config == ALIGNMENT::MEMORY_ALIGN) ||
(config == ALIGNMENT::MEMORY_UNALIGNED));
if (config == ALIGNMENT::MEMORY_UNALIGNED) {
CV_Assert(m.data && (this->step == m.step) && (this->rows == m.rows) &&
(this->cols == m.cols) && (this->type() == m.type()));
aclrtMemcpyAsync((void *)this->data, this->totalSize, (void *)m.data,
(m.step * m.rows), ACL_MEMCPY_HOST_TO_DEVICE, stream);
} else if (config == ALIGNMENT::MEMORY_ALIGN) {
CV_Assert(m.data && (this->rows == m.rows) && (this->cols == m.cols) &&
(this->type() == m.type()));
aclrtMemcpy2dAsync((void *)this->data, this->step, (void *)m.data, m.step,
m.cols * m.elemSize(), m.rows, ACL_MEMCPY_HOST_TO_DEVICE,
stream);
}
AclSafeCall(aclrtSynchronizeStream(stream));
}
void aclMat::download(Mat &m, ALIGNMENT config) const
{
CV_Assert((config == ALIGNMENT::MEMORY_ALIGN) || (config == ALIGNMENT::MEMORY_UNALIGNED));
if (config == ALIGNMENT::MEMORY_UNALIGNED)
{
CV_Assert(m.data && (this->step == m.step) && (this->rows == m.rows) && (this->cols == m.cols) && (this->type() == m.type()));
aclrtMemcpy((void *)m.data, (m.step * m.rows), (void *)(this->data), (m.step * m.rows), ACL_MEMCPY_DEVICE_TO_HOST);
}
else if (config == ALIGNMENT::MEMORY_ALIGN)
{
CV_Assert(m.data && (this->rows == m.rows) && (this->cols == m.cols) && (this->type() == m.type()));
aclrtMemcpy2d((void *)m.data, m.step, (void *)(this->data), this->step, this->cols * this->elemSize(), this->rows, ACL_MEMCPY_DEVICE_TO_HOST);
}
return;
}
void aclMat::download(Mat &m, ALIGNMENT config) const {
CV_Assert((config == ALIGNMENT::MEMORY_ALIGN) ||
(config == ALIGNMENT::MEMORY_UNALIGNED));
if (config == ALIGNMENT::MEMORY_UNALIGNED) {
CV_Assert(m.data && (this->step == m.step) && (this->rows == m.rows) &&
(this->cols == m.cols) && (this->type() == m.type()));
aclrtMemcpy((void *)m.data, (m.step * m.rows), (void *)(this->data),
(m.step * m.rows), ACL_MEMCPY_DEVICE_TO_HOST);
} else if (config == ALIGNMENT::MEMORY_ALIGN) {
CV_Assert(m.data && (this->rows == m.rows) && (this->cols == m.cols) &&
(this->type() == m.type()));
aclrtMemcpy2d((void *)m.data, m.step, (void *)(this->data), this->step,
this->cols * this->elemSize(), this->rows,
ACL_MEMCPY_DEVICE_TO_HOST);
}
return;
}
void aclMat::download(Mat &m, aclStream stream, ALIGNMENT config) const
{
CV_Assert((config == ALIGNMENT::MEMORY_ALIGN) || (config == ALIGNMENT::MEMORY_UNALIGNED));
if (config == ALIGNMENT::MEMORY_UNALIGNED)
{
CV_Assert(m.data && (this->step == m.step) && (this->rows == m.rows) && (this->cols == m.cols) && (this->type() == m.type()));
aclrtMemcpyAsync((void *)m.data, (m.step * m.rows), (void *)(this->data), this->totalSize, ACL_MEMCPY_DEVICE_TO_HOST, stream);
}
else if (config == ALIGNMENT::MEMORY_ALIGN)
{
CV_Assert(m.data && (this->rows == m.rows) && (this->cols == m.cols) && (this->type() == m.type()));
aclrtMemcpy2dAsync((void *)m.data, m.step, (void *)(this->data), this->step, this->cols * this->elemSize(), this->rows, ACL_MEMCPY_DEVICE_TO_HOST, stream);
}
AclSafeCall(aclrtSynchronizeStream(stream));
return;
}
void aclMat::download(Mat &m, aclStream stream, ALIGNMENT config) const {
CV_Assert((config == ALIGNMENT::MEMORY_ALIGN) ||
(config == ALIGNMENT::MEMORY_UNALIGNED));
if (config == ALIGNMENT::MEMORY_UNALIGNED) {
CV_Assert(m.data && (this->step == m.step) && (this->rows == m.rows) &&
(this->cols == m.cols) && (this->type() == m.type()));
aclrtMemcpyAsync((void *)m.data, (m.step * m.rows), (void *)(this->data),
this->totalSize, ACL_MEMCPY_DEVICE_TO_HOST, stream);
} else if (config == ALIGNMENT::MEMORY_ALIGN) {
CV_Assert(m.data && (this->rows == m.rows) && (this->cols == m.cols) &&
(this->type() == m.type()));
aclrtMemcpy2dAsync((void *)m.data, m.step, (void *)(this->data), this->step,
this->cols * this->elemSize(), this->rows,
ACL_MEMCPY_DEVICE_TO_HOST, stream);
}
AclSafeCall(aclrtSynchronizeStream(stream));
return;
}
void aclMat::create(int _rows, int _cols, int _type, ALIGNMENT config, MemMallocPolicy policy)
{
createEx(_rows, _cols, _type, config, policy);
}
void aclMat::create(int _rows, int _cols, int _type, ALIGNMENT config,
MemMallocPolicy policy) {
createEx(_rows, _cols, _type, config, policy);
}
void aclMat::create(Size size, int type, ALIGNMENT config, MemMallocPolicy policy)
{
createEx(size, type, config, policy);
}
void aclMat::create(Size size, int type, ALIGNMENT config,
MemMallocPolicy policy) {
createEx(size, type, config, policy);
}
inline size_t alignSize(size_t sz, int n)
{
return (((sz) + n - 1) / n ) * n;
}
inline size_t alignSize(size_t sz, int n) { return (((sz) + n - 1) / n) * n; }
/* core logic */
void aclMat::createEx(int _rows, int _cols, int _type, ALIGNMENT config, MemMallocPolicy policy)
{
/* TO ENSURE */
//_type &= CV_MAT_TYPE_MASK;
_type &= TYPE_MASK;
if (rows == _rows && cols == _cols && type() == _type && data)
return;
/* core logic */
void aclMat::createEx(int _rows, int _cols, int _type, ALIGNMENT config,
MemMallocPolicy policy) {
/* TO ENSURE */
//_type &= CV_MAT_TYPE_MASK;
_type &= TYPE_MASK;
if (rows == _rows && cols == _cols && type() == _type && data) return;
if (data)
release();
CV_DbgAssert(_rows >= 0 && _cols >= 0);
if (data) release();
if (_rows > 0 && _cols > 0)
{
/* TO ENSURE */
//flags = (_type & CV_MAT_TYPE_MASK) | MAGIC_VAL;
flags = Mat::MAGIC_VAL + _type;
rows = _rows;
cols = _cols;
wholerows = _rows;
wholecols = _cols;
size_t esz = elemSize();
void *dev_ptr;
if (config == ALIGNMENT::MEMORY_ALIGN)
{
if (channels() == 3)
step = alignSize(cols * esz, ALIGN * channels());
else
step = alignSize(cols * esz);
}
else
step = cols * esz;
totalSize = step * rows;
CV_DbgAssert(_rows >= 0 && _cols >= 0);
AclSafeCall(aclrtMalloc(&dev_ptr, totalSize, type_transition(policy)));
if (_rows > 0 && _cols > 0) {
/* TO ENSURE */
// flags = (_type & CV_MAT_TYPE_MASK) | MAGIC_VAL;
flags = Mat::MAGIC_VAL + _type;
rows = _rows;
cols = _cols;
wholerows = _rows;
wholecols = _cols;
size_t esz = elemSize();
void *dev_ptr;
if (config == ALIGNMENT::MEMORY_ALIGN) {
if (channels() == 3)
step = alignSize(cols * esz, ALIGN * channels());
else
step = alignSize(cols * esz);
} else
step = cols * esz;
totalSize = step * rows;
data = dev_ptr;
datastart = static_cast<uchar *>(data);
dataend = static_cast<uchar *>(data) + totalSize;
refcount = static_cast<int *>(fastMalloc(sizeof(*refcount)));
*refcount = 0;
CV_XADD(refcount, 1);
flags |= Mat::CONTINUOUS_FLAG;
}
}
AclSafeCall(aclrtMalloc(&dev_ptr, totalSize, type_transition(policy)));
void aclMat::createEx(Size size, int type, ALIGNMENT config, MemMallocPolicy policy)
{
createEx(size.height, size.width, type, config, policy);
}
data = dev_ptr;
datastart = static_cast<uchar *>(data);
dataend = static_cast<uchar *>(data) + totalSize;
refcount = static_cast<int *>(fastMalloc(sizeof(*refcount)));
*refcount = 0;
CV_XADD(refcount, 1);
flags |= Mat::CONTINUOUS_FLAG;
}
}
void aclMat::release()
{
CV_XADD(refcount, -1);
if (data && (*refcount == 0))
{
aclrtFree(data);
}
data = nullptr;
datastart = nullptr;
dataend = nullptr;
}
void aclMat::createEx(Size size, int type, ALIGNMENT config,
MemMallocPolicy policy) {
createEx(size.height, size.width, type, config, policy);
}
aclMat &aclMat::operator+=(const aclMat &m)
{
CV_Assert(this->rows == m.rows && this->cols == m.cols && this->type() == m.type());
TwoInAndOneOut(*this, m, *this, "Add");
return *this;
}
void aclMat::release() {
CV_XADD(refcount, -1);
if (data && (*refcount == 0)) {
aclrtFree(data);
}
data = nullptr;
datastart = nullptr;
dataend = nullptr;
}
aclMat &aclMat::operator-=(const aclMat &m)
{
CV_Assert(this->rows == m.rows && this->cols == m.cols && this->type() == m.type());
TwoInAndOneOut(*this, m, *this, "Sub");
return *this;
}
aclMat &aclMat::operator+=(const aclMat &m) {
CV_Assert(this->rows == m.rows && this->cols == m.cols &&
this->type() == m.type());
TwoInAndOneOut(*this, m, *this, "Add");
return *this;
}
aclMat &aclMat::operator/=(const aclMat &m)
{
CV_Assert(this->rows == m.rows && this->cols == m.cols && this->type() == m.type());
TwoInAndOneOut(*this, m, *this, "Div");
return *this;
}
aclMat &aclMat::operator-=(const aclMat &m) {
CV_Assert(this->rows == m.rows && this->cols == m.cols &&
this->type() == m.type());
TwoInAndOneOut(*this, m, *this, "Sub");
return *this;
}
aclMat &aclMat::operator*=(const aclMat &m)
{
CV_Assert(this->cols == m.rows && this->type() == m.type());
vector<aclMat> input_Mat;
vector<aclMat> output_Mat;
vector<aclDataBuffer *> inputBuffers_;
vector<aclDataBuffer *> outputBuffers_;
aclMat newMat{this->rows, m.cols, this->type(), this->acl_context};
aclMat &aclMat::operator/=(const aclMat &m) {
CV_Assert(this->rows == m.rows && this->cols == m.cols &&
this->type() == m.type());
TwoInAndOneOut(*this, m, *this, "Div");
return *this;
}
input_Mat.emplace_back(*this);
input_Mat.emplace_back(m);
output_Mat.emplace_back(newMat);
aclMat &aclMat::operator*=(const aclMat &m) {
CV_Assert(this->cols == m.rows && this->type() == m.type());
vector<aclMat> input_Mat;
vector<aclMat> output_Mat;
vector<aclDataBuffer *> inputBuffers_;
vector<aclDataBuffer *> outputBuffers_;
aclMat newMat{this->rows, m.cols, this->type(), this->acl_context};
OperatorDesc opDesc = CreateOpDesc("MatMul", input_Mat, output_Mat, ACL_FORMAT_NHWC, TWO_DIMS);
opDesc.AddInputTensorDesc(ACL_DT_UNDEFINED, 0, nullptr, ACL_FORMAT_UNDEFINED);
opDesc.AddTensorAttr("transpose_x1", OP_BOOL, false);
opDesc.AddTensorAttr("transpose_x2", OP_BOOL, false);
input_Mat.emplace_back(*this);
input_Mat.emplace_back(m);
output_Mat.emplace_back(newMat);
inputBuffers_.emplace_back(aclCreateDataBuffer(this->data, this->totalSize));
inputBuffers_.emplace_back(aclCreateDataBuffer(m.data, m.totalSize));
inputBuffers_.emplace_back(aclCreateDataBuffer(nullptr, 0));
outputBuffers_.emplace_back(aclCreateDataBuffer(newMat.data, newMat.totalSize));
OperatorDesc opDesc =
CreateOpDesc("MatMul", input_Mat, output_Mat, ACL_FORMAT_NHWC, TWO_DIMS);
opDesc.AddInputTensorDesc(ACL_DT_UNDEFINED, 0, nullptr, ACL_FORMAT_UNDEFINED);
opDesc.AddTensorAttr("transpose_x1", OP_BOOL, false);
opDesc.AddTensorAttr("transpose_x2", OP_BOOL, false);
compileAndRunop(opDesc, inputBuffers_, outputBuffers_, this->acl_context, 0);
inputBuffers_.emplace_back(aclCreateDataBuffer(this->data, this->totalSize));
inputBuffers_.emplace_back(aclCreateDataBuffer(m.data, m.totalSize));
inputBuffers_.emplace_back(aclCreateDataBuffer(nullptr, 0));
outputBuffers_.emplace_back(
aclCreateDataBuffer(newMat.data, newMat.totalSize));
*this = newMat;
compileAndRunop(opDesc, inputBuffers_, outputBuffers_, this->acl_context, 0);
for (size_t i = 0; i < inputBuffers_.size(); i++)
AclSafeCall(aclDestroyDataBuffer(inputBuffers_[i]));
for (size_t i = 0; i < outputBuffers_.size(); i++)
AclSafeCall(aclDestroyDataBuffer(outputBuffers_[i]));
*this = newMat;
return *this;
}
for (size_t i = 0; i < inputBuffers_.size(); i++)
AclSafeCall(aclDestroyDataBuffer(inputBuffers_[i]));
for (size_t i = 0; i < outputBuffers_.size(); i++)
AclSafeCall(aclDestroyDataBuffer(outputBuffers_[i]));
} /* end of namespace acl */
return *this;
}
} /* end of namespace acl */
} /* end of namespace cv */

View File

@@ -1,88 +1,103 @@
#include "precomp.hpp"
namespace cv
{
namespace acl
{
/**
* @brief: matrix multiplication
*
*/
void MatMul(const aclMat& src1, const aclMat& src2, aclMat& dest, int stream_id)
{
CV_Assert(src1.cols == src2.rows && src1.type() == src2.type());
vector<aclMat> input_Mat;
vector<aclMat> output_Mat;
vector<aclDataBuffer *> inputBuffers_;
vector<aclDataBuffer *> outputBuffers_;
using namespace std;
using namespace cv;
using namespace cv::acl;
namespace cv {
namespace acl {
/**
* @brief: matrix multiplication
*
*/
void MatMul(const aclMat& src1, const aclMat& src2, aclMat& dest,
int stream_id) {
CV_Assert(src1.cols == src2.rows && src1.type() == src2.type());
vector<aclMat> input_Mat;
vector<aclMat> output_Mat;
vector<aclDataBuffer*> inputBuffers_;
vector<aclDataBuffer*> outputBuffers_;
input_Mat.emplace_back(src1);
input_Mat.emplace_back(src2);
output_Mat.emplace_back(dest);
input_Mat.emplace_back(src1);
input_Mat.emplace_back(src2);
output_Mat.emplace_back(dest);
inputBuffers_.emplace_back(aclCreateDataBuffer(src1.data, src1.totalSize));
inputBuffers_.emplace_back(aclCreateDataBuffer(src2.data, src2.totalSize));
inputBuffers_.emplace_back(aclCreateDataBuffer(nullptr, 0));
outputBuffers_.emplace_back(aclCreateDataBuffer(dest.data, dest.totalSize));
inputBuffers_.emplace_back(aclCreateDataBuffer(src1.data, src1.totalSize));
inputBuffers_.emplace_back(aclCreateDataBuffer(src2.data, src2.totalSize));
inputBuffers_.emplace_back(aclCreateDataBuffer(nullptr, 0));
outputBuffers_.emplace_back(aclCreateDataBuffer(dest.data, dest.totalSize));
OperatorDesc opDesc = CreateOpDesc("MatMul", input_Mat, output_Mat, ACL_FORMAT_NHWC, TWO_DIMS);
opDesc.AddInputTensorDesc(ACL_DT_UNDEFINED, 0, nullptr, ACL_FORMAT_UNDEFINED);
opDesc.AddTensorAttr("transpose_x1", OP_BOOL, false);
opDesc.AddTensorAttr("transpose_x2", OP_BOOL, false);
compileAndRunop(opDesc, inputBuffers_, outputBuffers_, dest.acl_context, stream_id);
OperatorDesc opDesc =
CreateOpDesc("MatMul", input_Mat, output_Mat, ACL_FORMAT_NHWC, TWO_DIMS);
opDesc.AddInputTensorDesc(ACL_DT_UNDEFINED, 0, nullptr, ACL_FORMAT_UNDEFINED);
opDesc.AddTensorAttr("transpose_x1", OP_BOOL, false);
opDesc.AddTensorAttr("transpose_x2", OP_BOOL, false);
compileAndRunop(opDesc, inputBuffers_, outputBuffers_, dest.acl_context,
stream_id);
for (size_t i = 0; i < inputBuffers_.size(); i++)
AclSafeCall(aclDestroyDataBuffer(inputBuffers_[i]));
for (size_t i = 0; i < outputBuffers_.size(); i++)
AclSafeCall(aclDestroyDataBuffer(outputBuffers_[i]));
}
for (size_t i = 0; i < inputBuffers_.size(); i++)
AclSafeCall(aclDestroyDataBuffer(inputBuffers_[i]));
for (size_t i = 0; i < outputBuffers_.size(); i++)
AclSafeCall(aclDestroyDataBuffer(outputBuffers_[i]));
}
/**
* @brief convolution
* @param [in] src: characteristic matrix
* @param [in] kernel: convolution kernel
* @param [in] dest: destination matrix
* @param [in] stridesList: strides, The N and C dimensions must be set to 1
* @param [in] padSList: pads, vector<int64_t>(top, bottom, left, right)
*/
void Convolution(const aclMat& src, const aclMat& kernel, aclMat& dest, const vector<int64_t>& stridesList, const vector<int64_t>& padsList, int stream_id)
{
vector<aclDataBuffer *> inputBuffers_;
vector<aclDataBuffer *> outputBuffers_;
vector<int64_t> dilationsList{1, 1, 1, 1};
string opType = "Conv2D";
int dest_rows = (src.rows + padsList[0] + padsList[1] - (1 * (kernel.rows - 1) + 1)) / stridesList[2] + 1;
int dest_cols = (src.cols + padsList[2] + padsList[3] - (1 * (kernel.cols - 1) + 1)) / stridesList[3] + 1;
aclMat acl_dest{dest_rows, dest_cols, src.type(), src.acl_context};
/**
* @brief convolution
* @param [in] src: characteristic matrix
* @param [in] kernel: convolution kernel
* @param [in] dest: destination matrix
* @param [in] stridesList: strides, The N and C dimensions must be set to 1
* @param [in] padSList: pads, vector<int64_t>(top, bottom, left, right)
*/
void Convolution(const aclMat& src, const aclMat& kernel, aclMat& dest,
const vector<int64_t>& stridesList,
const vector<int64_t>& padsList, int stream_id) {
vector<aclDataBuffer*> inputBuffers_;
vector<aclDataBuffer*> outputBuffers_;
vector<int64_t> dilationsList{1, 1, 1, 1};
string opType = "Conv2D";
int dest_rows =
(src.rows + padsList[0] + padsList[1] - (1 * (kernel.rows - 1) + 1)) /
stridesList[2] +
1;
int dest_cols =
(src.cols + padsList[2] + padsList[3] - (1 * (kernel.cols - 1) + 1)) /
stridesList[3] +
1;
aclMat acl_dest{dest_rows, dest_cols, src.type(), src.acl_context};
vector<int64_t> shape{1, 1, src.rows, src.cols};
vector<int64_t> shape1{1, 1, kernel.rows, kernel.cols};
vector<int64_t> shape2{1, 1, acl_dest.rows, acl_dest.cols};
vector<int64_t> shape{1, 1, src.rows, src.cols};
vector<int64_t> shape1{1, 1, kernel.rows, kernel.cols};
vector<int64_t> shape2{1, 1, acl_dest.rows, acl_dest.cols};
aclDataType dataType = type_transition(src.depth());
aclFormat format = ACL_FORMAT_NCHW;
OperatorDesc opDesc(opType);
opDesc.AddInputTensorDesc(dataType, shape.size(), shape.data(), format);
opDesc.AddInputTensorDesc(dataType, shape1.size(), shape1.data(), format);
opDesc.AddOutputTensorDesc(dataType, shape2.size(), shape2.data(), format);
aclDataType dataType = type_transition(src.depth());
aclFormat format = ACL_FORMAT_NCHW;
OperatorDesc opDesc(opType);
opDesc.AddInputTensorDesc(dataType, shape.size(), shape.data(), format);
opDesc.AddInputTensorDesc(dataType, shape1.size(), shape1.data(), format);
opDesc.AddOutputTensorDesc(dataType, shape2.size(), shape2.data(), format);
auto opAttr = opDesc.opAttr;
aclopSetAttrListInt(opAttr, "strides", stridesList.size(), stridesList.data());
aclopSetAttrListInt(opAttr, "pads", padsList.size(), padsList.data());
aclopSetAttrListInt(opAttr, "dilations", dilationsList.size(), dilationsList.data());
auto opAttr = opDesc.opAttr;
aclopSetAttrListInt(opAttr, "strides", stridesList.size(),
stridesList.data());
aclopSetAttrListInt(opAttr, "pads", padsList.size(), padsList.data());
aclopSetAttrListInt(opAttr, "dilations", dilationsList.size(),
dilationsList.data());
inputBuffers_.emplace_back(aclCreateDataBuffer(src.data, src.totalSize));
inputBuffers_.emplace_back(aclCreateDataBuffer(kernel.data, kernel.totalSize));
outputBuffers_.emplace_back(aclCreateDataBuffer(acl_dest.data, acl_dest.totalSize));
compileAndRunop(opDesc, inputBuffers_, outputBuffers_, src.acl_context, stream_id);
acl_dest.data = aclGetDataBufferAddr(outputBuffers_[0]);
dest = acl_dest;
inputBuffers_.emplace_back(aclCreateDataBuffer(src.data, src.totalSize));
inputBuffers_.emplace_back(
aclCreateDataBuffer(kernel.data, kernel.totalSize));
outputBuffers_.emplace_back(
aclCreateDataBuffer(acl_dest.data, acl_dest.totalSize));
compileAndRunop(opDesc, inputBuffers_, outputBuffers_, src.acl_context,
stream_id);
acl_dest.data = aclGetDataBufferAddr(outputBuffers_[0]);
dest = acl_dest;
for (size_t i = 0; i < inputBuffers_.size(); i++)
AclSafeCall(aclDestroyDataBuffer(inputBuffers_[i]));
for (size_t i = 0; i < outputBuffers_.size(); i++)
AclSafeCall(aclDestroyDataBuffer(outputBuffers_[i]));
}
} /* end of namespace acl */
for (size_t i = 0; i < inputBuffers_.size(); i++)
AclSafeCall(aclDestroyDataBuffer(inputBuffers_[i]));
for (size_t i = 0; i < outputBuffers_.size(); i++)
AclSafeCall(aclDestroyDataBuffer(outputBuffers_[i]));
}
} /* end of namespace acl */
} /* end of namespace cv */

View File

@@ -1,224 +1,224 @@
#include "precomp.hpp"
namespace cv
{
namespace acl
{
aclMat abs(const aclMat& a, int stream_id)
{
aclMat dest(a.rows, a.cols, a.type(), a.acl_context);
OneInAndOneOut(a, dest, "Abs", stream_id);
return dest;
}
using namespace std;
using namespace cv;
using namespace cv::acl;
namespace cv {
namespace acl {
aclMat abs(const aclMat &a, int stream_id) {
aclMat dest(a.rows, a.cols, a.type(), a.acl_context);
OneInAndOneOut(a, dest, "Abs", stream_id);
return dest;
}
static void *power_data(double power, aclDataType type, size_t powersize)
{
void *dev_ptr;
static void *power_data(double power, aclDataType type, size_t powersize) {
void *dev_ptr;
switch(type)
{
case ACL_UINT8:
{
aclrtMalloc(&dev_ptr, powersize, ACL_MEM_MALLOC_NORMAL_ONLY);
uchar power_8u = uchar(power);
aclrtMemcpy(dev_ptr, powersize, static_cast<void *>(&power_8u), powersize, ACL_MEMCPY_HOST_TO_DEVICE);
return dev_ptr;
}
case ACL_INT8:
{
aclrtMalloc(&dev_ptr, powersize, ACL_MEM_MALLOC_NORMAL_ONLY);
char power_8s = char(power);
aclrtMemcpy(dev_ptr, powersize, static_cast<void *>(&power_8s), powersize, ACL_MEMCPY_HOST_TO_DEVICE);
return dev_ptr;
}
case ACL_FLOAT16:
{
aclrtMalloc(&dev_ptr, powersize, ACL_MEM_MALLOC_NORMAL_ONLY);
float16_t power_16f = float16_t(power);
aclrtMemcpy(dev_ptr, powersize, static_cast<void *>(&power_16f), powersize, ACL_MEMCPY_HOST_TO_DEVICE);
return dev_ptr;
}
case ACL_INT32:
{
aclrtMalloc(&dev_ptr, powersize, ACL_MEM_MALLOC_NORMAL_ONLY);
int power_32s = int(power);
aclrtMemcpy(dev_ptr, powersize, static_cast<void *>(&power_32s), powersize, ACL_MEMCPY_HOST_TO_DEVICE);
return dev_ptr;
}
case ACL_FLOAT:
{
aclrtMalloc(&dev_ptr, powersize, ACL_MEM_MALLOC_NORMAL_ONLY);
float power_32f = float(power);
aclrtMemcpy(dev_ptr, powersize, static_cast<void *>(&power_32f), powersize, ACL_MEMCPY_HOST_TO_DEVICE);
return dev_ptr;
}
case ACL_DOUBLE:
{
aclrtMalloc(&dev_ptr, powersize, ACL_MEM_MALLOC_NORMAL_ONLY);
double power_64f = double(power);
aclrtMemcpy(dev_ptr, powersize, static_cast<void *>(&power_64f), powersize, ACL_MEMCPY_HOST_TO_DEVICE);
return dev_ptr;
}
default:
return nullptr;
}
}
switch (type) {
case ACL_UINT8: {
aclrtMalloc(&dev_ptr, powersize, ACL_MEM_MALLOC_NORMAL_ONLY);
uchar power_8u = uchar(power);
aclrtMemcpy(dev_ptr, powersize, static_cast<void *>(&power_8u), powersize,
ACL_MEMCPY_HOST_TO_DEVICE);
return dev_ptr;
}
case ACL_INT8: {
aclrtMalloc(&dev_ptr, powersize, ACL_MEM_MALLOC_NORMAL_ONLY);
char power_8s = char(power);
aclrtMemcpy(dev_ptr, powersize, static_cast<void *>(&power_8s), powersize,
ACL_MEMCPY_HOST_TO_DEVICE);
return dev_ptr;
}
case ACL_FLOAT16: {
aclrtMalloc(&dev_ptr, powersize, ACL_MEM_MALLOC_NORMAL_ONLY);
float16_t power_16f = float16_t(power);
aclrtMemcpy(dev_ptr, powersize, static_cast<void *>(&power_16f),
powersize, ACL_MEMCPY_HOST_TO_DEVICE);
return dev_ptr;
}
case ACL_INT32: {
aclrtMalloc(&dev_ptr, powersize, ACL_MEM_MALLOC_NORMAL_ONLY);
int power_32s = int(power);
aclrtMemcpy(dev_ptr, powersize, static_cast<void *>(&power_32s),
powersize, ACL_MEMCPY_HOST_TO_DEVICE);
return dev_ptr;
}
case ACL_FLOAT: {
aclrtMalloc(&dev_ptr, powersize, ACL_MEM_MALLOC_NORMAL_ONLY);
float power_32f = float(power);
aclrtMemcpy(dev_ptr, powersize, static_cast<void *>(&power_32f),
powersize, ACL_MEMCPY_HOST_TO_DEVICE);
return dev_ptr;
}
case ACL_DOUBLE: {
aclrtMalloc(&dev_ptr, powersize, ACL_MEM_MALLOC_NORMAL_ONLY);
double power_64f = double(power);
aclrtMemcpy(dev_ptr, powersize, static_cast<void *>(&power_64f),
powersize, ACL_MEMCPY_HOST_TO_DEVICE);
return dev_ptr;
}
default:
return nullptr;
}
}
void pow(const aclMat& src, double power, aclMat& dest, int stream_id)
{
vector<aclMat> input_Mat;
vector<aclMat> output_Mat;
vector<aclDataBuffer *> inputBuffers_;
vector<aclDataBuffer *> outputBuffers_;
void pow(const aclMat &src, double power, aclMat &dest, int stream_id) {
vector<aclMat> input_Mat;
vector<aclMat> output_Mat;
vector<aclDataBuffer *> inputBuffers_;
vector<aclDataBuffer *> outputBuffers_;
aclDataType dataType = type_transition(src.depth());
input_Mat.emplace_back(src);
output_Mat.emplace_back(dest);
aclDataType dataType = type_transition(src.depth());
OperatorDesc opDesc = CreateOpDesc("Pow", input_Mat, output_Mat);
vector<int64_t> shape2{1};
opDesc.AddInputTensorDesc(dataType, shape2.size(), shape2.data(), ACL_FORMAT_NHWC);
input_Mat.emplace_back(src);
output_Mat.emplace_back(dest);
size_t size = aclGetTensorDescSize(opDesc.inputDesc[1]);
void *power_dev = power_data(power, dataType, size);
OperatorDesc opDesc = CreateOpDesc("Pow", input_Mat, output_Mat);
vector<int64_t> shape2{1};
opDesc.AddInputTensorDesc(dataType, shape2.size(), shape2.data(),
ACL_FORMAT_NHWC);
inputBuffers_.emplace_back(aclCreateDataBuffer(src.data, src.totalSize));
inputBuffers_.emplace_back(aclCreateDataBuffer(power_dev, size));
size_t size = aclGetTensorDescSize(opDesc.inputDesc[1]);
void *power_dev = power_data(power, dataType, size);
outputBuffers_.emplace_back(aclCreateDataBuffer(dest.data, dest.totalSize));
inputBuffers_.emplace_back(aclCreateDataBuffer(src.data, src.totalSize));
inputBuffers_.emplace_back(aclCreateDataBuffer(power_dev, size));
compileAndRunop(opDesc, inputBuffers_, outputBuffers_, dest.acl_context, stream_id);
outputBuffers_.emplace_back(aclCreateDataBuffer(dest.data, dest.totalSize));
aclrtFree(power_dev);
for (size_t i = 0; i < inputBuffers_.size(); i++)
AclSafeCall(aclDestroyDataBuffer(inputBuffers_[i]));
for (size_t i = 0; i < outputBuffers_.size(); i++)
AclSafeCall(aclDestroyDataBuffer(outputBuffers_[i]));
}
compileAndRunop(opDesc, inputBuffers_, outputBuffers_, dest.acl_context,
stream_id);
void add(const aclMat& src, const aclMat& other_src, aclMat& dest, int stream_id)
{
bool is_correct;
is_correct = (src.rows == other_src.rows);
is_correct &= (src.rows == dest.rows);
is_correct &= (src.cols == other_src.cols);
is_correct &= (src.cols == dest.cols);
is_correct &= (src.type() == other_src.type());
is_correct &= (src.type() == dest.type());
CV_Assert(is_correct);
aclrtFree(power_dev);
for (size_t i = 0; i < inputBuffers_.size(); i++)
AclSafeCall(aclDestroyDataBuffer(inputBuffers_[i]));
for (size_t i = 0; i < outputBuffers_.size(); i++)
AclSafeCall(aclDestroyDataBuffer(outputBuffers_[i]));
}
TwoInAndOneOut(src, other_src, dest, "Add", stream_id);
}
void divide(const aclMat& src, const aclMat& other_src, aclMat& dest, int stream_id)
{
bool is_correct;
void add(const aclMat &src, const aclMat &other_src, aclMat &dest,
int stream_id) {
bool is_correct;
is_correct = (src.rows == other_src.rows);
is_correct &= (src.rows == dest.rows);
is_correct &= (src.cols == other_src.cols);
is_correct &= (src.cols == dest.cols);
is_correct &= (src.type() == other_src.type());
is_correct &= (src.type() == dest.type());
CV_Assert(is_correct);
is_correct = (src.rows == other_src.rows);
is_correct &= (src.rows == dest.rows);
is_correct &= (src.cols == other_src.cols);
is_correct &= (src.cols == dest.cols);
is_correct &= (src.type() == other_src.type());
is_correct &= (src.type() == dest.type());
CV_Assert(is_correct);
TwoInAndOneOut(src, other_src, dest, "Div", stream_id);
}
TwoInAndOneOut(src, other_src, dest, "Add", stream_id);
}
void exp(const aclMat& src, aclMat& dest, int stream_id)
{
CV_Assert(src.rows == dest.rows && src.cols == dest.cols && src.type() == dest.type());
void divide(const aclMat &src, const aclMat &other_src, aclMat &dest,
int stream_id) {
bool is_correct;
vector<aclMat> input_Mat;
vector<aclMat> output_Mat;
is_correct = (src.rows == other_src.rows);
is_correct &= (src.rows == dest.rows);
is_correct &= (src.cols == other_src.cols);
is_correct &= (src.cols == dest.cols);
is_correct &= (src.type() == other_src.type());
is_correct &= (src.type() == dest.type());
CV_Assert(is_correct);
vector<aclDataBuffer *> inputBuffers_;
vector<aclDataBuffer *> outputBuffers_;
TwoInAndOneOut(src, other_src, dest, "Div", stream_id);
}
input_Mat.emplace_back(src);
output_Mat.emplace_back(dest);
void exp(const aclMat &src, aclMat &dest, int stream_id) {
CV_Assert(src.rows == dest.rows && src.cols == dest.cols &&
src.type() == dest.type());
inputBuffers_.emplace_back(aclCreateDataBuffer(src.data, src.totalSize));
outputBuffers_.emplace_back(aclCreateDataBuffer(dest.data, dest.totalSize));
vector<aclMat> input_Mat;
vector<aclMat> output_Mat;
OperatorDesc opDesc = CreateOpDesc("Exp", input_Mat, output_Mat);
opDesc.AddTensorAttr("base", OP_FLOAT, -1.0);
opDesc.AddTensorAttr("scale", OP_FLOAT, 1.0);
opDesc.AddTensorAttr("shift", OP_FLOAT, 0.0);
compileAndRunop(opDesc, inputBuffers_, outputBuffers_, dest.acl_context, stream_id);
vector<aclDataBuffer *> inputBuffers_;
vector<aclDataBuffer *> outputBuffers_;
AclSafeCall(aclDestroyDataBuffer(inputBuffers_[0]));
AclSafeCall(aclDestroyDataBuffer(outputBuffers_[0]));
}
input_Mat.emplace_back(src);
output_Mat.emplace_back(dest);
void log(const aclMat &src, aclMat &dest, int stream_id)
{
CV_Assert(src.rows == dest.rows && src.cols == dest.cols && src.type() == dest.type());
inputBuffers_.emplace_back(aclCreateDataBuffer(src.data, src.totalSize));
outputBuffers_.emplace_back(aclCreateDataBuffer(dest.data, dest.totalSize));
vector<aclMat> input_Mat;
vector<aclMat> output_Mat;
OperatorDesc opDesc = CreateOpDesc("Exp", input_Mat, output_Mat);
opDesc.AddTensorAttr("base", OP_FLOAT, -1.0);
opDesc.AddTensorAttr("scale", OP_FLOAT, 1.0);
opDesc.AddTensorAttr("shift", OP_FLOAT, 0.0);
vector<aclDataBuffer *> inputBuffers_;
vector<aclDataBuffer *> outputBuffers_;
compileAndRunop(opDesc, inputBuffers_, outputBuffers_, dest.acl_context,
stream_id);
input_Mat.emplace_back(src);
output_Mat.emplace_back(dest);
AclSafeCall(aclDestroyDataBuffer(inputBuffers_[0]));
AclSafeCall(aclDestroyDataBuffer(outputBuffers_[0]));
}
inputBuffers_.emplace_back(aclCreateDataBuffer(src.data, src.totalSize));
outputBuffers_.emplace_back(aclCreateDataBuffer(dest.data, dest.totalSize));
void log(const aclMat &src, aclMat &dest, int stream_id) {
CV_Assert(src.rows == dest.rows && src.cols == dest.cols &&
src.type() == dest.type());
OperatorDesc opDesc = CreateOpDesc("Log", input_Mat, output_Mat);
opDesc.AddTensorAttr("base", OP_FLOAT, -1.0);
opDesc.AddTensorAttr("scale", OP_FLOAT, 1.0);
opDesc.AddTensorAttr("shift", OP_FLOAT, 0.0);
compileAndRunop(opDesc, inputBuffers_, outputBuffers_, dest.acl_context, stream_id);
vector<aclMat> input_Mat;
vector<aclMat> output_Mat;
AclSafeCall(aclDestroyDataBuffer(inputBuffers_[0]));
AclSafeCall(aclDestroyDataBuffer(outputBuffers_[0]));
}
vector<aclDataBuffer *> inputBuffers_;
vector<aclDataBuffer *> outputBuffers_;
void max(const aclMat &src, const aclMat &other_src, aclMat &dest, int stream_id)
{
bool is_correct;
input_Mat.emplace_back(src);
output_Mat.emplace_back(dest);
is_correct = (src.rows == other_src.rows);
is_correct &= (src.rows == dest.rows);
is_correct &= (src.cols == other_src.cols);
is_correct &= (src.cols == dest.cols);
is_correct &= (src.type() == other_src.type());
is_correct &= (src.type() == dest.type());
CV_Assert(is_correct);
inputBuffers_.emplace_back(aclCreateDataBuffer(src.data, src.totalSize));
outputBuffers_.emplace_back(aclCreateDataBuffer(dest.data, dest.totalSize));
TwoInAndOneOut(src, other_src, dest, "Maximum", stream_id);
}
OperatorDesc opDesc = CreateOpDesc("Log", input_Mat, output_Mat);
opDesc.AddTensorAttr("base", OP_FLOAT, -1.0);
opDesc.AddTensorAttr("scale", OP_FLOAT, 1.0);
opDesc.AddTensorAttr("shift", OP_FLOAT, 0.0);
void min(const aclMat &src, const aclMat &other_src, aclMat &dest, int stream_id)
{
bool is_correct;
compileAndRunop(opDesc, inputBuffers_, outputBuffers_, dest.acl_context,
stream_id);
is_correct = (src.rows == other_src.rows);
is_correct &= (src.rows == dest.rows);
is_correct &= (src.cols == other_src.cols);
is_correct &= (src.cols == dest.cols);
is_correct &= (src.type() == other_src.type());
is_correct &= (src.type() == dest.type());
CV_Assert(is_correct);
AclSafeCall(aclDestroyDataBuffer(inputBuffers_[0]));
AclSafeCall(aclDestroyDataBuffer(outputBuffers_[0]));
}
TwoInAndOneOut(src, other_src, dest, "Minimum", stream_id);
}
void max(const aclMat &src, const aclMat &other_src, aclMat &dest,
int stream_id) {
bool is_correct;
void sqrt(const aclMat &src, aclMat &dest, int stream_id)
{
CV_Assert(src.rows == dest.rows && src.cols == dest.cols && src.type() == dest.type());
is_correct = (src.rows == other_src.rows);
is_correct &= (src.rows == dest.rows);
is_correct &= (src.cols == other_src.cols);
is_correct &= (src.cols == dest.cols);
is_correct &= (src.type() == other_src.type());
is_correct &= (src.type() == dest.type());
CV_Assert(is_correct);
OneInAndOneOut(src, dest, "Sqrt", stream_id);
}
TwoInAndOneOut(src, other_src, dest, "Maximum", stream_id);
}
} /* end of namespace acl */
void min(const aclMat &src, const aclMat &other_src, aclMat &dest,
int stream_id) {
bool is_correct;
is_correct = (src.rows == other_src.rows);
is_correct &= (src.rows == dest.rows);
is_correct &= (src.cols == other_src.cols);
is_correct &= (src.cols == dest.cols);
is_correct &= (src.type() == other_src.type());
is_correct &= (src.type() == dest.type());
CV_Assert(is_correct);
TwoInAndOneOut(src, other_src, dest, "Minimum", stream_id);
}
void sqrt(const aclMat &src, aclMat &dest, int stream_id) {
CV_Assert(src.rows == dest.rows && src.cols == dest.cols &&
src.type() == dest.type());
OneInAndOneOut(src, dest, "Sqrt", stream_id);
}
} /* end of namespace acl */
} /* end of namespace cv */

View File

@@ -1,60 +1,11 @@
#include "precomp.hpp"
namespace cv
{
namespace acl
{
/*
//disable
void lookUpTable(const aclMat& src, const aclMat& lut, aclMat& dest)
{
bool is_correct;
is_correct = ((src.depth() == CV_8U) || (src.depth() == CV_8S));
is_correct &= ((lut.depth() == CV_8U) || (lut.depth() == CV_8S));
is_correct &= (lut.totalSize == 256);
CV_Assert(is_correct);
vector<aclMat> input_Mat;
vector<aclMat> output_Mat;
vector<aclDataBuffer *> inputBuffers_;
vector<aclDataBuffer *> outputBuffers_;
uchar keyValue[256];
for (int i = 0; i < 256; ++i)
keyValue[i] = i;
aclMat key(1, 256, src.type(), keyValue, src.acl_context);
input_Mat.emplace_back(src);
input_Mat.emplace_back(key);
input_Mat.emplace_back(lut);
inputBuffers_.emplace_back(aclCreateDataBuffer(src.data, src.totalSize));
inputBuffers_.emplace_back(aclCreateDataBuffer(key.data, key.totalSize));
inputBuffers_.emplace_back(aclCreateDataBuffer(lut.data, lut.totalSize));
aclDataType dataType = type_transition(input_Mat[0].depth());
aclFormat format = ACL_FORMAT_NHWC;
OperatorDesc opDesc("LookupTableImport");
vector<int64_t> shape1{src.rows, src.cols * src.channels()};
vector<int64_t> shape2{lut.rows, lut.cols * lut.channels()};
vector<int64_t> shape3{dest.rows, dest.cols * dest.channels()};
opDesc.AddInputTensorDesc(dataType, shape1.size(), shape1.data(), format);
opDesc.AddInputTensorDesc(dataType, shape2.size(), shape2.data(), format);
opDesc.AddInputTensorDesc(dataType, shape3.size(), shape3.data(), format);
compileAndRunop(opDesc, inputBuffers_, outputBuffers_, dest.acl_context);
dest.data = aclGetDataBufferAddr(inputBuffers_[0]);
for (size_t i = 0; i < inputBuffers_.size(); i++)
AclSafeCall(aclDestroyDataBuffer(inputBuffers_[i]));
for (size_t i = 0; i < outputBuffers_.size(); i++)
AclSafeCall(aclDestroyDataBuffer(outputBuffers_[i]));
}
*/
/*
using namespace std;
using namespace cv;
using namespace cv::acl;
namespace cv {
namespace acl {
#if 0
void merge(const vector<aclMat>& mv, aclMat& dest)
{
vector<aclDataBuffer *> inputBuffers_;
@@ -66,191 +17,190 @@ namespace cv
for (size_t i = 0; i < mv.size(); ++i)
{
int cols = mv[i].step/mv[i].elemSize();
vector<int64_t> inputShape{1, mv[i].rows, cols, mv[i].channels()};
opDesc.AddInputTensorDesc(dataType, inputShape.size(), inputShape.data(), ACL_FORMAT_ND);
vector<int64_t> inputShape{1, mv[i].rows, cols,
mv[i].channels()}; opDesc.AddInputTensorDesc(dataType, inputShape.size(),
inputShape.data(), ACL_FORMAT_ND);
}
int cols = dest.step/dest.elemSize();
vector<int64_t> outputShape{1, dest.rows, cols, dest.channels()};
opDesc.AddOutputTensorDesc(dataType, outputShape.size(), outputShape.data(), ACL_FORMAT_ND);
opDesc.AddOutputTensorDesc(dataType, outputShape.size(),
outputShape.data(), ACL_FORMAT_ND);
for (size_t i = 0; i < opDesc.inputDesc.size(); ++i)
{
inputBuffers_.emplace_back(aclCreateDataBuffer(mv[i].data, mv[i].totalSize));
inputBuffers_.emplace_back(aclCreateDataBuffer(mv[i].data,
mv[i].totalSize));
}
outputBuffers_.emplace_back(aclCreateDataBuffer(dest.data, dest.totalSize));
outputBuffers_.emplace_back(aclCreateDataBuffer(dest.data,
dest.totalSize));
aclopSetAttrInt(opDesc.opAttr, "N", mv.size());
aclopSetAttrInt(opDesc.opAttr, "concat_dim", 3);
compileAndRunop(opDesc, inputBuffers_, outputBuffers_, dest.acl_context);
compileAndRunop(opDesc, inputBuffers_, outputBuffers_,
dest.acl_context);
for (size_t i = 0; i < inputBuffers_.size(); i++)
AclSafeCall(aclDestroyDataBuffer(inputBuffers_[i]));
for (size_t i = 0; i < outputBuffers_.size(); i++)
AclSafeCall(aclDestroyDataBuffer(outputBuffers_[i]));
}
*/
static int merge_type(int depth, int channels)
{
switch (depth)
{
case CV_8U:
return CV_8UC(channels);
case CV_8S:
return CV_8SC(channels);
case CV_32F:
return CV_32FC(channels);
case CV_32S:
return CV_32SC(channels);
case CV_64F:
return CV_64FC(channels);
}
return -1;
}
#endif
void merge(const vector<aclMat>& mv, aclMat& dest, int stream_id)
{
vector<aclDataBuffer *> inputBuffers_;
vector<aclDataBuffer *> outputBuffers_;
static int merge_type(int depth, int channels) {
switch (depth) {
case CV_8U:
return CV_8UC(channels);
case CV_8S:
return CV_8SC(channels);
case CV_32F:
return CV_32FC(channels);
case CV_32S:
return CV_32SC(channels);
case CV_64F:
return CV_64FC(channels);
}
return -1;
}
OperatorDesc opDesc("Concat");
aclDataType dataType = type_transition(mv[0].depth());
void merge(const vector<aclMat> &mv, aclMat &dest, int stream_id) {
vector<aclDataBuffer *> inputBuffers_;
vector<aclDataBuffer *> outputBuffers_;
vector<int64_t> inputShape{};
opDesc.AddInputTensorDesc(ACL_INT32, inputShape.size(), inputShape.data(), ACL_FORMAT_ND);
OperatorDesc opDesc("Concat");
aclDataType dataType = type_transition(mv[0].depth());
for (size_t i = 0; i < mv.size(); ++i)
{
int cols = mv[i].step/mv[i].elemSize();
vector<int64_t> inputShape{1, mv[i].rows, cols, mv[i].channels()};
opDesc.AddInputTensorDesc(dataType, inputShape.size(), inputShape.data(), ACL_FORMAT_NHWC);
}
vector<int64_t> inputShape{};
opDesc.AddInputTensorDesc(ACL_INT32, inputShape.size(), inputShape.data(),
ACL_FORMAT_ND);
int cols = mv[0].step/mv[0].elemSize();
int channels = mv.size();
vector<int64_t> outputShape{1, mv[0].rows, cols, channels};
opDesc.AddOutputTensorDesc(dataType, outputShape.size(), outputShape.data(), ACL_FORMAT_NHWC);
for (size_t i = 0; i < mv.size(); ++i) {
int cols = mv[i].step / mv[i].elemSize();
vector<int64_t> inputShape{1, mv[i].rows, cols, mv[i].channels()};
opDesc.AddInputTensorDesc(dataType, inputShape.size(), inputShape.data(),
ACL_FORMAT_NHWC);
}
ino64_t N = mv.size();
aclopSetAttrInt(opDesc.opAttr, "N", N);
int cols = mv[0].step / mv[0].elemSize();
int channels = mv.size();
vector<int64_t> outputShape{1, mv[0].rows, cols, channels};
opDesc.AddOutputTensorDesc(dataType, outputShape.size(), outputShape.data(),
ACL_FORMAT_NHWC);
aclSetTensorDescName(opDesc.inputDesc[0], "concat_dim");
aclSetTensorDescName(opDesc.inputDesc[1], "x0");
aclSetTensorDescName(opDesc.inputDesc[2], "x1");
if (mv.size() == 3)
aclSetTensorDescName(opDesc.inputDesc[3], "x2");
else if(mv.size() == 4)
aclSetTensorDescName(opDesc.inputDesc[4], "x3");
aclSetTensorDescName(opDesc.outputDesc[0], "y");
ino64_t N = mv.size();
aclopSetAttrInt(opDesc.opAttr, "N", N);
void *dev;
int64_t concat_dim = 3;
size_t size = aclGetTensorDescSize(opDesc.inputDesc[0]);
aclrtMalloc(&dev, size, ACL_MEM_MALLOC_NORMAL_ONLY);
aclrtMemcpy(dev, size, &concat_dim, size, ACL_MEMCPY_HOST_TO_DEVICE);
inputBuffers_.emplace_back(aclCreateDataBuffer(dev, size));
aclSetTensorDescName(opDesc.inputDesc[0], "concat_dim");
for (size_t i = 0; i < mv.size(); ++i)
inputBuffers_.emplace_back(aclCreateDataBuffer(mv[i].data, mv[i].totalSize));
aclSetTensorDescName(opDesc.inputDesc[1], "x0");
aclSetTensorDescName(opDesc.inputDesc[2], "x1");
if (mv.size() == 3)
aclSetTensorDescName(opDesc.inputDesc[3], "x2");
else if (mv.size() == 4)
aclSetTensorDescName(opDesc.inputDesc[4], "x3");
aclSetTensorDescName(opDesc.outputDesc[0], "y");
int type = merge_type(mv[0].depth(), channels);
aclMat temp(mv[0].rows, mv[0].cols, type, mv[0].acl_context);
dest = temp;
outputBuffers_.emplace_back(aclCreateDataBuffer(dest.data, dest.totalSize));
void *dev;
int64_t concat_dim = 3;
size_t size = aclGetTensorDescSize(opDesc.inputDesc[0]);
aclrtMalloc(&dev, size, ACL_MEM_MALLOC_NORMAL_ONLY);
aclrtMemcpy(dev, size, &concat_dim, size, ACL_MEMCPY_HOST_TO_DEVICE);
inputBuffers_.emplace_back(aclCreateDataBuffer(dev, size));
compileAndRunop(opDesc, inputBuffers_, outputBuffers_, dest.acl_context, stream_id);
for (size_t i = 0; i < mv.size(); ++i)
inputBuffers_.emplace_back(
aclCreateDataBuffer(mv[i].data, mv[i].totalSize));
for (size_t i = 0; i < inputBuffers_.size(); i++)
AclSafeCall(aclDestroyDataBuffer(inputBuffers_[i]));
for (size_t i = 0; i < outputBuffers_.size(); i++)
AclSafeCall(aclDestroyDataBuffer(outputBuffers_[i]));
int type = merge_type(mv[0].depth(), channels);
aclMat temp(mv[0].rows, mv[0].cols, type, mv[0].acl_context);
dest = temp;
outputBuffers_.emplace_back(aclCreateDataBuffer(dest.data, dest.totalSize));
aclrtFree(dev);
}
compileAndRunop(opDesc, inputBuffers_, outputBuffers_, dest.acl_context,
stream_id);
for (size_t i = 0; i < inputBuffers_.size(); i++)
AclSafeCall(aclDestroyDataBuffer(inputBuffers_[i]));
for (size_t i = 0; i < outputBuffers_.size(); i++)
AclSafeCall(aclDestroyDataBuffer(outputBuffers_[i]));
aclrtFree(dev);
}
/**
* @brief : Dynamic shape reasoning
*
*
*/
void transpose(const aclMat &src, aclMat &dest, int stream_id) {
vector<aclDataBuffer *> inputBuffers_;
vector<aclDataBuffer *> outputBuffers_;
vector<aclDataBuffer *> inputBuffers_host;
void transpose(const aclMat& src, aclMat& dest, int stream_id)
{
vector<aclDataBuffer *> inputBuffers_;
vector<aclDataBuffer *> outputBuffers_;
vector<aclDataBuffer *> inputBuffers_host;
OperatorDesc opDesc("Transpose");
aclDataType dataType = type_transition(src.depth());
OperatorDesc opDesc("Transpose");
aclDataType dataType = type_transition(src.depth());
vector<int64_t> inputShape1{1, src.rows, src.cols, src.channels()};
opDesc.AddInputTensorDesc(dataType, inputShape1.size(), inputShape1.data(),
ACL_FORMAT_ND);
vector<int64_t> inputShape1{1, src.rows, src.cols, src.channels()};
opDesc.AddInputTensorDesc(dataType, inputShape1.size(), inputShape1.data(), ACL_FORMAT_ND);
vector<int64_t> inputShape2{4};
opDesc.AddInputTensorDesc(ACL_INT32, inputShape2.size(), inputShape2.data(),
ACL_FORMAT_ND);
vector<int64_t> inputShape2{4};
opDesc.AddInputTensorDesc(ACL_INT32, inputShape2.size(), inputShape2.data(), ACL_FORMAT_ND);
vector<int64_t> outputShape{-1, -1, -1, -1};
opDesc.AddOutputTensorDesc(dataType, outputShape.size(), outputShape.data(),
ACL_FORMAT_ND);
vector<int64_t> outputShape{-1, -1, -1, -1};
opDesc.AddOutputTensorDesc(dataType, outputShape.size(), outputShape.data(), ACL_FORMAT_ND);
inputBuffers_.emplace_back(aclCreateDataBuffer(src.data, src.totalSize));
inputBuffers_.emplace_back(aclCreateDataBuffer(src.data, src.totalSize));
void *dev;
void *perm;
void *dev;
void *perm;
size_t size = aclGetTensorDescSize(opDesc.inputDesc[1]);
aclrtMalloc(&dev, size, ACL_MEM_MALLOC_NORMAL_ONLY);
aclrtMallocHost(&perm, aclGetTensorDescSize(opDesc.inputDesc.data()[1]));
((int *)perm)[0] = 0;
((int *)perm)[1] = 2;
((int *)perm)[2] = 1;
((int *)perm)[3] = 3;
aclrtMemcpy(dev, size, perm, size, ACL_MEMCPY_HOST_TO_DEVICE);
inputBuffers_.emplace_back(aclCreateDataBuffer(dev, size));
size_t size = aclGetTensorDescSize(opDesc.inputDesc[1]);
aclrtMalloc(&dev, size, ACL_MEM_MALLOC_NORMAL_ONLY);
aclrtMallocHost(&perm, aclGetTensorDescSize(opDesc.inputDesc.data()[1]));
((int *)perm)[0] = 0;
((int *)perm)[1] = 2;
((int *)perm)[2] = 1;
((int *)perm)[3] = 3;
aclrtMemcpy(dev, size, perm, size, ACL_MEMCPY_HOST_TO_DEVICE);
inputBuffers_.emplace_back(aclCreateDataBuffer(dev, size));
AclSafeCall(aclopCompile(opDesc.opType.c_str(), opDesc.inputDesc.size(),
opDesc.inputDesc.data(), opDesc.outputDesc.size(),
opDesc.outputDesc.data(), opDesc.opAttr,
ACL_ENGINE_SYS, ACL_COMPILE_SYS, nullptr));
AclSafeCall(aclopCompile(opDesc.opType.c_str(),
opDesc.inputDesc.size(),
opDesc.inputDesc.data(),
opDesc.outputDesc.size(),
opDesc.outputDesc.data(),
opDesc.opAttr,
ACL_ENGINE_SYS,
ACL_COMPILE_SYS,
nullptr));
void *host_data;
size_t host_size = src.totalSize;
aclrtMallocHost(&host_data, host_size);
aclrtMemcpy(host_data, host_size, src.data, host_size,
ACL_MEMCPY_DEVICE_TO_HOST);
inputBuffers_host.emplace_back(aclCreateDataBuffer(host_data, host_size));
inputBuffers_host.emplace_back(aclCreateDataBuffer(perm, size));
void *host_data;
size_t host_size = src.totalSize;
aclrtMallocHost(&host_data, host_size);
aclrtMemcpy(host_data, host_size, src.data, host_size, ACL_MEMCPY_DEVICE_TO_HOST);
inputBuffers_host.emplace_back(aclCreateDataBuffer(host_data, host_size));
inputBuffers_host.emplace_back(aclCreateDataBuffer(perm, size));
AclSafeCall(aclopInferShape("Transpose", opDesc.inputDesc.size(),
opDesc.inputDesc.data(), inputBuffers_host.data(),
opDesc.outputDesc.size(),
opDesc.outputDesc.data(), opDesc.opAttr));
outputBuffers_.emplace_back(aclCreateDataBuffer(dest.data, dest.totalSize));
AclSafeCall(aclopInferShape("Transpose", opDesc.inputDesc.size(), opDesc.inputDesc.data(), \
inputBuffers_host.data(), opDesc.outputDesc.size(), opDesc.outputDesc.data(), opDesc.opAttr));
outputBuffers_.emplace_back(aclCreateDataBuffer(dest.data, dest.totalSize));
AclSafeCall(aclopExecuteV2(opDesc.opType.c_str(),
inputBuffers_.size(),
opDesc.inputDesc.data(),
inputBuffers_.data(),
outputBuffers_.size(),
opDesc.outputDesc.data(),
outputBuffers_.data(),
opDesc.opAttr,
dest.acl_context->get_stream(stream_id)));
AclSafeCall(aclDestroyDataBuffer(inputBuffers_[0]));
AclSafeCall(aclDestroyDataBuffer(inputBuffers_[1]));
AclSafeCall(aclDestroyDataBuffer(inputBuffers_host[0]));
AclSafeCall(aclDestroyDataBuffer(inputBuffers_host[1]));
AclSafeCall(aclDestroyDataBuffer(outputBuffers_[0]));
AclSafeCall(aclrtFree(dev));
AclSafeCall(aclrtFreeHost(perm));
AclSafeCall(aclrtFreeHost(host_data));
}
AclSafeCall(aclopExecuteV2(opDesc.opType.c_str(), inputBuffers_.size(),
opDesc.inputDesc.data(), inputBuffers_.data(),
outputBuffers_.size(), opDesc.outputDesc.data(),
outputBuffers_.data(), opDesc.opAttr,
dest.acl_context->get_stream(stream_id)));
AclSafeCall(aclDestroyDataBuffer(inputBuffers_[0]));
AclSafeCall(aclDestroyDataBuffer(inputBuffers_[1]));
AclSafeCall(aclDestroyDataBuffer(inputBuffers_host[0]));
AclSafeCall(aclDestroyDataBuffer(inputBuffers_host[1]));
AclSafeCall(aclDestroyDataBuffer(outputBuffers_[0]));
AclSafeCall(aclrtFree(dev));
AclSafeCall(aclrtFreeHost(perm));
AclSafeCall(aclrtFreeHost(host_data));
}
/* transposeD */
#if 0
@@ -281,65 +231,63 @@ namespace cv
}
#endif
static int split_type(int depth)
{
switch (depth)
{
case CV_8U:
return CV_8UC1;
case CV_8S:
return CV_8SC1;
case CV_32F:
return CV_32FC1;
case CV_32S:
return CV_32SC1;
case CV_64F:
return CV_64FC1;
}
return -1;
}
static int split_type(int depth) {
switch (depth) {
case CV_8U:
return CV_8UC1;
case CV_8S:
return CV_8SC1;
case CV_32F:
return CV_32FC1;
case CV_32S:
return CV_32SC1;
case CV_64F:
return CV_64FC1;
}
return -1;
}
void split(const aclMat& src, vector<aclMat>& mv, int stream_id)
{
vector<aclDataBuffer *> inputBuffers_;
vector<aclDataBuffer *> outputBuffers_;
int split_dim = 3;
int num_split = src.channels();
void split(const aclMat &src, vector<aclMat> &mv, int stream_id) {
vector<aclDataBuffer *> inputBuffers_;
vector<aclDataBuffer *> outputBuffers_;
int split_dim = 3;
int num_split = src.channels();
OperatorDesc opDesc("SplitD");
aclDataType dataType = type_transition(src.depth());
OperatorDesc opDesc("SplitD");
aclDataType dataType = type_transition(src.depth());
int cols = src.step/src.elemSize();
vector<int64_t> inputShape1{1, src.rows, cols, src.channels()};
opDesc.AddInputTensorDesc(dataType, inputShape1.size(), inputShape1.data(), ACL_FORMAT_ND);
int cols = src.step / src.elemSize();
vector<int64_t> inputShape1{1, src.rows, cols, src.channels()};
opDesc.AddInputTensorDesc(dataType, inputShape1.size(), inputShape1.data(),
ACL_FORMAT_ND);
for (int i = 0; i < num_split; ++i)
{
vector<int64_t> outputShape{1, src.rows, cols, 1};
opDesc.AddOutputTensorDesc(dataType, outputShape.size(), outputShape.data(), ACL_FORMAT_ND);
}
auto opAttr = opDesc.opAttr;
aclopSetAttrInt(opAttr, "split_dim", split_dim);
aclopSetAttrInt(opAttr, "num_split", num_split);
for (int i = 0; i < num_split; ++i) {
vector<int64_t> outputShape{1, src.rows, cols, 1};
opDesc.AddOutputTensorDesc(dataType, outputShape.size(), outputShape.data(),
ACL_FORMAT_ND);
}
inputBuffers_.emplace_back(aclCreateDataBuffer(src.data, src.totalSize));
auto opAttr = opDesc.opAttr;
aclopSetAttrInt(opAttr, "split_dim", split_dim);
aclopSetAttrInt(opAttr, "num_split", num_split);
int type = split_type(src.depth());
for (int i = 0; i < num_split; ++i)
{
aclMat tmp(src.rows, src.cols, type, src.acl_context);
mv[i] = tmp;
outputBuffers_.emplace_back(aclCreateDataBuffer(mv[i].data, mv[i].totalSize));
}
inputBuffers_.emplace_back(aclCreateDataBuffer(src.data, src.totalSize));
compileAndRunop(opDesc, inputBuffers_, outputBuffers_, src.acl_context, stream_id);
int type = split_type(src.depth());
for (int i = 0; i < num_split; ++i) {
aclMat tmp(src.rows, src.cols, type, src.acl_context);
mv[i] = tmp;
outputBuffers_.emplace_back(
aclCreateDataBuffer(mv[i].data, mv[i].totalSize));
}
AclSafeCall(aclDestroyDataBuffer(inputBuffers_[0]));
for (int i = 0; i < num_split; ++i)
AclSafeCall(aclDestroyDataBuffer(outputBuffers_[i]));
}
compileAndRunop(opDesc, inputBuffers_, outputBuffers_, src.acl_context,
stream_id);
AclSafeCall(aclDestroyDataBuffer(inputBuffers_[0]));
for (int i = 0; i < num_split; ++i)
AclSafeCall(aclDestroyDataBuffer(outputBuffers_[i]));
}
#if 0
//disable
@@ -429,56 +377,57 @@ namespace cv
}
#endif
static void flip_(const aclMat& src, aclMat& dest, int axis, int stream_id)
{
vector<aclDataBuffer *> inputBuffers_;
vector<aclDataBuffer *> outputBuffers_;
static void flip_(const aclMat &src, aclMat &dest, int axis, int stream_id) {
vector<aclDataBuffer *> inputBuffers_;
vector<aclDataBuffer *> outputBuffers_;
OperatorDesc opDesc("ReverseV2");
aclDataType dataType = type_transition(src.depth());
OperatorDesc opDesc("ReverseV2");
aclDataType dataType = type_transition(src.depth());
vector<int64_t> inputShape1{1, src.rows, src.cols, src.channels()};
opDesc.AddInputTensorDesc(dataType, inputShape1.size(), inputShape1.data(), ACL_FORMAT_ND);
vector<int64_t> inputShape1{1, src.rows, src.cols, src.channels()};
opDesc.AddInputTensorDesc(dataType, inputShape1.size(), inputShape1.data(),
ACL_FORMAT_ND);
vector<int64_t> inputShape2{1};
opDesc.AddInputTensorDesc(ACL_INT32, inputShape2.size(), inputShape2.data(), ACL_FORMAT_ND);
vector<int64_t> inputShape2{1};
opDesc.AddInputTensorDesc(ACL_INT32, inputShape2.size(), inputShape2.data(),
ACL_FORMAT_ND);
vector<int64_t> outputShape{1, dest.rows, dest.cols, dest.channels()};
opDesc.AddOutputTensorDesc(dataType, outputShape.size(), outputShape.data(), ACL_FORMAT_ND);
inputBuffers_.emplace_back(aclCreateDataBuffer(src.data, src.totalSize));
vector<int64_t> outputShape{1, dest.rows, dest.cols, dest.channels()};
opDesc.AddOutputTensorDesc(dataType, outputShape.size(), outputShape.data(),
ACL_FORMAT_ND);
void *dev;
size_t size = aclGetTensorDescSize(opDesc.inputDesc[1]);
aclrtMalloc(&dev, size, ACL_MEM_MALLOC_NORMAL_ONLY);
aclrtMemcpy(dev, size, &axis, size, ACL_MEMCPY_HOST_TO_DEVICE);
inputBuffers_.emplace_back(aclCreateDataBuffer(dev, size));
inputBuffers_.emplace_back(aclCreateDataBuffer(src.data, src.totalSize));
outputBuffers_.emplace_back(aclCreateDataBuffer(dest.data, dest.totalSize));
void *dev;
size_t size = aclGetTensorDescSize(opDesc.inputDesc[1]);
aclrtMalloc(&dev, size, ACL_MEM_MALLOC_NORMAL_ONLY);
aclrtMemcpy(dev, size, &axis, size, ACL_MEMCPY_HOST_TO_DEVICE);
inputBuffers_.emplace_back(aclCreateDataBuffer(dev, size));
compileAndRunop(opDesc, inputBuffers_, outputBuffers_, dest.acl_context, stream_id);
AclSafeCall(aclDestroyDataBuffer(inputBuffers_[0]));
AclSafeCall(aclDestroyDataBuffer(inputBuffers_[1]));
AclSafeCall(aclDestroyDataBuffer(outputBuffers_[0]));
AclSafeCall(aclrtFree(dev));
}
outputBuffers_.emplace_back(aclCreateDataBuffer(dest.data, dest.totalSize));
void flip(const aclMat& src, aclMat& dest, int filpCode, int stream_id)
{
if (filpCode == 0) {
flip_(src, dest, 1, stream_id);
}
else if (filpCode > 0) {
flip_(src, dest, 2, stream_id);
}
else {
flip_(src, dest, 2, stream_id);
aclMat tmp(dest.rows, dest.cols, dest.type(), dest.acl_context);
aclrtMemcpy(tmp.data, dest.totalSize, dest.data, dest.totalSize, ACL_MEMCPY_DEVICE_TO_DEVICE);
flip_(tmp, dest, 1, stream_id);
}
}
} /* end of namespace acl */
compileAndRunop(opDesc, inputBuffers_, outputBuffers_, dest.acl_context,
stream_id);
AclSafeCall(aclDestroyDataBuffer(inputBuffers_[0]));
AclSafeCall(aclDestroyDataBuffer(inputBuffers_[1]));
AclSafeCall(aclDestroyDataBuffer(outputBuffers_[0]));
AclSafeCall(aclrtFree(dev));
}
void flip(const aclMat &src, aclMat &dest, int filpCode, int stream_id) {
if (filpCode == 0) {
flip_(src, dest, 1, stream_id);
} else if (filpCode > 0) {
flip_(src, dest, 2, stream_id);
} else {
flip_(src, dest, 2, stream_id);
aclMat tmp(dest.rows, dest.cols, dest.type(), dest.acl_context);
aclrtMemcpy(tmp.data, dest.totalSize, dest.data, dest.totalSize,
ACL_MEMCPY_DEVICE_TO_DEVICE);
flip_(tmp, dest, 1, stream_id);
}
}
} /* end of namespace acl */
} /* end of namespace cv */

View File

@@ -1,181 +1,166 @@
/**
* @file operator_desc.cpp
*
* Copyright (C) 2020. Huawei Technologies Co., Ltd. All rights reserved.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
* @file operator_desc.cpp
*
* Copyright (C) 2020. Huawei Technologies Co., Ltd. All rights reserved.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
#include "precomp.hpp"
using namespace std;
using namespace cv;
using namespace cv::acl;
namespace cv {
namespace acl {
OperatorDesc::OperatorDesc(std::string opType) : opType(std::move(opType)) {
opAttr = aclopCreateAttr();
}
namespace cv
{
namespace acl
{
OperatorDesc::OperatorDesc(std::string opType) : opType(std::move(opType))
{
opAttr = aclopCreateAttr();
}
OperatorDesc::~OperatorDesc() {
for (auto* desc : inputDesc) {
aclDestroyTensorDesc(desc);
}
OperatorDesc::~OperatorDesc()
{
for (auto *desc : inputDesc)
{
aclDestroyTensorDesc(desc);
}
for (auto* desc : outputDesc) {
aclDestroyTensorDesc(desc);
}
for (auto *desc : outputDesc)
{
aclDestroyTensorDesc(desc);
}
aclopDestroyAttr(opAttr);
}
aclopDestroyAttr(opAttr);
}
OperatorDesc& OperatorDesc::AddInputTensorDesc(aclDataType dataType,
int numDims, const int64_t* dims,
aclFormat format) {
aclTensorDesc* desc = aclCreateTensorDesc(dataType, numDims, dims, format);
CV_Assert(desc);
inputDesc.emplace_back(desc);
return *this;
}
OperatorDesc &OperatorDesc::AddInputTensorDesc(aclDataType dataType,
int numDims,
const int64_t *dims,
aclFormat format)
{
aclTensorDesc *desc = aclCreateTensorDesc(dataType, numDims, dims, format);
CV_Assert(desc);
inputDesc.emplace_back(desc);
return *this;
}
OperatorDesc& OperatorDesc::AddOutputTensorDesc(aclDataType dataType,
int numDims,
const int64_t* dims,
aclFormat format) {
aclTensorDesc* desc = aclCreateTensorDesc(dataType, numDims, dims, format);
CV_Assert(desc);
outputDesc.emplace_back(desc);
return *this;
}
OperatorDesc &OperatorDesc::AddOutputTensorDesc(aclDataType dataType,
int numDims,
const int64_t *dims,
aclFormat format)
{
aclTensorDesc *desc = aclCreateTensorDesc(dataType, numDims, dims, format);
CV_Assert(desc);
outputDesc.emplace_back(desc);
return *this;
}
/**
* @brief create operator describe
*
*/
OperatorDesc CreateOpDesc(const string opType, const vector<aclMat>& input_Mat,
vector<aclMat>& output_Mat, aclFormat format,
Opdims config) {
CV_Assert(config == TWO_DIMS || config == FOUR_DIMS);
/**
* @brief create operator describe
*
*/
OperatorDesc CreateOpDesc(const string opType, const vector<aclMat>& input_Mat, vector<aclMat>& output_Mat, aclFormat format, Opdims config)
{
CV_Assert(config == TWO_DIMS || config == FOUR_DIMS);
size_t i;
aclDataType dataType = type_transition(input_Mat[0].depth());
size_t i;
aclDataType dataType = type_transition(input_Mat[0].depth());
OperatorDesc opDesc(opType);
for (i = 0; i < input_Mat.size(); ++i) {
if (config == TWO_DIMS) {
int cols = input_Mat[i].step / input_Mat[i].elemSize();
vector<int64_t> shape{input_Mat[i].rows, cols};
opDesc.AddInputTensorDesc(dataType, shape.size(), shape.data(), format);
} else if (config == FOUR_DIMS) {
int cols = input_Mat[i].step / input_Mat[i].elemSize();
vector<int64_t> shape{1, input_Mat[i].rows, cols,
input_Mat[i].channels()};
opDesc.AddInputTensorDesc(dataType, shape.size(), shape.data(), format);
}
}
OperatorDesc opDesc(opType);
for (i = 0; i < input_Mat.size(); ++i) {
if (config == TWO_DIMS)
{
int cols = input_Mat[i].step / input_Mat[i].elemSize();
vector<int64_t> shape{input_Mat[i].rows, cols};
opDesc.AddInputTensorDesc(dataType, shape.size(), shape.data(), format);
}
else if(config == FOUR_DIMS)
{
int cols = input_Mat[i].step / input_Mat[i].elemSize();
vector<int64_t> shape{1, input_Mat[i].rows, cols, input_Mat[i].channels()};
opDesc.AddInputTensorDesc(dataType, shape.size(), shape.data(), format);
}
}
for (i = 0; i < output_Mat.size(); ++i) {
if (config == TWO_DIMS) {
int cols = output_Mat[i].step / output_Mat[i].elemSize();
vector<int64_t> shape{output_Mat[i].rows, cols};
opDesc.AddOutputTensorDesc(dataType, shape.size(), shape.data(), format);
} else if (config == FOUR_DIMS) {
int cols = output_Mat[i].step / output_Mat[i].elemSize();
vector<int64_t> shape{1, output_Mat[i].rows, cols,
output_Mat[i].channels()};
opDesc.AddOutputTensorDesc(dataType, shape.size(), shape.data(), format);
}
}
for (i = 0; i < output_Mat.size(); ++i) {
if (config == TWO_DIMS)
{
int cols = output_Mat[i].step / output_Mat[i].elemSize();
vector<int64_t> shape{output_Mat[i].rows, cols};
opDesc.AddOutputTensorDesc(dataType, shape.size(), shape.data(), format);
}
else if(config == FOUR_DIMS)
{
int cols = output_Mat[i].step / output_Mat[i].elemSize();
vector<int64_t> shape{1, output_Mat[i].rows, cols, output_Mat[i].channels()};
opDesc.AddOutputTensorDesc(dataType, shape.size(), shape.data(), format);
}
}
return opDesc;
}
return opDesc;
}
/**
* @brief compile and run operator
*
*/
void compileAndRunop(OperatorDesc& opDesc,
vector<aclDataBuffer*>& inputBuffers_,
vector<aclDataBuffer*>& outputBuffers_,
aclCxt* acl_context, int stream_id) {
AclSafeCall(aclopCompile(opDesc.opType.c_str(), opDesc.inputDesc.size(),
opDesc.inputDesc.data(), opDesc.outputDesc.size(),
opDesc.outputDesc.data(), opDesc.opAttr,
ACL_ENGINE_SYS, ACL_COMPILE_SYS, nullptr));
/**
* @brief compile and run operator
*
*/
void compileAndRunop(OperatorDesc& opDesc, vector<aclDataBuffer *>& inputBuffers_, vector<aclDataBuffer *>& outputBuffers_, aclCxt *acl_context, int stream_id)
{
AclSafeCall(aclopCompile(opDesc.opType.c_str(),
opDesc.inputDesc.size(),
opDesc.inputDesc.data(),
opDesc.outputDesc.size(),
opDesc.outputDesc.data(),
opDesc.opAttr,
ACL_ENGINE_SYS,
ACL_COMPILE_SYS,
nullptr));
AclSafeCall(aclopExecuteV2(opDesc.opType.c_str(),
inputBuffers_.size(),
opDesc.inputDesc.data(),
inputBuffers_.data(),
outputBuffers_.size(),
opDesc.outputDesc.data(),
outputBuffers_.data(),
opDesc.opAttr,
acl_context->get_stream(stream_id)));
}
AclSafeCall(aclopExecuteV2(opDesc.opType.c_str(), inputBuffers_.size(),
opDesc.inputDesc.data(), inputBuffers_.data(),
outputBuffers_.size(), opDesc.outputDesc.data(),
outputBuffers_.data(), opDesc.opAttr,
acl_context->get_stream(stream_id)));
}
void Runop(vector<aclMat>& input, vector<aclMat>& output, OperatorDesc& opDesc, int stream_id)
{
size_t i;
void Runop(vector<aclMat>& input, vector<aclMat>& output, OperatorDesc& opDesc,
int stream_id) {
size_t i;
vector<aclDataBuffer *> inputBuffers_;
vector<aclDataBuffer *> outputBuffers_;
vector<aclDataBuffer*> inputBuffers_;
vector<aclDataBuffer*> outputBuffers_;
for (i = 0; i < input.size(); ++i)
inputBuffers_.emplace_back(aclCreateDataBuffer(input[i].data, input[i].totalSize));
for (i = 0; i < output.size(); ++i)
outputBuffers_.emplace_back(aclCreateDataBuffer(output[i].data, output[i].totalSize));
for (i = 0; i < input.size(); ++i)
inputBuffers_.emplace_back(
aclCreateDataBuffer(input[i].data, input[i].totalSize));
for (i = 0; i < output.size(); ++i)
outputBuffers_.emplace_back(
aclCreateDataBuffer(output[i].data, output[i].totalSize));
compileAndRunop(opDesc, inputBuffers_, outputBuffers_, output[0].acl_context, stream_id);
compileAndRunop(opDesc, inputBuffers_, outputBuffers_, output[0].acl_context,
stream_id);
for (i = 0; i < input.size(); ++i)
AclSafeCall(aclDestroyDataBuffer(inputBuffers_[i]));
for (i = 0; i < output.size(); ++i)
AclSafeCall(aclDestroyDataBuffer(outputBuffers_[i]));
}
for (i = 0; i < input.size(); ++i)
AclSafeCall(aclDestroyDataBuffer(inputBuffers_[i]));
for (i = 0; i < output.size(); ++i)
AclSafeCall(aclDestroyDataBuffer(outputBuffers_[i]));
}
void OneInAndOneOut(const aclMat& inputMat, aclMat& outputMat, const string opType, int stream_id)
{
vector<aclMat> input_Mat;
vector<aclMat> output_Mat;
void OneInAndOneOut(const aclMat& inputMat, aclMat& outputMat,
const string opType, int stream_id) {
vector<aclMat> input_Mat;
vector<aclMat> output_Mat;
input_Mat.emplace_back(inputMat);
output_Mat.emplace_back(outputMat);
input_Mat.emplace_back(inputMat);
output_Mat.emplace_back(outputMat);
OperatorDesc opDesc = CreateOpDesc(opType, input_Mat, output_Mat);
Runop(input_Mat, output_Mat, opDesc, stream_id);
}
OperatorDesc opDesc = CreateOpDesc(opType, input_Mat, output_Mat);
Runop(input_Mat, output_Mat, opDesc, stream_id);
}
void TwoInAndOneOut(const aclMat& inputMat, const aclMat& inputMatOther, aclMat& outputMat, const string opType, int stream_id)
{
vector<aclMat> input_Mat;
vector<aclMat> output_Mat;
void TwoInAndOneOut(const aclMat& inputMat, const aclMat& inputMatOther,
aclMat& outputMat, const string opType, int stream_id) {
vector<aclMat> input_Mat;
vector<aclMat> output_Mat;
input_Mat.emplace_back(inputMat);
input_Mat.emplace_back(inputMatOther);
output_Mat.emplace_back(outputMat);
OperatorDesc opDesc = CreateOpDesc(opType, input_Mat, output_Mat);
Runop(input_Mat, output_Mat, opDesc, stream_id);
}
input_Mat.emplace_back(inputMat);
input_Mat.emplace_back(inputMatOther);
output_Mat.emplace_back(outputMat);
} /* end of namespace acl */
OperatorDesc opDesc = CreateOpDesc(opType, input_Mat, output_Mat);
Runop(input_Mat, output_Mat, opDesc, stream_id);
}
} /* end of namespace acl */
} /* end of namespace cv */

View File

@@ -1,8 +1,9 @@
/*M///////////////////////////////////////////////////////////////////////////////////////
/* M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// By downloading, copying, installing or using the software you agree to this
license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
@@ -14,23 +15,29 @@
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// Redistribution and use in source and binary forms, with or without
modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// * Redistribution's in binary form must reproduce the above copyright
notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of the copyright holders may not be used to endorse or promote products
// * The name of the copyright holders may not be used to endorse or promote
products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// This software is provided by the copyright holders and contributors "as is"
and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// warranties of merchantability and fitness for a particular purpose are
disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any
direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
@@ -38,12 +45,11 @@
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
//M */
#ifndef OPENCV_ACL_PRECOMP_HPP__
#define OPENCV_ACL_PRECOMP_HPP__
#include <assert.h>
#include <ctype.h>
#include <float.h>
@@ -52,19 +58,16 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory>
#include <vector>
#include "opencv2/core.hpp"
#include "opencv2/acl/acl.hpp"
#include "opencv2/core/utility.hpp"
#include "opencv2/acl/operator_desc.hpp"
#include "acl/acl.h"
#include "acl/acl_op_compiler.h"
#include "opencv2/acl/acl.hpp"
#include "opencv2/acl/operator_desc.hpp"
#include "opencv2/core.hpp"
#include "opencv2/core/utility.hpp"
using namespace std;
using namespace cv;
using namespace cv::acl;
#endif

View File

@@ -1,299 +1,277 @@
#include "test_common.hpp"
#include "test_correctness.hpp"
#include "test_perf.hpp"
#include "test_common.hpp"
using namespace cv;
using namespace cv::acl;
using namespace cvtest;
using namespace testing;
using namespace std;
namespace opencv_test
{
namespace
{
aclCxt *acl_context_0 = set_device("../../modules/acl/test/acl.json", 2, 3);
////////////////////////////////////////////////////Correctness_test////////////////////////////////////////////////////////
/* range: rows: 1 ~ 64, cols: 1 ~ 64, type: 0 ~ 7
* test function:
* config: MEMORY_ALIGN
* aclMat(int rows, int cols, int type, aclCxt *acl_context, ALIGNMENT config = MEMORY_UNALIGNED, aclrtMemMallocPolicy policy = ACL_MEM_MALLOC_HUGE_FIRST);
* aclMat(Size size, int type, aclCxt *acl_context, ALIGNMENT config = MEMORY_UNALIGNED, aclrtMemMallocPolicy policy = ACL_MEM_MALLOC_HUGE_FIRST);
* aclMat(const aclMat &m);
*
*/
TEST(ACLMAT_CONSTRUCTOR, MEMORY_ALIGN)
{
AclMat_Test test;
test.Test_constructor_ALIGN(acl_context_0);
}
namespace opencv_test {
namespace {
aclCxt *acl_context_0 = set_device("../../modules/acl/test/acl.json", 2, 3);
////////////////////////////////////////////////////Correctness_test////////////////////////////////////////////////////////
/* range: rows: 1 ~ 64, cols: 1 ~ 64, type: 0 ~ 7
* test function:
* config: MEMORY_ALIGN
* aclMat(int rows, int cols, int type, aclCxt *acl_context, ALIGNMENT config =
* MEMORY_UNALIGNED, aclrtMemMallocPolicy policy = ACL_MEM_MALLOC_HUGE_FIRST);
* aclMat(Size size, int type, aclCxt *acl_context, ALIGNMENT config =
* MEMORY_UNALIGNED, aclrtMemMallocPolicy policy = ACL_MEM_MALLOC_HUGE_FIRST);
* aclMat(const aclMat &m);
*
*/
TEST(ACLMAT_CONSTRUCTOR, MEMORY_ALIGN) {
AclMat_Test test;
test.Test_constructor_ALIGN(acl_context_0);
}
/* range: rows: 1 ~ 64, cols: 1 ~ 64, type: 0 ~ 7
* test function:
* config: MEMORY_UNALIGNED
* aclMat(int rows, int cols, int type, aclCxt *acl_context, ALIGNMENT config = MEMORY_UNALIGNED, aclrtMemMallocPolicy policy = ACL_MEM_MALLOC_HUGE_FIRST);
* aclMat(Size size, int type, aclCxt *acl_context, ALIGNMENT config = MEMORY_UNALIGNED, aclrtMemMallocPolicy policy = ACL_MEM_MALLOC_HUGE_FIRST);
*
*/
TEST(ACLMAT_CONSTRUCTOR, MEMORY_UNALIGNED)
{
AclMat_Test test;
test.Test_constructor_UNALIGNED(acl_context_0);
}
/* range: rows: 1 ~ 64, cols: 1 ~ 64, type: 0 ~ 7
* test function:
* config: MEMORY_UNALIGNED
* aclMat(int rows, int cols, int type, aclCxt *acl_context, ALIGNMENT config =
* MEMORY_UNALIGNED, aclrtMemMallocPolicy policy = ACL_MEM_MALLOC_HUGE_FIRST);
* aclMat(Size size, int type, aclCxt *acl_context, ALIGNMENT config =
* MEMORY_UNALIGNED, aclrtMemMallocPolicy policy = ACL_MEM_MALLOC_HUGE_FIRST);
*
*/
TEST(ACLMAT_CONSTRUCTOR, MEMORY_UNALIGNED) {
AclMat_Test test;
test.Test_constructor_UNALIGNED(acl_context_0);
}
/* range: rows: 1 ~ 64, cols: 1 ~ 64, type: 0 ~ 7
* test function:
* aclMat(const aclMat &m);
*/
TEST(ACLMAT_CONSTRUCTOR, COPY_CONSTRUCTOR)
{
AclMat_Test test;
test.Test_constructor(acl_context_0);
}
/* range: rows: 1 ~ 64, cols: 1 ~ 64, type: 0 ~ 7
* test function:
* aclMat(const aclMat &m);
*/
TEST(ACLMAT_CONSTRUCTOR, COPY_CONSTRUCTOR) {
AclMat_Test test;
test.Test_constructor(acl_context_0);
}
/* range: rows: 1 ~ 64, cols: 1 ~ 64, type: 0 ~ 7
* test function:
* aclMat(int rows, int cols, int type, void *data, aclCxt* acl_context, ALIGNMENT config = MEMORY_UNALIGNED, size_t step = Mat::AUTO_STEP);
* aclMat(Size size, int type, void *data, aclCxt* acl_context, ALIGNMENT config = MEMORY_UNALIGNED, size_t step = Mat::AUTO_STEP);
*/
TEST(ACLMAT_CONSTRUCTOR, DATA)
{
AclMat_Test test;
test.Test_constructor_DATA(acl_context_0);
}
/* range: rows: 1 ~ 64, cols: 1 ~ 64, type: 0 ~ 7
* test function:
* aclMat(int rows, int cols, int type, void *data, aclCxt* acl_context,
* ALIGNMENT config = MEMORY_UNALIGNED, size_t step = Mat::AUTO_STEP);
* aclMat(Size size, int type, void *data, aclCxt* acl_context, ALIGNMENT config
* = MEMORY_UNALIGNED, size_t step = Mat::AUTO_STEP);
*/
TEST(ACLMAT_CONSTRUCTOR, DATA) {
AclMat_Test test;
test.Test_constructor_DATA(acl_context_0);
}
/* range: rows: 1 ~ 64, cols: 1 ~ 64, type: 0 ~ 7
* test function:
* aclMat(const aclMat &m, const Range &rowRange, const Range &colRange = Range::all());
*
*/
TEST(ACLMAT_CONSTRUCTOR, RANGE)
{
AclMat_Test test;
test.Test_constructor_RANGE(acl_context_0);
}
/* range: rows: 1 ~ 64, cols: 1 ~ 64, type: 0 ~ 7
* test function:
* aclMat(const aclMat &m, const Range &rowRange, const Range &colRange =
* Range::all());
*
*/
TEST(ACLMAT_CONSTRUCTOR, RANGE) {
AclMat_Test test;
test.Test_constructor_RANGE(acl_context_0);
}
/*
* test function:
* aclMat(const aclMat &m, const Rect &roi);
*
*/
TEST(ACLMAT_CONSTRUCTOR, ROI)
{
AclMat_Test test;
test.Test_constructor_ROI(acl_context_0);
}
/*
* test function:
* aclMat (const Mat &m, aclCxt* acl_context, ALIGNMENT config = MEMORY_UNALIGNED, aclrtMemMallocPolicy policy = ACL_MEM_MALLOC_HUGE_FIRST);
*/
TEST(ACLMAT_CONSTRUCTOR, MAT)
{
AclMat_Test test;
test.Test_constructor_MAT(acl_context_0);
}
/*
* test function:
* aclMat(const aclMat &m, const Rect &roi);
*
*/
TEST(ACLMAT_CONSTRUCTOR, ROI) {
AclMat_Test test;
test.Test_constructor_ROI(acl_context_0);
}
/* range: rows: 1 ~ 64, cols: 1 ~ 64, type: 0 ~ 7
* test function:
* CV_EXPORTS void upload(const Mat &m, ALIGNMENT config = MEMORY_UNALIGNED);
* CV_EXPORTS void upload(const Mat &m, aclStream stream, ALIGNMENT config = MEMORY_UNALIGNED);
*
*/
TEST(ACLMAT_FUNCTION, DATA_TRANSFER)
{
AclMat_Test test;
test.Test_DATA_TRANSFER(acl_context_0);
}
/*
* test function:
* aclMat (const Mat &m, aclCxt* acl_context, ALIGNMENT config =
* MEMORY_UNALIGNED, aclrtMemMallocPolicy policy = ACL_MEM_MALLOC_HUGE_FIRST);
*/
TEST(ACLMAT_CONSTRUCTOR, MAT) {
AclMat_Test test;
test.Test_constructor_MAT(acl_context_0);
}
/* range: rows: 1 ~ 64, cols: 1 ~ 64, type: 0 ~ 7
* test function:
* CV_EXPORTS void download(Mat &m, ALIGNMENT config = MEMORY_UNALIGNED) const;
* CV_EXPORTS void download(Mat &m, aclStream stream, ALIGNMENT config = MEMORY_UNALIGNED) const;
*
*/
TEST(ACLMAT_FUNCTION, DATA_TRANSFERASYNC)
{
AclMat_Test test;
test.Test_DATA_TRANSFERASYNC(acl_context_0);
}
/* range: rows: 1 ~ 64, cols: 1 ~ 64, type: 0 ~ 7
* test function:
* CV_EXPORTS void upload(const Mat &m, ALIGNMENT config = MEMORY_UNALIGNED);
* CV_EXPORTS void upload(const Mat &m, aclStream stream, ALIGNMENT config =
* MEMORY_UNALIGNED);
*
*/
TEST(ACLMAT_FUNCTION, DATA_TRANSFER) {
AclMat_Test test;
test.Test_DATA_TRANSFER(acl_context_0);
}
/*
* test function:
* void locateROI(Size &wholeSize, Point &ofs) const;
*/
TEST(ACLMAT_FUNCTION, LOCATEROI)
{
AclMat_Test test;
test.Test_locateROI(acl_context_0);
}
/* range: rows: 1 ~ 64, cols: 1 ~ 64, type: 0 ~ 7
* test function:
* CV_EXPORTS void download(Mat &m, ALIGNMENT config = MEMORY_UNALIGNED) const;
* CV_EXPORTS void download(Mat &m, aclStream stream, ALIGNMENT config =
* MEMORY_UNALIGNED) const;
*
*/
TEST(ACLMAT_FUNCTION, DATA_TRANSFERASYNC) {
AclMat_Test test;
test.Test_DATA_TRANSFERASYNC(acl_context_0);
}
/*
* test function:
* void swap(aclMat &mat);
*
*/
TEST(ACLMAT_FUNCTION, SWAP)
{
AclMat_Test test;
test.Test_swap(acl_context_0);
}
/*
* test function:
* void locateROI(Size &wholeSize, Point &ofs) const;
*/
TEST(ACLMAT_FUNCTION, LOCATEROI) {
AclMat_Test test;
test.Test_locateROI(acl_context_0);
}
/*
* test function:
* operator+=()
*
*/
TEST(ACLMAT_FUNCTION, OPERATOR_ADD)
{
AclMat_Test test;
test.Test_operator_add(acl_context_0);
}
/*
* test function:
* void swap(aclMat &mat);
*
*/
TEST(ACLMAT_FUNCTION, SWAP) {
AclMat_Test test;
test.Test_swap(acl_context_0);
}
/*
* test function:
* operator-=()
*
*/
TEST(ACLMAT_FUNCTION, OPERATOR_SUB)
{
AclMat_Test test;
test.Test_operator_sub(acl_context_0);
}
/*
* test function:
* operator+=()
*
*/
TEST(ACLMAT_FUNCTION, OPERATOR_ADD) {
AclMat_Test test;
test.Test_operator_add(acl_context_0);
}
/*
* test function:
* operator*=()
*
*/
TEST(ACLMAT_FUNCTION, OPERATOR_MUL)
{
AclMat_Test test;
test.Test_operator_mul(acl_context_0);
}
/*
* test function:
* operator-=()
*
*/
TEST(ACLMAT_FUNCTION, OPERATOR_SUB) {
AclMat_Test test;
test.Test_operator_sub(acl_context_0);
}
/*
* test function:
* operator/=()
*
*/
TEST(ACLMAT_FUNCTION, OPERATOR_DIV)
{
AclMat_Test test;
test.Test_operator_div(acl_context_0);
}
////////////////////////////////////////////////////Perf_test////////////////////////////////////////////////////////
/*
* test function:
* operator*=()
*
*/
TEST(ACLMAT_FUNCTION, OPERATOR_MUL) {
AclMat_Test test;
test.Test_operator_mul(acl_context_0);
}
TEST(Operator, add)
{
PERF_TEST test;
test.Test_operator_add_perf(acl_context_0);
}
/*
* test function:
* operator/=()
*
*/
TEST(ACLMAT_FUNCTION, OPERATOR_DIV) {
AclMat_Test test;
test.Test_operator_div(acl_context_0);
}
TEST(Operator, sub)
{
PERF_TEST test;
test.Test_operator_sub_perf(acl_context_0);
}
////////////////////////////////////////////////////Perf_test////////////////////////////////////////////////////////
TEST(Operator, div)
{
PERF_TEST test;
test.Test_operator_div_perf(acl_context_0);
}
TEST(Operator, add) {
PERF_TEST test;
test.Test_operator_add_perf(acl_context_0);
}
TEST(Operator, mul)
{
PERF_TEST test;
test.Test_operator_mul_perf(acl_context_0);
}
TEST(Operator, sub) {
PERF_TEST test;
test.Test_operator_sub_perf(acl_context_0);
}
TEST(Mathfunction, abs)
{
PERF_TEST test;
test.Test_Abs(acl_context_0);
}
TEST(Operator, div) {
PERF_TEST test;
test.Test_operator_div_perf(acl_context_0);
}
TEST(Mathfunction, pow)
{
PERF_TEST test;
test.Test_Pow(acl_context_0);
}
TEST(Operator, mul) {
PERF_TEST test;
test.Test_operator_mul_perf(acl_context_0);
}
TEST(Mathfunction, sqrt)
{
PERF_TEST test;
test.Test_Sqrt(acl_context_0);
}
TEST(Mathfunction, abs) {
PERF_TEST test;
test.Test_Abs(acl_context_0);
}
TEST(Mathfunction, add)
{
PERF_TEST test;
test.Test_Add(acl_context_0);
}
TEST(Mathfunction, pow) {
PERF_TEST test;
test.Test_Pow(acl_context_0);
}
TEST(Mathfunction, divide)
{
PERF_TEST test;
test.Test_Divide(acl_context_0);
}
TEST(Mathfunction, sqrt) {
PERF_TEST test;
test.Test_Sqrt(acl_context_0);
}
TEST(Mathfunction, exp)
{
PERF_TEST test;
test.Test_Exp(acl_context_0);
}
TEST(Mathfunction, add) {
PERF_TEST test;
test.Test_Add(acl_context_0);
}
TEST(Mathfunction, log)
{
PERF_TEST test;
test.Test_Log(acl_context_0);
}
TEST(Mathfunction, divide) {
PERF_TEST test;
test.Test_Divide(acl_context_0);
}
TEST(Mathfunction, max)
{
PERF_TEST test;
test.Test_Max(acl_context_0);
}
TEST(Mathfunction, exp) {
PERF_TEST test;
test.Test_Exp(acl_context_0);
}
TEST(Mathfunction, min)
{
PERF_TEST test;
test.Test_Min(acl_context_0);
}
TEST(Mathfunction, log) {
PERF_TEST test;
test.Test_Log(acl_context_0);
}
TEST(Gemm, MatMul)
{
PERF_TEST test;
test.Test_MatMul(acl_context_0);
}
TEST(Mathfunction, max) {
PERF_TEST test;
test.Test_Max(acl_context_0);
}
TEST(Gemm, Convolution)
{
PERF_TEST test;
test.Test_Convolution(acl_context_0);
}
TEST(Mathfunction, min) {
PERF_TEST test;
test.Test_Min(acl_context_0);
}
TEST(Matrices, merge)
{
PERF_TEST test;
test.Test_Merge(acl_context_0);
}
TEST(Gemm, MatMul) {
PERF_TEST test;
test.Test_MatMul(acl_context_0);
}
TEST(Matrices, split)
{
PERF_TEST test;
test.Test_Split(acl_context_0);
}
TEST(Gemm, Convolution) {
PERF_TEST test;
test.Test_Convolution(acl_context_0);
}
TEST(Matrices, merge) {
PERF_TEST test;
test.Test_Merge(acl_context_0);
}
TEST(Matrices, transpose)
{
PERF_TEST test;
test.Test_Transpose(acl_context_0);
}
TEST(Matrices, split) {
PERF_TEST test;
test.Test_Split(acl_context_0);
}
TEST(Matrices, flip)
{
PERF_TEST test;
test.Test_Flip(acl_context_0);
release_device(acl_context_0);
}
}
}
TEST(Matrices, transpose) {
PERF_TEST test;
test.Test_Transpose(acl_context_0);
}
TEST(Matrices, flip) {
PERF_TEST test;
test.Test_Flip(acl_context_0);
release_device(acl_context_0);
}
} // namespace
} // namespace opencv_test

View File

@@ -1,2 +1 @@
{
}
{}

View File

@@ -1,216 +1,202 @@
#include "test_common.hpp"
#include "test_perf.hpp"
using namespace cv;
using namespace cv::acl;
using namespace cvtest;
using namespace testing;
using namespace std;
void PERF_TEST::Test_operator_add_perf(aclCxt *acl_context)
{
int val, n;
int valmax = 8192;
int cycle_index = 10;
double begin, end, time, acltime;
Common_Test test;
void PERF_TEST::Test_operator_add_perf(aclCxt *acl_context) {
int val, n;
int valmax = 8192;
int cycle_index = 10;
double begin, end, time, acltime;
Common_Test test;
vector<int> type{CV_8UC1, CV_32FC1, CV_32SC1, CV_64FC1};
for (size_t i = 0; i < type.size(); ++i)
{
test.PrintLog("Perf test : Function: operator+=()", type[i]);
for (val = 8; val <= valmax; val *= 2)
{
n = cycle_index;
Mat mat_src(val, val, type[i]);
Mat mat_dest(val, val, type[i]);
Mat mat_dest1(val, val, type[i]);
vector<int> type{CV_8UC1, CV_32FC1, CV_32SC1, CV_64FC1};
for (size_t i = 0; i < type.size(); ++i) {
test.PrintLog("Perf test : Function: operator+=()", type[i]);
for (val = 8; val <= valmax; val *= 2) {
n = cycle_index;
Mat mat_src(val, val, type[i]);
Mat mat_dest(val, val, type[i]);
Mat mat_dest1(val, val, type[i]);
test.SetDataRange(mat_src, 1);
test.SetDataRange(mat_dest, 1);
test.SetDataRange(mat_src, 1);
test.SetDataRange(mat_dest, 1);
aclMat aclmat_src(val, val, type[i], mat_src.data, acl_context);
aclMat aclmat_dest(val, val, type[i], mat_dest.data, acl_context);
aclMat aclmat_src(val, val, type[i], mat_src.data, acl_context);
aclMat aclmat_dest(val, val, type[i], mat_dest.data, acl_context);
begin = static_cast<double>(getTickCount());
while (n--)
mat_dest += mat_src;
end = static_cast<double>(getTickCount());
time = (end - begin) / getTickFrequency() / cycle_index;
begin = static_cast<double>(getTickCount());
while (n--) mat_dest += mat_src;
end = static_cast<double>(getTickCount());
time = (end - begin) / getTickFrequency() / cycle_index;
n = (cycle_index - 1);
aclmat_dest += aclmat_src;
wait_stream(acl_context);
begin = static_cast<double>(getTickCount());
while (n--)
aclmat_dest += aclmat_src;
wait_stream(acl_context);
end = static_cast<double>(getTickCount());
acltime = (end - begin) / getTickFrequency() / (cycle_index - 1);
n = (cycle_index - 1);
aclmat_dest += aclmat_src;
wait_stream(acl_context);
begin = static_cast<double>(getTickCount());
while (n--) aclmat_dest += aclmat_src;
wait_stream(acl_context);
end = static_cast<double>(getTickCount());
acltime = (end - begin) / getTickFrequency() / (cycle_index - 1);
aclmat_dest.download(mat_dest1);
bool ret = test.Test_Diff(mat_dest, mat_dest1);
ASSERT_TRUE(ret);
if (val < 128)
cout << "Shape: " << val << " x " << val << "\t\t";
else
cout << "Shape: " << val << " x " << val << "\t";
cout << "CpuTimes: " << time << "\tAclTimes: " << acltime << "\tRate: " << time / acltime << endl;
}
aclmat_dest.download(mat_dest1);
bool ret = test.Test_Diff(mat_dest, mat_dest1);
ASSERT_TRUE(ret);
if (val < 128)
cout << "Shape: " << val << " x " << val << "\t\t";
else
cout << "Shape: " << val << " x " << val << "\t";
cout << "CpuTimes: " << time << "\tAclTimes: " << acltime
<< "\tRate: " << time / acltime << endl;
}
}
}
void PERF_TEST::Test_operator_sub_perf(aclCxt *acl_context)
{
int val, n;
int valmax = 8192;
int cycle_index = 10;
double begin, end, time, acltime;
Common_Test test;
void PERF_TEST::Test_operator_sub_perf(aclCxt *acl_context) {
int val, n;
int valmax = 8192;
int cycle_index = 10;
double begin, end, time, acltime;
Common_Test test;
vector<int> type{CV_8UC1, CV_32FC1, CV_32SC1,CV_64FC1};
//vector<int> type{CV_64FC1};
for (size_t i = 0; i < type.size(); ++i)
{
test.PrintLog("Perf test : Function: operator-=()", type[i]);
for (val = 8; val <= valmax; val *= 2)
{
n = cycle_index;
Mat mat_src(val, val, type[i]);
Mat mat_dest(val, val, type[i]);
Mat mat_dest1(val, val, type[i]);
vector<int> type{CV_8UC1, CV_32FC1, CV_32SC1, CV_64FC1};
// vector<int> type{CV_64FC1};
for (size_t i = 0; i < type.size(); ++i) {
test.PrintLog("Perf test : Function: operator-=()", type[i]);
for (val = 8; val <= valmax; val *= 2) {
n = cycle_index;
Mat mat_src(val, val, type[i]);
Mat mat_dest(val, val, type[i]);
Mat mat_dest1(val, val, type[i]);
test.SetDataRange(mat_src, 4);
test.SetDataRange(mat_dest, 32);
test.SetDataRange(mat_src, 4);
test.SetDataRange(mat_dest, 32);
aclMat aclmat_src(val, val, type[i], mat_src.data, acl_context);
aclMat aclmat_dest(val, val, type[i], mat_dest.data, acl_context);
aclMat aclmat_src(val, val, type[i], mat_src.data, acl_context);
aclMat aclmat_dest(val, val, type[i], mat_dest.data, acl_context);
begin = static_cast<double>(getTickCount());
while (n--)
mat_dest -= mat_src;
end = static_cast<double>(getTickCount());
time = (end - begin) / getTickFrequency() / cycle_index;
begin = static_cast<double>(getTickCount());
while (n--) mat_dest -= mat_src;
end = static_cast<double>(getTickCount());
time = (end - begin) / getTickFrequency() / cycle_index;
n = (cycle_index - 1);
aclmat_dest -= aclmat_src;
wait_stream(acl_context);
begin = static_cast<double>(getTickCount());
while (n--)
aclmat_dest -= aclmat_src;
wait_stream(acl_context);
end = static_cast<double>(getTickCount());
acltime = (end - begin) / getTickFrequency() / (cycle_index - 1);
n = (cycle_index - 1);
aclmat_dest -= aclmat_src;
wait_stream(acl_context);
begin = static_cast<double>(getTickCount());
while (n--) aclmat_dest -= aclmat_src;
wait_stream(acl_context);
end = static_cast<double>(getTickCount());
acltime = (end - begin) / getTickFrequency() / (cycle_index - 1);
aclmat_dest.download(mat_dest1);
//bool ret = test.Test_Diff(mat_dest, mat_dest1);
//ASSERT_TRUE(ret);
if (val < 128)
cout << "Shape: " << val << " x " << val << "\t\t";
else
cout << "Shape: " << val << " x " << val << "\t";
cout << "CpuTimes: " << time << "\tAclTimes: " << acltime << "\tRate: " << time / acltime << endl;
}
aclmat_dest.download(mat_dest1);
// bool ret = test.Test_Diff(mat_dest, mat_dest1);
// ASSERT_TRUE(ret);
if (val < 128)
cout << "Shape: " << val << " x " << val << "\t\t";
else
cout << "Shape: " << val << " x " << val << "\t";
cout << "CpuTimes: " << time << "\tAclTimes: " << acltime
<< "\tRate: " << time / acltime << endl;
}
}
}
void PERF_TEST::Test_operator_div_perf(aclCxt *acl_context)
{
int val, n;
int valmax = 8192;
int cycle_index = 10;
double begin, end, time, acltime;
Common_Test test;
void PERF_TEST::Test_operator_div_perf(aclCxt *acl_context) {
int val, n;
int valmax = 8192;
int cycle_index = 10;
double begin, end, time, acltime;
Common_Test test;
//vector<int> type{CV_32FC1};
vector<int> type{CV_8UC1,CV_32FC1, CV_32SC1, CV_64FC1};
for (size_t i = 0; i < type.size(); ++i)
{
test.PrintLog("Perf test : Function: operator/=()", type[i]);
for (val = 8; val <= valmax; val *= 2)
{
n = cycle_index;
Mat mat_src(val, val, type[i], Scalar(1, 2, 4));
Mat mat_dest(val, val, type[i], Scalar(2, 4, 8));
Mat mat_dest1(val, val, type[i]);
// vector<int> type{CV_32FC1};
vector<int> type{CV_8UC1, CV_32FC1, CV_32SC1, CV_64FC1};
for (size_t i = 0; i < type.size(); ++i) {
test.PrintLog("Perf test : Function: operator/=()", type[i]);
for (val = 8; val <= valmax; val *= 2) {
n = cycle_index;
Mat mat_src(val, val, type[i], Scalar(1, 2, 4));
Mat mat_dest(val, val, type[i], Scalar(2, 4, 8));
Mat mat_dest1(val, val, type[i]);
aclMat aclmat_src(val, val, type[i], mat_src.data, acl_context);
aclMat aclmat_dest(val, val, type[i], mat_dest.data, acl_context);
aclMat aclmat_src(val, val, type[i], mat_src.data, acl_context);
aclMat aclmat_dest(val, val, type[i], mat_dest.data, acl_context);
begin = static_cast<double>(getTickCount());
while (n--)
mat_dest /= mat_src;
end = static_cast<double>(getTickCount());
time = (end - begin) / getTickFrequency() / cycle_index;
begin = static_cast<double>(getTickCount());
while (n--) mat_dest /= mat_src;
end = static_cast<double>(getTickCount());
time = (end - begin) / getTickFrequency() / cycle_index;
n = (cycle_index - 1);
aclmat_dest /= aclmat_src;
wait_stream(acl_context);
begin = static_cast<double>(getTickCount());
while (n--)
aclmat_dest /= aclmat_src;
wait_stream(acl_context);
end = static_cast<double>(getTickCount());
acltime = (end - begin) / getTickFrequency() / (cycle_index - 1);
n = (cycle_index - 1);
aclmat_dest /= aclmat_src;
wait_stream(acl_context);
begin = static_cast<double>(getTickCount());
while (n--) aclmat_dest /= aclmat_src;
wait_stream(acl_context);
end = static_cast<double>(getTickCount());
acltime = (end - begin) / getTickFrequency() / (cycle_index - 1);
aclmat_dest.download(mat_dest1);
//bool ret = test.Test_Diff(mat_dest, mat_dest1);
//ASSERT_TRUE(ret);
if (val < 128)
cout << "Shape: " << val << " x " << val << "\t\t";
else
cout << "Shape: " << val << " x " << val << "\t";
cout << "CpuTimes: " << time << "\tAclTimes: " << acltime << "\tRate: " << time / acltime << endl;
}
aclmat_dest.download(mat_dest1);
// bool ret = test.Test_Diff(mat_dest, mat_dest1);
// ASSERT_TRUE(ret);
if (val < 128)
cout << "Shape: " << val << " x " << val << "\t\t";
else
cout << "Shape: " << val << " x " << val << "\t";
cout << "CpuTimes: " << time << "\tAclTimes: " << acltime
<< "\tRate: " << time / acltime << endl;
}
}
}
void PERF_TEST::Test_operator_mul_perf(aclCxt *acl_context)
{
int val, n;
int valmax = 4096;
int cycle_index = 10;
double begin, end, time, acltime;
Common_Test test;
vector<int> type{CV_32FC1};
void PERF_TEST::Test_operator_mul_perf(aclCxt *acl_context) {
int val, n;
int valmax = 4096;
int cycle_index = 10;
double begin, end, time, acltime;
Common_Test test;
vector<int> type{CV_32FC1};
for (size_t i = 0; i < type.size(); ++i)
{
for (val = 8; val <= valmax; val *= 2)
{
n = cycle_index;
Mat mat_src(val, val, type[i]);
Mat mat_dest(val, val, type[i]);
Mat mat_dest1(val, val, type[i]);
for (size_t i = 0; i < type.size(); ++i) {
for (val = 8; val <= valmax; val *= 2) {
n = cycle_index;
Mat mat_src(val, val, type[i]);
Mat mat_dest(val, val, type[i]);
Mat mat_dest1(val, val, type[i]);
test.SetDataRange(mat_src, 1);
test.SetDataRange(mat_dest, 1);
test.SetDataRange(mat_src, 1);
test.SetDataRange(mat_dest, 1);
aclMat aclmat_src(val, val, type[i], mat_src.data, acl_context);
aclMat aclmat_dest(val, val, type[i], mat_dest.data, acl_context);
aclMat aclmat_src(val, val, type[i], mat_src.data, acl_context);
aclMat aclmat_dest(val, val, type[i], mat_dest.data, acl_context);
begin = static_cast<double>(getTickCount());
while (n--)
mat_dest *= mat_src;
end = static_cast<double>(getTickCount());
time = (end - begin) / getTickFrequency() / cycle_index;
begin = static_cast<double>(getTickCount());
while (n--) mat_dest *= mat_src;
end = static_cast<double>(getTickCount());
time = (end - begin) / getTickFrequency() / cycle_index;
n = (cycle_index - 1);
aclmat_dest *= aclmat_src;
wait_stream(acl_context);
begin = static_cast<double>(getTickCount());
while (n--)
aclmat_dest *= aclmat_src;
wait_stream(acl_context);
end = static_cast<double>(getTickCount());
acltime = (end - begin) / getTickFrequency() / (cycle_index - 1);
n = (cycle_index - 1);
aclmat_dest *= aclmat_src;
wait_stream(acl_context);
begin = static_cast<double>(getTickCount());
while (n--) aclmat_dest *= aclmat_src;
wait_stream(acl_context);
end = static_cast<double>(getTickCount());
acltime = (end - begin) / getTickFrequency() / (cycle_index - 1);
aclmat_dest.download(mat_dest1);
bool ret = test.Test_Diff(mat_dest, mat_dest1);
ASSERT_TRUE(ret);
if (val < 128)
cout << "Shape: " << val << " x " << val << "\t\t";
else
cout << "Shape: " << val << " x " << val << "\t";
cout << "CpuTimes: " << time << "\tAclTimes: " << acltime << "\tRate: " << time / acltime << endl;
}
aclmat_dest.download(mat_dest1);
bool ret = test.Test_Diff(mat_dest, mat_dest1);
ASSERT_TRUE(ret);
if (val < 128)
cout << "Shape: " << val << " x " << val << "\t\t";
else
cout << "Shape: " << val << " x " << val << "\t";
cout << "CpuTimes: " << time << "\tAclTimes: " << acltime
<< "\tRate: " << time / acltime << endl;
}
}
}

View File

@@ -1,306 +1,319 @@
#include "test_common.hpp"
Common_Test::Common_Test() {
srand((unsigned)time(NULL));
using namespace cv;
using namespace cv::acl;
using namespace cvtest;
using namespace testing;
using namespace std;
Common_Test::Common_Test() { srand((unsigned)time(NULL)); }
Common_Test::~Common_Test() {}
bool Common_Test::Test_Diff(const aclMat &aclmat, const Mat &mat,
ALIGNMENT config) {
bool is_correct;
if (config == ALIGNMENT::MEMORY_UNALIGNED) {
is_correct = (aclmat.rows == mat.rows);
is_correct &= (aclmat.cols == mat.cols);
is_correct &= (aclmat.channels() == mat.channels());
is_correct &= (aclmat.type() == mat.type());
is_correct &= (aclmat.step == mat.step);
is_correct &= (aclmat.elemSize() == mat.elemSize());
is_correct &= (aclmat.totalSize == mat.total() * mat.elemSize());
is_correct &=
((aclmat.dataend - aclmat.datastart) == (mat.dataend - mat.datastart));
Mat mat_dest(mat.rows, mat.cols, mat.type());
aclmat.download(mat_dest);
is_correct &= Test_Diff(mat, mat_dest);
} else {
is_correct = (aclmat.rows == mat.rows);
is_correct &= (aclmat.cols == mat.cols);
is_correct &= (aclmat.channels() == mat.channels());
is_correct &= (aclmat.type() == mat.type());
is_correct &= (aclmat.elemSize() == mat.elemSize());
Mat mat_dest(mat.rows, mat.cols, mat.type());
aclmat.download(mat_dest, MEMORY_ALIGN);
is_correct &= Test_Diff(mat, mat_dest);
}
return is_correct;
}
Common_Test::~Common_Test() {
bool Common_Test::Test_Diff(const aclMat &aclmat, const aclMat &aclmat_other) {
bool is_correct;
is_correct = (aclmat.flags == aclmat_other.flags);
is_correct &= (aclmat.rows == aclmat_other.rows);
is_correct &= (aclmat.cols == aclmat_other.cols);
is_correct &= (aclmat.type() == aclmat_other.type());
is_correct &= (aclmat.step == aclmat_other.step);
is_correct &= (aclmat.data == aclmat_other.data);
is_correct &= (aclmat.refcount == aclmat_other.refcount);
is_correct &= (aclmat.datastart == aclmat_other.datastart);
is_correct &= (aclmat.dataend == aclmat_other.dataend);
is_correct &= (aclmat.offset == aclmat_other.offset);
is_correct &= (aclmat.wholerows == aclmat_other.wholerows);
is_correct &= (aclmat.wholecols == aclmat_other.wholecols);
is_correct &= (aclmat.acl_context == aclmat_other.acl_context);
is_correct &= (aclmat.totalSize == aclmat_other.totalSize);
return is_correct;
}
bool Common_Test::Test_Diff(const aclMat& aclmat, const Mat& mat, ALIGNMENT config) {
bool is_correct;
bool Common_Test::Test_Diff(const Mat &mat, const Mat &mat_other) {
bool is_correct;
if (config == ALIGNMENT::MEMORY_UNALIGNED)
{
is_correct = (aclmat.rows == mat.rows);
is_correct &= (aclmat.cols == mat.cols);
is_correct &= (aclmat.channels() == mat.channels());
is_correct &= (aclmat.type() == mat.type());
is_correct &= (aclmat.step == mat.step);
is_correct &= (aclmat.elemSize() == mat.elemSize());
is_correct &= (aclmat.totalSize == mat.total() * mat.elemSize());
is_correct &= ((aclmat.dataend - aclmat.datastart) == (mat.dataend - mat.datastart));
Mat mat_dest(mat.rows, mat.cols, mat.type());
aclmat.download(mat_dest);
is_correct &= Test_Diff(mat, mat_dest);
}
else
{
is_correct = (aclmat.rows == mat.rows);
is_correct &= (aclmat.cols == mat.cols);
is_correct &= (aclmat.channels() == mat.channels());
is_correct &= (aclmat.type() == mat.type());
is_correct &= (aclmat.elemSize() == mat.elemSize());
is_correct = (mat.rows == mat_other.rows);
is_correct &= (mat.cols == mat_other.cols);
is_correct &= (mat.type() == mat_other.type());
is_correct &= (mat.channels() == mat.channels());
is_correct &= (mat.step == mat_other.step);
is_correct &= (mat.elemSize() == mat_other.elemSize());
is_correct &= (mat.total() == mat_other.total());
Mat mat_dest(mat.rows, mat.cols, mat.type());
aclmat.download(mat_dest, MEMORY_ALIGN);
is_correct &= Test_Diff(mat, mat_dest);
}
return is_correct;
}
bool Common_Test::Test_Diff(const aclMat& aclmat, const aclMat& aclmat_other) {
bool is_correct;
is_correct = (aclmat.flags == aclmat_other.flags);
is_correct &= (aclmat.rows == aclmat_other.rows);
is_correct &= (aclmat.cols == aclmat_other.cols);
is_correct &= (aclmat.type() == aclmat_other.type());
is_correct &= (aclmat.step == aclmat_other.step);
is_correct &= (aclmat.data == aclmat_other.data);
is_correct &= (aclmat.refcount == aclmat_other.refcount);
is_correct &= (aclmat.datastart == aclmat_other.datastart);
is_correct &= (aclmat.dataend == aclmat_other.dataend);
is_correct &= (aclmat.offset == aclmat_other.offset);
is_correct &= (aclmat.wholerows == aclmat_other.wholerows);
is_correct &= (aclmat.wholecols == aclmat_other.wholecols);
is_correct &= (aclmat.acl_context == aclmat_other.acl_context);
is_correct &= (aclmat.totalSize == aclmat_other.totalSize);
return is_correct;
}
bool Common_Test::Test_Diff(const Mat &mat, const Mat &mat_other)
{
bool is_correct;
is_correct = (mat.rows == mat_other.rows);
is_correct &= (mat.cols == mat_other.cols);
is_correct &= (mat.type() == mat_other.type());
is_correct &= (mat.channels() == mat.channels());
is_correct &= (mat.step == mat_other.step);
is_correct &= (mat.elemSize() == mat_other.elemSize());
is_correct &= (mat.total() == mat_other.total());
switch (mat.depth())
{
switch (mat.depth()) {
case CV_8U:
for (int i = 0; (is_correct == true) && (i < mat.rows * mat.cols * mat.channels()); i += mat.channels())
{
for (int j = 0; j < mat.channels(); ++j)
is_correct &= ((mat.data)[i+j] == (mat_other.data)[i+j]);
}
return is_correct;
for (int i = 0;
(is_correct == true) && (i < mat.rows * mat.cols * mat.channels());
i += mat.channels()) {
for (int j = 0; j < mat.channels(); ++j)
is_correct &= ((mat.data)[i + j] == (mat_other.data)[i + j]);
}
return is_correct;
case CV_16U:
for (int i = 0; (is_correct == true) && (i < mat.rows * mat.cols * mat.channels()); i += mat.channels())
{
for (int j = 0; j < mat.channels(); ++j)
is_correct &= (((unsigned short *)mat.data)[i+j] == ((unsigned short *)mat_other.data)[i+j]);
}
return is_correct;
for (int i = 0;
(is_correct == true) && (i < mat.rows * mat.cols * mat.channels());
i += mat.channels()) {
for (int j = 0; j < mat.channels(); ++j)
is_correct &= (((unsigned short *)mat.data)[i + j] ==
((unsigned short *)mat_other.data)[i + j]);
}
return is_correct;
case CV_32S:
for (int i = 0; (is_correct == true) && (i < mat.rows * mat.cols * mat.channels()); i += mat.channels())
{
for (int j = 0; j < mat.channels(); ++j)
is_correct &= (((int *)(mat.data))[i+j] == (((int *)mat_other.data))[i+j]);
}
return is_correct;
for (int i = 0;
(is_correct == true) && (i < mat.rows * mat.cols * mat.channels());
i += mat.channels()) {
for (int j = 0; j < mat.channels(); ++j)
is_correct &=
(((int *)(mat.data))[i + j] == (((int *)mat_other.data))[i + j]);
}
return is_correct;
case CV_32F:
for (int i = 0; (is_correct == true) && (i < mat.rows * mat.cols * mat.channels()); i += mat.channels())
{
for (int j = 0; j < mat.channels(); ++j)
is_correct &= ((((float *)(mat.data))[i+j] - (((float *)mat_other.data))[i+j] >= -0.00001) || \
(((float *)(mat.data))[i+j] - (((float *)mat_other.data))[i+j] <= 0.00001));
}
return is_correct;
for (int i = 0;
(is_correct == true) && (i < mat.rows * mat.cols * mat.channels());
i += mat.channels()) {
for (int j = 0; j < mat.channels(); ++j)
is_correct &= ((((float *)(mat.data))[i + j] -
(((float *)mat_other.data))[i + j] >=
-0.00001) ||
(((float *)(mat.data))[i + j] -
(((float *)mat_other.data))[i + j] <=
0.00001));
}
return is_correct;
case CV_64F:
for (int i = 0; (is_correct == true) && (i < mat.rows * mat.cols * mat.channels()); i += mat.channels())
{
for (int j = 0; j < mat.channels(); ++j)
is_correct &= ((((double *)(mat.data))[i+j] - (((double *)mat_other.data))[i+j] >= -0.00001) || \
(((double *)(mat.data))[i+j] - (((double *)mat_other.data))[i+j] <= 0.00001));
}
return is_correct;
}
return is_correct;
for (int i = 0;
(is_correct == true) && (i < mat.rows * mat.cols * mat.channels());
i += mat.channels()) {
for (int j = 0; j < mat.channels(); ++j)
is_correct &= ((((double *)(mat.data))[i + j] -
(((double *)mat_other.data))[i + j] >=
-0.00001) ||
(((double *)(mat.data))[i + j] -
(((double *)mat_other.data))[i + j] <=
0.00001));
}
return is_correct;
}
return is_correct;
}
void Common_Test::MatShow(cv::Mat &m, string str)
{
cout << str.c_str() << endl;
cout << m;
cout << endl
<< endl
<< endl;
void Common_Test::MatShow(cv::Mat &m, string str) {
cout << str.c_str() << endl;
cout << m;
cout << endl << endl << endl;
}
void Common_Test::StatShow(cv::Mat &mat_src, aclMat &aclmat_dst)
{
cout << "//////////////////////////////// MatStat ////////////////////////////////" << endl;
cout << "type: " << mat_src.type() << endl;
cout << "elemSize: " << mat_src.elemSize() << endl;
cout << "channels: " << mat_src.channels() << endl;
cout << "step: " << mat_src.step << endl;
cout << "totalSize: " << mat_src.rows * mat_src.cols * mat_src.elemSize() << endl;
cout << "totalSize: " << mat_src.total() * mat_src.elemSize() << endl;
cout << "dataend - datastart: " << mat_src.dataend - mat_src.datastart << endl;
void Common_Test::StatShow(cv::Mat &mat_src, aclMat &aclmat_dst) {
cout << "//////////////////////////////// MatStat "
"////////////////////////////////"
<< endl;
cout << "type: " << mat_src.type() << endl;
cout << "elemSize: " << mat_src.elemSize() << endl;
cout << "channels: " << mat_src.channels() << endl;
cout << "step: " << mat_src.step << endl;
cout << "totalSize: " << mat_src.rows * mat_src.cols * mat_src.elemSize()
<< endl;
cout << "totalSize: " << mat_src.total() * mat_src.elemSize() << endl;
cout << "dataend - datastart: " << mat_src.dataend - mat_src.datastart
<< endl;
cout << "//////////////////////////////// aclMatStat ////////////////////////////////" << endl;
cout << "type: " << aclmat_dst.type() << endl;
cout << "elemSize: " << aclmat_dst.elemSize() << endl;
cout << "channels: " << aclmat_dst.channels() << endl;
cout << "step: " << aclmat_dst.step << endl;
cout << "totalSize: " << aclmat_dst.rows * aclmat_dst.step << endl;
cout << "totalSize: " << aclmat_dst.totalSize << endl;
cout << "dataend - datastart: " << aclmat_dst.dataend - aclmat_dst.datastart << endl;
cout << "wholerows: " << aclmat_dst.wholerows << endl;
cout << "wholecols: " << aclmat_dst.wholecols << endl;
cout << "offset : " << aclmat_dst.offset << endl;
cout << "//////////////////////////////// aclMatStat "
"////////////////////////////////"
<< endl;
cout << "type: " << aclmat_dst.type() << endl;
cout << "elemSize: " << aclmat_dst.elemSize() << endl;
cout << "channels: " << aclmat_dst.channels() << endl;
cout << "step: " << aclmat_dst.step << endl;
cout << "totalSize: " << aclmat_dst.rows * aclmat_dst.step << endl;
cout << "totalSize: " << aclmat_dst.totalSize << endl;
cout << "dataend - datastart: " << aclmat_dst.dataend - aclmat_dst.datastart
<< endl;
cout << "wholerows: " << aclmat_dst.wholerows << endl;
cout << "wholecols: " << aclmat_dst.wholecols << endl;
cout << "offset : " << aclmat_dst.offset << endl;
}
void Common_Test::PrintLog(const string& funcname, int type)
{
switch (type)
{
void Common_Test::PrintLog(const string &funcname, int type) {
switch (type) {
case CV_8UC1:
cout << funcname << "\t"
<< "Type: CV_8UC1" << endl;
break;
cout << funcname << "\t"
<< "Type: CV_8UC1" << endl;
break;
case CV_8UC2:
cout << funcname << "\t"
<< "Type: CV_8UC2" << endl;
break;
cout << funcname << "\t"
<< "Type: CV_8UC2" << endl;
break;
case CV_8UC3:
cout << funcname << "\t"
<< "Type: CV_8UC3" << endl;
break;
cout << funcname << "\t"
<< "Type: CV_8UC3" << endl;
break;
case CV_8UC4:
cout << funcname << "\t"
<< "Type: CV_8UC4" << endl;
break;
cout << funcname << "\t"
<< "Type: CV_8UC4" << endl;
break;
case CV_8SC1:
cout << funcname << "\t"
<< "Type: CV_8SC1" << endl;
break;
cout << funcname << "\t"
<< "Type: CV_8SC1" << endl;
break;
case CV_8SC2:
cout << funcname << "\t"
<< "Type: CV_8SC2" << endl;
break;
cout << funcname << "\t"
<< "Type: CV_8SC2" << endl;
break;
case CV_8SC3:
cout << funcname << "\t"
<< "Type: CV_8SC3" << endl;
break;
cout << funcname << "\t"
<< "Type: CV_8SC3" << endl;
break;
case CV_8SC4:
cout << funcname << "\t"
<< "Type: CV_8SC4" << endl;
break;
cout << funcname << "\t"
<< "Type: CV_8SC4" << endl;
break;
case CV_16FC1:
cout << funcname << "\t"
<< "Type: CV_16FC1" << endl;
break;
cout << funcname << "\t"
<< "Type: CV_16FC1" << endl;
break;
case CV_16FC2:
cout << funcname << "\t"
<< "Type: CV_16FC2" << endl;
break;
cout << funcname << "\t"
<< "Type: CV_16FC2" << endl;
break;
case CV_16FC3:
cout << funcname << "\t"
<< "Type: CV_16FC3" << endl;
break;
cout << funcname << "\t"
<< "Type: CV_16FC3" << endl;
break;
case CV_16FC4:
cout << funcname << "\t"
<< "Type: CV_16FC4" << endl;
break;
cout << funcname << "\t"
<< "Type: CV_16FC4" << endl;
break;
case CV_32FC1:
cout << funcname << "\t"
<< "Type: CV_32FC1" << endl;
break;
cout << funcname << "\t"
<< "Type: CV_32FC1" << endl;
break;
case CV_32FC2:
cout << funcname << "\t"
<< "Type: CV_32FC2" << endl;
break;
cout << funcname << "\t"
<< "Type: CV_32FC2" << endl;
break;
case CV_32FC3:
cout << funcname << "\t"
<< "Type: CV_32FC3" << endl;
break;
cout << funcname << "\t"
<< "Type: CV_32FC3" << endl;
break;
case CV_32FC4:
cout << funcname << "\t"
<< "Type: CV_32FC4" << endl;
break;
cout << funcname << "\t"
<< "Type: CV_32FC4" << endl;
break;
case CV_32SC1:
cout << funcname << "\t"
<< "Type: CV_32SC1" << endl;
break;
cout << funcname << "\t"
<< "Type: CV_32SC1" << endl;
break;
case CV_32SC2:
cout << funcname << "\t"
<< "Type: CV_32SC2" << endl;
break;
cout << funcname << "\t"
<< "Type: CV_32SC2" << endl;
break;
case CV_32SC3:
cout << funcname << "\t"
<< "Type: CV_32SC3" << endl;
break;
cout << funcname << "\t"
<< "Type: CV_32SC3" << endl;
break;
case CV_32SC4:
cout << funcname << "\t"
<< "Type: CV_32SC4" << endl;
break;
cout << funcname << "\t"
<< "Type: CV_32SC4" << endl;
break;
case CV_64FC1:
cout << funcname << "\t"
<< "Type: CV_64FC1" << endl;
break;
cout << funcname << "\t"
<< "Type: CV_64FC1" << endl;
break;
case CV_64FC2:
cout << funcname << "\t"
<< "Type: CV_64FC2" << endl;
break;
cout << funcname << "\t"
<< "Type: CV_64FC2" << endl;
break;
case CV_64FC3:
cout << funcname << "\t"
<< "Type: CV_64FC3" << endl;
break;
cout << funcname << "\t"
<< "Type: CV_64FC3" << endl;
break;
case CV_64FC4:
cout << funcname << "\t"
<< "Type: CV_64FC4" << endl;
break;
cout << funcname << "\t"
<< "Type: CV_64FC4" << endl;
break;
default:
break;
}
break;
}
}
/* srand((unsigned)time(NULL)) in constructor */
size_t Common_Test::RandDom_(int config) {
return static_cast<size_t>(rand() % config);
return static_cast<size_t>(rand() % config);
}
bool Common_Test::SetDataRange(Mat &src, int dataRange)
{
switch (src.depth())
{
bool Common_Test::SetDataRange(Mat &src, int dataRange) {
switch (src.depth()) {
case CV_8U:
for (int i = 0; i < src.rows * src.cols * src.channels(); i += src.channels())
{
for (int j = 0; j < src.channels(); ++j)
(src.data)[i+j] = RandDom_(dataRange) + 1;
}
return true;
for (int i = 0; i < src.rows * src.cols * src.channels();
i += src.channels()) {
for (int j = 0; j < src.channels(); ++j)
(src.data)[i + j] = RandDom_(dataRange) + 1;
}
return true;
case CV_16U:
for (int i = 0; i < src.rows * src.cols * src.channels(); i += src.channels())
{
for (int j = 0; j < src.channels(); ++j)
((unsigned short *)src.data)[i+j] = RandDom_(dataRange) + 1;
}
return true;
for (int i = 0; i < src.rows * src.cols * src.channels();
i += src.channels()) {
for (int j = 0; j < src.channels(); ++j)
((unsigned short *)src.data)[i + j] = RandDom_(dataRange) + 1;
}
return true;
case CV_32S:
for (int i = 0; i < src.rows * src.cols * src.channels(); i += src.channels())
{
for (int j = 0; j < src.channels(); ++j)
((int *)src.data)[i+j] = RandDom_(dataRange) + 1;
}
return true;
for (int i = 0; i < src.rows * src.cols * src.channels();
i += src.channels()) {
for (int j = 0; j < src.channels(); ++j)
((int *)src.data)[i + j] = RandDom_(dataRange) + 1;
}
return true;
case CV_32F:
for (int i = 0; i < src.rows * src.cols * src.channels(); i += src.channels())
{
for (int j = 0; j < src.channels(); ++j)
((float *)src.data)[i+j] = RandDom_(dataRange) / 1.0 + 1;
}
return true;
for (int i = 0; i < src.rows * src.cols * src.channels();
i += src.channels()) {
for (int j = 0; j < src.channels(); ++j)
((float *)src.data)[i + j] = RandDom_(dataRange) / 1.0 + 1;
}
return true;
case CV_64F:
for (int i = 0; i < src.rows * src.cols * src.channels(); i += src.channels())
{
for (int j = 0; j < src.channels(); ++j)
((double *)src.data)[i+j] = RandDom_(dataRange) / 1.0 + 1;
}
return true;
for (int i = 0; i < src.rows * src.cols * src.channels();
i += src.channels()) {
for (int j = 0; j < src.channels(); ++j)
((double *)src.data)[i + j] = RandDom_(dataRange) / 1.0 + 1;
}
return true;
default:
return false;
}
return false;
}
}

View File

@@ -3,25 +3,24 @@
#include "test_precomp.hpp"
typedef enum TestDatatype {
INT = 1,
FLOAT
} TestDatatype;
typedef enum TestDatatype { INT = 1, FLOAT } TestDatatype;
class CV_EXPORTS Common_Test {
public:
Common_Test();
~Common_Test();
CV_EXPORTS bool Test_Diff(const aclMat& aclmat, const Mat& mat, ALIGNMENT config = ALIGNMENT::MEMORY_UNALIGNED);
CV_EXPORTS bool Test_Diff(const aclMat& aclmat, const aclMat& aclmat_other);
CV_EXPORTS bool Test_Diff(const Mat& mat, const Mat& mat_other);
CV_EXPORTS void MatShow(Mat &m, string str);
CV_EXPORTS void StatShow(Mat &mat_src, aclMat &aclmat_dst);
CV_EXPORTS void PrintLog(const string& funcname, int type);
public:
Common_Test();
~Common_Test();
CV_EXPORTS bool Test_Diff(
const cv::acl::aclMat& aclmat, const cv::Mat& mat,
cv::acl::ALIGNMENT config = cv::acl::ALIGNMENT::MEMORY_UNALIGNED);
CV_EXPORTS bool Test_Diff(const cv::acl::aclMat& aclmat,
const cv::acl::aclMat& aclmat_other);
CV_EXPORTS bool Test_Diff(const cv::Mat& mat, const cv::Mat& mat_other);
CV_EXPORTS void MatShow(cv::Mat& m, std::string str);
CV_EXPORTS void StatShow(cv::Mat& mat_src, cv::acl::aclMat& aclmat_dst);
CV_EXPORTS void PrintLog(const std::string& funcname, int type);
CV_EXPORTS size_t RandDom_(int config = 0xff);
CV_EXPORTS bool SetDataRange(Mat &src, int dataRange = 0xff);
CV_EXPORTS size_t RandDom_(int config = 0xff);
CV_EXPORTS bool SetDataRange(cv::Mat& src, int dataRange = 0xff);
};
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -2,39 +2,50 @@
#define __OPENCV_CORRECTNESS_HPP__
#include "test_precomp.hpp"
using namespace cv;
using namespace cv::acl;
using namespace cvtest;
using namespace testing;
using namespace std;
class CV_EXPORTS AclMat_Test {
public:
AclMat_Test();
~AclMat_Test();
/* test set_device() */
CV_EXPORTS void Test_set_device();
/* test aclMat(int rows, int cols, int type, aclCxt *acl_context, aclrtMemMallocPolicy policy = ACL_MEM_MALLOC_HUGE_FIRST) */
CV_EXPORTS void Test_constructor_UNALIGNED(aclCxt *acl_context);
CV_EXPORTS void Test_constructor_ALIGN(aclCxt *acl_context);
public:
AclMat_Test();
~AclMat_Test();
/* test set_device() */
CV_EXPORTS void Test_set_device();
/* test aclMat(int rows, int cols, int type, aclCxt *acl_context,
* aclrtMemMallocPolicy policy = ACL_MEM_MALLOC_HUGE_FIRST) */
CV_EXPORTS void Test_constructor_UNALIGNED(aclCxt *acl_context);
CV_EXPORTS void Test_constructor_ALIGN(aclCxt *acl_context);
/* test aclMat(const aclMat &m) */
CV_EXPORTS void Test_constructor(aclCxt *acl_context);
/* test aclMat(int rows, int cols, int type, void *data, aclCxt* acl_context, size_t step = Mat::AUTO_STEP) */
CV_EXPORTS void Test_constructor_DATA(aclCxt *acl_context);
/* test aclMat(const aclMat &m, const Range &rowRange, const Range &colRange = Range::all()) */
CV_EXPORTS void Test_constructor_RANGE(aclCxt *acl_context);
/* test aclMat(const aclMat &m, const Rect &roi) */
CV_EXPORTS void Test_constructor_ROI(aclCxt *acl_context);
/* test aclMat (const Mat &m, aclCxt* acl_context, aclrtMemMallocPolicy policy = ACL_MEM_MALLOC_HUGE_FIRST) */
CV_EXPORTS void Test_constructor_MAT(aclCxt *acl_context);
/* test upload download*/
CV_EXPORTS void Test_DATA_TRANSFER(aclCxt *acl_context);
/* test upload_2d download_2d */
CV_EXPORTS void Test_DATA_TRANSFERASYNC(aclCxt *acl_context);
/* test locateROI adjustROI */
CV_EXPORTS void Test_locateROI(aclCxt *acl_context);
/* test swap */
CV_EXPORTS void Test_swap(aclCxt *acl_context);
/* test aclMat(const aclMat &m) */
CV_EXPORTS void Test_constructor(aclCxt *acl_context);
/* test aclMat(int rows, int cols, int type, void *data, aclCxt* acl_context,
* size_t step = Mat::AUTO_STEP) */
CV_EXPORTS void Test_constructor_DATA(aclCxt *acl_context);
/* test aclMat(const aclMat &m, const Range &rowRange, const Range &colRange =
* Range::all()) */
CV_EXPORTS void Test_constructor_RANGE(aclCxt *acl_context);
/* test aclMat(const aclMat &m, const Rect &roi) */
CV_EXPORTS void Test_constructor_ROI(aclCxt *acl_context);
/* test aclMat (const Mat &m, aclCxt* acl_context, aclrtMemMallocPolicy policy
* = ACL_MEM_MALLOC_HUGE_FIRST) */
CV_EXPORTS void Test_constructor_MAT(aclCxt *acl_context);
/* test upload download*/
CV_EXPORTS void Test_DATA_TRANSFER(aclCxt *acl_context);
/* test upload_2d download_2d */
CV_EXPORTS void Test_DATA_TRANSFERASYNC(aclCxt *acl_context);
/* test locateROI adjustROI */
CV_EXPORTS void Test_locateROI(aclCxt *acl_context);
/* test swap */
CV_EXPORTS void Test_swap(aclCxt *acl_context);
CV_EXPORTS void Test_operator_add(aclCxt *acl_context);
CV_EXPORTS void Test_operator_sub(aclCxt *acl_context);
CV_EXPORTS void Test_operator_mul(aclCxt *acl_context);
CV_EXPORTS void Test_operator_div(aclCxt *acl_context);
CV_EXPORTS void Test_operator_add(aclCxt *acl_context);
CV_EXPORTS void Test_operator_sub(aclCxt *acl_context);
CV_EXPORTS void Test_operator_mul(aclCxt *acl_context);
CV_EXPORTS void Test_operator_div(aclCxt *acl_context);
};
void thread_handler(void);

View File

@@ -1,113 +1,111 @@
#include "test_common.hpp"
#include "test_perf.hpp"
void PERF_TEST::Test_MatMul(aclCxt *acl_context)
{
int val, n;
int valmax = 4096;
int cycle_index = 10;//100;
double begin, end, time, acltime;
Common_Test test;
vector<int> type{CV_32FC1};
using namespace cv;
using namespace cv::acl;
using namespace cvtest;
using namespace testing;
using namespace std;
for (size_t i = 0; i < type.size(); ++i)
{
for (val = 8; val <= valmax; val *= 2)
{
Mat mat_src(val, val, type[i]);
Mat mat_src1(val, val, type[i]);
Mat mat_dest(val, val, type[i]);
Mat mat_dest1(val, val, type[i]);
void PERF_TEST::Test_MatMul(aclCxt *acl_context) {
int val, n;
int valmax = 4096;
int cycle_index = 10; // 100;
double begin, end, time, acltime;
Common_Test test;
vector<int> type{CV_32FC1};
test.SetDataRange(mat_src, 32);
test.SetDataRange(mat_src1, 32);
test.SetDataRange(mat_dest, 32);
for (size_t i = 0; i < type.size(); ++i) {
for (val = 8; val <= valmax; val *= 2) {
Mat mat_src(val, val, type[i]);
Mat mat_src1(val, val, type[i]);
Mat mat_dest(val, val, type[i]);
Mat mat_dest1(val, val, type[i]);
aclMat aclmat_src(val, val, type[i], mat_src.data, acl_context);
aclMat aclmat_src1(val, val, type[i], mat_src1.data, acl_context);
aclMat aclmat_dest(val, val, type[i], mat_dest.data, acl_context);
test.SetDataRange(mat_src, 32);
test.SetDataRange(mat_src1, 32);
test.SetDataRange(mat_dest, 32);
n = cycle_index;
begin = static_cast<double>(getTickCount());
while (n--)
mat_dest = mat_src * mat_src1;
end = static_cast<double>(getTickCount());
time = (end - begin) / getTickFrequency() / cycle_index;
aclMat aclmat_src(val, val, type[i], mat_src.data, acl_context);
aclMat aclmat_src1(val, val, type[i], mat_src1.data, acl_context);
aclMat aclmat_dest(val, val, type[i], mat_dest.data, acl_context);
n = (cycle_index - 1);
MatMul(aclmat_src1, aclmat_src, aclmat_dest, 0);
wait_stream(acl_context, 0);
begin = static_cast<double>(getTickCount());
while (n--)
MatMul(aclmat_src1, aclmat_src, aclmat_dest, 1);
wait_stream(acl_context, 1);
end = static_cast<double>(getTickCount());
acltime = (end - begin) / getTickFrequency() / (cycle_index - 1);
n = cycle_index;
begin = static_cast<double>(getTickCount());
while (n--) mat_dest = mat_src * mat_src1;
end = static_cast<double>(getTickCount());
time = (end - begin) / getTickFrequency() / cycle_index;
aclmat_dest.download(mat_dest1);
bool ret = test.Test_Diff(mat_dest, mat_dest1);
ASSERT_TRUE(ret);
if (val < 128)
cout << "Shape: " << val << " x " << val << "\t\t";
else
cout << "Shape: " << val << " x " << val << "\t";
cout << "CpuTimes: " << time << "\tAclTimes: " << acltime << "\tRate: " << time / acltime << endl;
}
n = (cycle_index - 1);
MatMul(aclmat_src1, aclmat_src, aclmat_dest, 0);
wait_stream(acl_context, 0);
begin = static_cast<double>(getTickCount());
while (n--) MatMul(aclmat_src1, aclmat_src, aclmat_dest, 1);
wait_stream(acl_context, 1);
end = static_cast<double>(getTickCount());
acltime = (end - begin) / getTickFrequency() / (cycle_index - 1);
aclmat_dest.download(mat_dest1);
bool ret = test.Test_Diff(mat_dest, mat_dest1);
ASSERT_TRUE(ret);
if (val < 128)
cout << "Shape: " << val << " x " << val << "\t\t";
else
cout << "Shape: " << val << " x " << val << "\t";
cout << "CpuTimes: " << time << "\tAclTimes: " << acltime
<< "\tRate: " << time / acltime << endl;
}
}
}
void PERF_TEST::Test_Convolution(aclCxt *acl_context)
{
int val, n;
int valmax = 4096;
int cycle_index = 10;
double begin, end, time, acltime;
Common_Test test;
vector<int> type{CV_32FC1};
void PERF_TEST::Test_Convolution(aclCxt *acl_context) {
int val, n;
int valmax = 4096;
int cycle_index = 10;
double begin, end, time, acltime;
Common_Test test;
vector<int> type{CV_32FC1};
for (size_t i = 0; i < type.size(); ++i)
{
for (val = 8; val <= valmax; val *= 2)
{
Mat mat_src(val, val, type[i], Scalar{1, 2});
Mat mat_kernel(3, 3, type[i], Scalar(1, 4));
Mat mat_dest(val, val, type[i], Scalar{6});
for (size_t i = 0; i < type.size(); ++i) {
for (val = 8; val <= valmax; val *= 2) {
Mat mat_src(val, val, type[i], Scalar{1, 2});
Mat mat_kernel(3, 3, type[i], Scalar(1, 4));
Mat mat_dest(val, val, type[i], Scalar{6});
aclMat aclmat_src(val, val, type[i], mat_src.data, acl_context);
aclMat aclmat_kernel(3, 3, type[i], mat_kernel.data, acl_context);
aclMat aclmat_dest(val, val, type[i], mat_dest.data, acl_context);
aclMat aclmat_src(val, val, type[i], mat_src.data, acl_context);
aclMat aclmat_kernel(3, 3, type[i], mat_kernel.data, acl_context);
aclMat aclmat_dest(val, val, type[i], mat_dest.data, acl_context);
n = cycle_index;
begin = static_cast<double>(getTickCount());
while (n--)
filter2D(mat_src, mat_dest, -1, mat_kernel);
end = static_cast<double>(getTickCount());
time = (end - begin) / getTickFrequency() / cycle_index;
n = cycle_index;
begin = static_cast<double>(getTickCount());
while (n--) filter2D(mat_src, mat_dest, -1, mat_kernel);
end = static_cast<double>(getTickCount());
time = (end - begin) / getTickFrequency() / cycle_index;
vector<int64_t> strides{1, 1, 1, 1};
vector<int64_t> pads{1, 1, 1, 1};
n = (cycle_index - 1);
Convolution(aclmat_src, aclmat_kernel, aclmat_dest, strides, pads, 0);
wait_stream(acl_context, 0);
begin = static_cast<double>(getTickCount());
while (n--)
Convolution(aclmat_src, aclmat_kernel, aclmat_dest, strides, pads, 1);
wait_stream(acl_context, 1);
end = static_cast<double>(getTickCount());
Mat mat_dest1(aclmat_dest.rows, aclmat_dest.cols, type[i]);
acltime = (end - begin) / getTickFrequency() / (cycle_index - 1);
vector<int64_t> strides{1, 1, 1, 1};
vector<int64_t> pads{1, 1, 1, 1};
n = (cycle_index - 1);
Convolution(aclmat_src, aclmat_kernel, aclmat_dest, strides, pads, 0);
wait_stream(acl_context, 0);
begin = static_cast<double>(getTickCount());
while (n--)
Convolution(aclmat_src, aclmat_kernel, aclmat_dest, strides, pads, 1);
wait_stream(acl_context, 1);
end = static_cast<double>(getTickCount());
Mat mat_dest1(aclmat_dest.rows, aclmat_dest.cols, type[i]);
acltime = (end - begin) / getTickFrequency() / (cycle_index - 1);
aclmat_dest.download(mat_dest1);
/*
bool ret = test.Test_Diff(mat_dest, mat_dest1);
ASSERT_TRUE(ret);
*/
if (val < 128)
cout << "Shape: " << val << " x " << val << "\t\t";
else
cout << "Shape: " << val << " x " << val << "\t";
cout << "CpuTimes: " << time << "\tAclTimes: " << acltime << "\tRate: " << time / acltime << endl;
}
aclmat_dest.download(mat_dest1);
/*
bool ret = test.Test_Diff(mat_dest, mat_dest1);
ASSERT_TRUE(ret);
*/
if (val < 128)
cout << "Shape: " << val << " x " << val << "\t\t";
else
cout << "Shape: " << val << " x " << val << "\t";
cout << "CpuTimes: " << time << "\tAclTimes: " << acltime
<< "\tRate: " << time / acltime << endl;
}
}
}

View File

@@ -1,10 +1,10 @@
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
// It is subject to the license terms in the LICENSE file found in the top-level
// directory of this distribution and at http://opencv.org/license.html.
#include "test_precomp.hpp"
#if defined(HAVE_HPX)
#include <hpx/hpx_main.hpp>
#include <hpx/hpx_main.hpp>
#endif
CV_TEST_MAIN("cv")

View File

@@ -1,481 +1,446 @@
#include "test_common.hpp"
#include "test_perf.hpp"
void PERF_TEST::Test_Abs(aclCxt *acl_context)
{
int val, n;
int valmax = 8192;
int cycle_index = 10;
double begin, end, time, acltime;
Common_Test test;
using namespace cv;
using namespace cv::acl;
using namespace cvtest;
using namespace testing;
using namespace std;
//vector<int> type{CV_32FC1};
vector<int> type{CV_32FC1,CV_32SC1};
for (size_t i = 0; i < type.size(); ++i)
{
test.PrintLog("Perf test : Function: Abs()", type[i]);
for (val = 8; val <= valmax; val *= 2)
{
n = cycle_index;
Mat mat_src(val, val, type[i], Scalar{-2});
Mat mat_dest(val, val, type[i], Scalar{-4});
Mat mat_dest1(val, val, type[i], Scalar{-6});
void PERF_TEST::Test_Abs(aclCxt *acl_context) {
int val, n;
int valmax = 8192;
int cycle_index = 10;
double begin, end, time, acltime;
Common_Test test;
aclMat aclmat_src(val, val, type[i], mat_src.data, acl_context);
aclMat aclmat_dest(val, val, type[i], mat_dest.data, acl_context);
// vector<int> type{CV_32FC1};
vector<int> type{CV_32FC1, CV_32SC1};
for (size_t i = 0; i < type.size(); ++i) {
test.PrintLog("Perf test : Function: Abs()", type[i]);
for (val = 8; val <= valmax; val *= 2) {
n = cycle_index;
Mat mat_src(val, val, type[i], Scalar{-2});
Mat mat_dest(val, val, type[i], Scalar{-4});
Mat mat_dest1(val, val, type[i], Scalar{-6});
begin = static_cast<double>(getTickCount());
while (n--)
mat_dest = abs(mat_src);
end = static_cast<double>(getTickCount());
time = (end - begin) / getTickFrequency() / cycle_index;
aclMat aclmat_src(val, val, type[i], mat_src.data, acl_context);
aclMat aclmat_dest(val, val, type[i], mat_dest.data, acl_context);
n = (cycle_index - 1);
aclmat_dest = abs(aclmat_src, 0);
wait_stream(acl_context, 0);
begin = static_cast<double>(getTickCount());
while (n--)
aclmat_dest = abs(aclmat_src, 1);
wait_stream(acl_context, 1);
end = static_cast<double>(getTickCount());
acltime = (end - begin) / getTickFrequency() / (cycle_index - 1);
begin = static_cast<double>(getTickCount());
while (n--) mat_dest = abs(mat_src);
end = static_cast<double>(getTickCount());
time = (end - begin) / getTickFrequency() / cycle_index;
aclmat_dest.download(mat_dest1);
bool ret = test.Test_Diff(mat_dest, mat_dest1);
ASSERT_TRUE(ret);
if (val < 128)
cout << "Shape: " << val << " x " << val << "\t\t";
else
cout << "Shape: " << val << " x " << val << "\t";
cout << "CpuTimes: " << time << "\tAclTimes: " << acltime << "\tRate: " << time / acltime << endl;
}
n = (cycle_index - 1);
aclmat_dest = abs(aclmat_src, 0);
wait_stream(acl_context, 0);
begin = static_cast<double>(getTickCount());
while (n--) aclmat_dest = abs(aclmat_src, 1);
wait_stream(acl_context, 1);
end = static_cast<double>(getTickCount());
acltime = (end - begin) / getTickFrequency() / (cycle_index - 1);
aclmat_dest.download(mat_dest1);
bool ret = test.Test_Diff(mat_dest, mat_dest1);
ASSERT_TRUE(ret);
if (val < 128)
cout << "Shape: " << val << " x " << val << "\t\t";
else
cout << "Shape: " << val << " x " << val << "\t";
cout << "CpuTimes: " << time << "\tAclTimes: " << acltime
<< "\tRate: " << time / acltime << endl;
}
}
}
void PERF_TEST::Test_Pow(aclCxt *acl_context)
{
int val, n;
int valmax = 8192;
int cycle_index = 10;
double begin, end, time, acltime;
Common_Test test;
void PERF_TEST::Test_Pow(aclCxt *acl_context) {
int val, n;
int valmax = 8192;
int cycle_index = 10;
double begin, end, time, acltime;
Common_Test test;
//vector<int> type{CV_32FC1};
vector<int> type{CV_8UC1, CV_32FC1,CV_32SC1};
for (size_t i = 0; i < type.size(); ++i)
{
test.PrintLog("Perf test : Function: Pow()", type[i]);
for (val = 8; val <= valmax; val *= 2)
{
n = cycle_index;
int power = test.RandDom_(6);
Mat mat_src(val, val, type[i]);
Mat mat_dest(val, val, type[i]);
Mat mat_dest1(val, val, type[i]);
// vector<int> type{CV_32FC1};
vector<int> type{CV_8UC1, CV_32FC1, CV_32SC1};
for (size_t i = 0; i < type.size(); ++i) {
test.PrintLog("Perf test : Function: Pow()", type[i]);
for (val = 8; val <= valmax; val *= 2) {
n = cycle_index;
int power = test.RandDom_(6);
Mat mat_src(val, val, type[i]);
Mat mat_dest(val, val, type[i]);
Mat mat_dest1(val, val, type[i]);
test.SetDataRange(mat_src, 32);
test.SetDataRange(mat_src, 32);
aclMat aclmat_src(val, val, type[i], mat_src.data, acl_context);
aclMat aclmat_dest(val, val, type[i], mat_dest.data, acl_context);
aclMat aclmat_src(val, val, type[i], mat_src.data, acl_context);
aclMat aclmat_dest(val, val, type[i], mat_dest.data, acl_context);
begin = static_cast<double>(getTickCount());
while (n--)
pow(mat_src, power, mat_dest);
end = static_cast<double>(getTickCount());
time = (end - begin) / getTickFrequency() / cycle_index;
begin = static_cast<double>(getTickCount());
while (n--) pow(mat_src, power, mat_dest);
end = static_cast<double>(getTickCount());
time = (end - begin) / getTickFrequency() / cycle_index;
n = (cycle_index - 1);
pow(aclmat_src, power, aclmat_dest, 0);
wait_stream(acl_context, 0);
begin = static_cast<double>(getTickCount());
while (n--)
pow(aclmat_src, power, aclmat_dest, 1);
wait_stream(acl_context, 1);
end = static_cast<double>(getTickCount());
acltime = (end - begin) / getTickFrequency() / (cycle_index - 1);
n = (cycle_index - 1);
pow(aclmat_src, power, aclmat_dest, 0);
wait_stream(acl_context, 0);
begin = static_cast<double>(getTickCount());
while (n--) pow(aclmat_src, power, aclmat_dest, 1);
wait_stream(acl_context, 1);
end = static_cast<double>(getTickCount());
acltime = (end - begin) / getTickFrequency() / (cycle_index - 1);
aclmat_dest.download(mat_dest1);
if (val < 128)
cout << "Shape: " << val << " x " << val << "\t\t";
else
cout << "Shape: " << val << " x " << val << "\t";
cout << "CpuTimes: " << time << "\tAclTimes: " << acltime << "\tRate: " << time / acltime << endl;
}
aclmat_dest.download(mat_dest1);
if (val < 128)
cout << "Shape: " << val << " x " << val << "\t\t";
else
cout << "Shape: " << val << " x " << val << "\t";
cout << "CpuTimes: " << time << "\tAclTimes: " << acltime
<< "\tRate: " << time / acltime << endl;
}
}
}
void PERF_TEST::Test_Sqrt(aclCxt *acl_context)
{
int val, n;
int valmax = 8192;
int cycle_index = 10;
double begin, end, time, acltime;
Common_Test test;
//vector<int> type{CV_32FC1};
vector<int> type{CV_32FC1,CV_64FC1};
for (size_t i = 0; i < type.size(); ++i)
{
for (val = 8; val <= valmax; val *= 2)
{
n = cycle_index;
Mat mat_src(val, val, type[i]);
Mat mat_dest(val, val, type[i]);
Mat mat_dest1(val, val, type[i]);
void PERF_TEST::Test_Sqrt(aclCxt *acl_context) {
int val, n;
int valmax = 8192;
int cycle_index = 10;
double begin, end, time, acltime;
Common_Test test;
// vector<int> type{CV_32FC1};
vector<int> type{CV_32FC1, CV_64FC1};
for (size_t i = 0; i < type.size(); ++i) {
for (val = 8; val <= valmax; val *= 2) {
n = cycle_index;
Mat mat_src(val, val, type[i]);
Mat mat_dest(val, val, type[i]);
Mat mat_dest1(val, val, type[i]);
test.SetDataRange(mat_src, 32);
test.SetDataRange(mat_dest, 32);
test.SetDataRange(mat_src, 32);
test.SetDataRange(mat_dest, 32);
aclMat aclmat_src(val, val, type[i], mat_src.data, acl_context);
aclMat aclmat_dest(val, val, type[i], mat_dest.data, acl_context);
aclMat aclmat_src(val, val, type[i], mat_src.data, acl_context);
aclMat aclmat_dest(val, val, type[i], mat_dest.data, acl_context);
begin = static_cast<double>(getTickCount());
while (n--)
sqrt(mat_src, mat_dest);
end = static_cast<double>(getTickCount());
time = (end - begin) / getTickFrequency() / cycle_index;
begin = static_cast<double>(getTickCount());
while (n--) sqrt(mat_src, mat_dest);
end = static_cast<double>(getTickCount());
time = (end - begin) / getTickFrequency() / cycle_index;
n = (cycle_index - 1);
sqrt(aclmat_src, aclmat_dest);
wait_stream(acl_context);
begin = static_cast<double>(getTickCount());
while (n--)
sqrt(aclmat_src, aclmat_dest, 1);
wait_stream(acl_context, 1);
end = static_cast<double>(getTickCount());
acltime = (end - begin) / getTickFrequency() / (cycle_index - 1);
n = (cycle_index - 1);
sqrt(aclmat_src, aclmat_dest);
wait_stream(acl_context);
begin = static_cast<double>(getTickCount());
while (n--) sqrt(aclmat_src, aclmat_dest, 1);
wait_stream(acl_context, 1);
end = static_cast<double>(getTickCount());
acltime = (end - begin) / getTickFrequency() / (cycle_index - 1);
aclmat_dest.download(mat_dest1);
if (val < 128)
cout << "Shape: " << val << " x " << val << "\t\t";
else
cout << "Shape: " << val << " x " << val << "\t";
cout << "CpuTimes: " << time << "\tAclTimes: " << acltime << "\tRate: " << time / acltime << endl;
}
aclmat_dest.download(mat_dest1);
if (val < 128)
cout << "Shape: " << val << " x " << val << "\t\t";
else
cout << "Shape: " << val << " x " << val << "\t";
cout << "CpuTimes: " << time << "\tAclTimes: " << acltime
<< "\tRate: " << time / acltime << endl;
}
}
}
void PERF_TEST::Test_Add(aclCxt *acl_context)
{
int val, n;
int valmax = 8192;
int cycle_index = 10;
double begin, end, time, acltime;
Common_Test test;
//vector<int> type{CV_32FC1};
vector<int> type{CV_8UC1,CV_32FC1, CV_32SC1, CV_64FC1};
for (size_t i = 0; i < type.size(); ++i)
{
for (val = 8; val <= valmax; val *= 2)
{
n = cycle_index;
Mat mat_src1(val, val, type[i]);
Mat mat_src2(val, val, type[i]);
Mat mat_dest(val, val, type[i]);
Mat mat_dest1(val, val, type[i]);
void PERF_TEST::Test_Add(aclCxt *acl_context) {
int val, n;
int valmax = 8192;
int cycle_index = 10;
double begin, end, time, acltime;
Common_Test test;
// vector<int> type{CV_32FC1};
vector<int> type{CV_8UC1, CV_32FC1, CV_32SC1, CV_64FC1};
for (size_t i = 0; i < type.size(); ++i) {
for (val = 8; val <= valmax; val *= 2) {
n = cycle_index;
Mat mat_src1(val, val, type[i]);
Mat mat_src2(val, val, type[i]);
Mat mat_dest(val, val, type[i]);
Mat mat_dest1(val, val, type[i]);
test.SetDataRange(mat_src1, 32);
test.SetDataRange(mat_src2, 32);
test.SetDataRange(mat_dest, 32);
test.SetDataRange(mat_src1, 32);
test.SetDataRange(mat_src2, 32);
test.SetDataRange(mat_dest, 32);
aclMat aclmat_src1(val, val, type[i], mat_src1.data, acl_context);
aclMat aclmat_src2(val, val, type[i], mat_src2.data, acl_context);
aclMat aclmat_dest(val, val, type[i], mat_dest.data, acl_context);
aclMat aclmat_src1(val, val, type[i], mat_src1.data, acl_context);
aclMat aclmat_src2(val, val, type[i], mat_src2.data, acl_context);
aclMat aclmat_dest(val, val, type[i], mat_dest.data, acl_context);
begin = static_cast<double>(getTickCount());
while (n--)
add(mat_src1, mat_src2, mat_dest);
end = static_cast<double>(getTickCount());
time = (end - begin) / getTickFrequency() / cycle_index;
begin = static_cast<double>(getTickCount());
while (n--) add(mat_src1, mat_src2, mat_dest);
end = static_cast<double>(getTickCount());
time = (end - begin) / getTickFrequency() / cycle_index;
n = (cycle_index - 1);
add(aclmat_src1, aclmat_src2, aclmat_dest);
wait_stream(acl_context);
begin = static_cast<double>(getTickCount());
while (n--)
add(aclmat_src1, aclmat_src2, aclmat_dest, 1);
wait_stream(acl_context, 1);
end = static_cast<double>(getTickCount());
acltime = (end - begin) / getTickFrequency() / (cycle_index - 1);
n = (cycle_index - 1);
add(aclmat_src1, aclmat_src2, aclmat_dest);
wait_stream(acl_context);
begin = static_cast<double>(getTickCount());
while (n--) add(aclmat_src1, aclmat_src2, aclmat_dest, 1);
wait_stream(acl_context, 1);
end = static_cast<double>(getTickCount());
acltime = (end - begin) / getTickFrequency() / (cycle_index - 1);
aclmat_dest.download(mat_dest1);
bool ret = test.Test_Diff(mat_dest, mat_dest1);
ASSERT_TRUE(ret);
if (val < 128)
cout << "Shape: " << val << " x " << val << "\t\t";
else
cout << "Shape: " << val << " x " << val << "\t";
cout << "CpuTimes: " << time << "\tAclTimes: " << acltime << "\tRate: " << time / acltime << endl;
}
aclmat_dest.download(mat_dest1);
bool ret = test.Test_Diff(mat_dest, mat_dest1);
ASSERT_TRUE(ret);
if (val < 128)
cout << "Shape: " << val << " x " << val << "\t\t";
else
cout << "Shape: " << val << " x " << val << "\t";
cout << "CpuTimes: " << time << "\tAclTimes: " << acltime
<< "\tRate: " << time / acltime << endl;
}
}
}
void PERF_TEST::Test_Divide(aclCxt *acl_context)
{
int val, n;
int valmax = 8192;
int cycle_index = 10;
double begin, end, time, acltime;
Common_Test test;
//vector<int> type{CV_32FC1};
vector<int> type{CV_8UC1,CV_32FC1, CV_32SC1};
for (size_t i = 0; i < type.size(); ++i)
{
for (val = 8; val <= valmax; val *= 2)
{
n = cycle_index;
Mat mat_src1(val, val, type[i]);
Mat mat_src2(val, val, type[i]);
Mat mat_dest(val, val, type[i]);
Mat mat_dest1(val, val, type[i]);
void PERF_TEST::Test_Divide(aclCxt *acl_context) {
int val, n;
int valmax = 8192;
int cycle_index = 10;
double begin, end, time, acltime;
Common_Test test;
// vector<int> type{CV_32FC1};
vector<int> type{CV_8UC1, CV_32FC1, CV_32SC1};
for (size_t i = 0; i < type.size(); ++i) {
for (val = 8; val <= valmax; val *= 2) {
n = cycle_index;
Mat mat_src1(val, val, type[i]);
Mat mat_src2(val, val, type[i]);
Mat mat_dest(val, val, type[i]);
Mat mat_dest1(val, val, type[i]);
test.SetDataRange(mat_src1, 32);
test.SetDataRange(mat_src2, 4);
test.SetDataRange(mat_dest, 32);
test.SetDataRange(mat_src1, 32);
test.SetDataRange(mat_src2, 4);
test.SetDataRange(mat_dest, 32);
aclMat aclmat_src1(val, val, type[i], mat_src1.data, acl_context);
aclMat aclmat_src2(val, val, type[i], mat_src2.data, acl_context);
aclMat aclmat_dest(val, val, type[i], mat_dest.data, acl_context);
aclMat aclmat_src1(val, val, type[i], mat_src1.data, acl_context);
aclMat aclmat_src2(val, val, type[i], mat_src2.data, acl_context);
aclMat aclmat_dest(val, val, type[i], mat_dest.data, acl_context);
begin = static_cast<double>(getTickCount());
while (n--)
divide(mat_src1, mat_src2, mat_dest);
end = static_cast<double>(getTickCount());
time = (end - begin) / getTickFrequency() / cycle_index;
begin = static_cast<double>(getTickCount());
while (n--) divide(mat_src1, mat_src2, mat_dest);
end = static_cast<double>(getTickCount());
time = (end - begin) / getTickFrequency() / cycle_index;
n = (cycle_index - 1);
divide(aclmat_src1, aclmat_src2, aclmat_dest);
wait_stream(acl_context);
begin = static_cast<double>(getTickCount());
while (n--)
divide(aclmat_src1, aclmat_src2, aclmat_dest, 1);
wait_stream(acl_context, 1);
end = static_cast<double>(getTickCount());
acltime = (end - begin) / getTickFrequency() / (cycle_index - 1);
n = (cycle_index - 1);
divide(aclmat_src1, aclmat_src2, aclmat_dest);
wait_stream(acl_context);
begin = static_cast<double>(getTickCount());
while (n--) divide(aclmat_src1, aclmat_src2, aclmat_dest, 1);
wait_stream(acl_context, 1);
end = static_cast<double>(getTickCount());
acltime = (end - begin) / getTickFrequency() / (cycle_index - 1);
aclmat_dest.download(mat_dest1);
// bool ret = test.Test_Diff(mat_dest, mat_dest1);
// ASSERT_TRUE(ret);
if (val < 128)
cout << "Shape: " << val << " x " << val << "\t\t";
else
cout << "Shape: " << val << " x " << val << "\t";
cout << "CpuTimes: " << time << "\tAclTimes: " << acltime << "\tRate: " << time / acltime << endl;
}
aclmat_dest.download(mat_dest1);
// bool ret = test.Test_Diff(mat_dest, mat_dest1);
// ASSERT_TRUE(ret);
if (val < 128)
cout << "Shape: " << val << " x " << val << "\t\t";
else
cout << "Shape: " << val << " x " << val << "\t";
cout << "CpuTimes: " << time << "\tAclTimes: " << acltime
<< "\tRate: " << time / acltime << endl;
}
}
}
void PERF_TEST::Test_Exp(aclCxt *acl_context)
{
int val, n;
int valmax = 8192;
int cycle_index = 10;
double begin, end, time, acltime;
Common_Test test;
//vector<int> type{CV_32FC1};
vector<int> type{CV_32FC1,CV_64FC1};
for (size_t i = 0; i < type.size(); ++i)
{
for (val = 8; val <= valmax; val *= 2)
{
n = cycle_index;
Mat mat_src(val, val, type[i]);
Mat mat_dest(val, val, type[i]);
Mat mat_dest1(val, val, type[i]);
void PERF_TEST::Test_Exp(aclCxt *acl_context) {
int val, n;
int valmax = 8192;
int cycle_index = 10;
double begin, end, time, acltime;
Common_Test test;
test.SetDataRange(mat_src, 32);
test.SetDataRange(mat_dest, 2);
// vector<int> type{CV_32FC1};
vector<int> type{CV_32FC1, CV_64FC1};
for (size_t i = 0; i < type.size(); ++i) {
for (val = 8; val <= valmax; val *= 2) {
n = cycle_index;
Mat mat_src(val, val, type[i]);
Mat mat_dest(val, val, type[i]);
Mat mat_dest1(val, val, type[i]);
aclMat aclmat_src(val, val, type[i], mat_src.data, acl_context);
aclMat aclmat_dest(val, val, type[i], mat_dest.data, acl_context);
test.SetDataRange(mat_src, 32);
test.SetDataRange(mat_dest, 2);
begin = static_cast<double>(getTickCount());
while (n--)
exp(mat_src, mat_dest);
end = static_cast<double>(getTickCount());
time = (end - begin) / getTickFrequency() / cycle_index;
aclMat aclmat_src(val, val, type[i], mat_src.data, acl_context);
aclMat aclmat_dest(val, val, type[i], mat_dest.data, acl_context);
n = (cycle_index - 1);
exp(aclmat_src, aclmat_dest);
wait_stream(acl_context);
begin = static_cast<double>(getTickCount());
while (n--)
exp(aclmat_src, aclmat_dest, 1);
wait_stream(acl_context, 1);
end = static_cast<double>(getTickCount());
acltime = (end - begin) / getTickFrequency() / (cycle_index - 1);
begin = static_cast<double>(getTickCount());
while (n--) exp(mat_src, mat_dest);
end = static_cast<double>(getTickCount());
time = (end - begin) / getTickFrequency() / cycle_index;
aclmat_dest.download(mat_dest1);
if (val < 128)
cout << "Shape: " << val << " x " << val << "\t\t";
else
cout << "Shape: " << val << " x " << val << "\t";
cout << "CpuTimes: " << time << "\tAclTimes: " << acltime << "\tRate: " << time / acltime << endl;
}
n = (cycle_index - 1);
exp(aclmat_src, aclmat_dest);
wait_stream(acl_context);
begin = static_cast<double>(getTickCount());
while (n--) exp(aclmat_src, aclmat_dest, 1);
wait_stream(acl_context, 1);
end = static_cast<double>(getTickCount());
acltime = (end - begin) / getTickFrequency() / (cycle_index - 1);
aclmat_dest.download(mat_dest1);
if (val < 128)
cout << "Shape: " << val << " x " << val << "\t\t";
else
cout << "Shape: " << val << " x " << val << "\t";
cout << "CpuTimes: " << time << "\tAclTimes: " << acltime
<< "\tRate: " << time / acltime << endl;
}
}
}
void PERF_TEST::Test_Log(aclCxt *acl_context)
{
int val, n;
int valmax = 8192;
int cycle_index = 10;
double begin, end, time, acltime;
Common_Test test;
//vector<int> type{CV_32FC1};
vector<int> type{CV_32FC1,CV_64FC1};
for (size_t i = 0; i < type.size(); ++i)
{
for (val = 8; val <= valmax; val *= 2)
{
n = cycle_index;
Mat mat_src(val, val, type[i]);
Mat mat_dest(val, val, type[i]);
Mat mat_dest1(val, val, type[i]);
void PERF_TEST::Test_Log(aclCxt *acl_context) {
int val, n;
int valmax = 8192;
int cycle_index = 10;
double begin, end, time, acltime;
Common_Test test;
// vector<int> type{CV_32FC1};
vector<int> type{CV_32FC1, CV_64FC1};
for (size_t i = 0; i < type.size(); ++i) {
for (val = 8; val <= valmax; val *= 2) {
n = cycle_index;
Mat mat_src(val, val, type[i]);
Mat mat_dest(val, val, type[i]);
Mat mat_dest1(val, val, type[i]);
test.SetDataRange(mat_src, 32);
test.SetDataRange(mat_dest, 32);
test.SetDataRange(mat_src, 32);
test.SetDataRange(mat_dest, 32);
aclMat aclmat_src(val, val, type[i], mat_src.data, acl_context);
aclMat aclmat_dest(val, val, type[i], mat_dest.data, acl_context);
aclMat aclmat_src(val, val, type[i], mat_src.data, acl_context);
aclMat aclmat_dest(val, val, type[i], mat_dest.data, acl_context);
begin = static_cast<double>(getTickCount());
while (n--)
log(mat_src, mat_dest);
end = static_cast<double>(getTickCount());
time = (end - begin) / getTickFrequency() / cycle_index;
begin = static_cast<double>(getTickCount());
while (n--) log(mat_src, mat_dest);
end = static_cast<double>(getTickCount());
time = (end - begin) / getTickFrequency() / cycle_index;
n = (cycle_index - 1);
log(aclmat_src, aclmat_dest, 1);
wait_stream(acl_context);
begin = static_cast<double>(getTickCount());
while (n--)
log(aclmat_src, aclmat_dest, 1);
wait_stream(acl_context, 1);
end = static_cast<double>(getTickCount());
acltime = (end - begin) / getTickFrequency() / (cycle_index - 1);
n = (cycle_index - 1);
log(aclmat_src, aclmat_dest, 1);
wait_stream(acl_context);
begin = static_cast<double>(getTickCount());
while (n--) log(aclmat_src, aclmat_dest, 1);
wait_stream(acl_context, 1);
end = static_cast<double>(getTickCount());
acltime = (end - begin) / getTickFrequency() / (cycle_index - 1);
aclmat_dest.download(mat_dest1);
if (val < 128)
cout << "Shape: " << val << " x " << val << "\t\t";
else
cout << "Shape: " << val << " x " << val << "\t";
cout << "CpuTimes: " << time << "\tAclTimes: " << acltime << "\tRate: " << time / acltime << endl;
}
aclmat_dest.download(mat_dest1);
if (val < 128)
cout << "Shape: " << val << " x " << val << "\t\t";
else
cout << "Shape: " << val << " x " << val << "\t";
cout << "CpuTimes: " << time << "\tAclTimes: " << acltime
<< "\tRate: " << time / acltime << endl;
}
}
}
void PERF_TEST::Test_Max(aclCxt *acl_context)
{
int val, n;
int valmax = 8192;
int cycle_index = 10;
double begin, end, time, acltime;
Common_Test test;
// vector<int> type{CV_32FC2};
vector<int> type{CV_32FC2,CV_32SC2, CV_64FC2};
for (size_t i = 0; i < type.size(); ++i)
{
for (val = 8; val <= valmax; val *= 2)
{
n = cycle_index;
Mat mat_src1(val, val, type[i]);
Mat mat_src2(val, val, type[i]);
Mat mat_dest(val, val, type[i]);
Mat mat_dest1(val, val, type[i]);
void PERF_TEST::Test_Max(aclCxt *acl_context) {
int val, n;
int valmax = 8192;
int cycle_index = 10;
double begin, end, time, acltime;
Common_Test test;
// vector<int> type{CV_32FC2};
vector<int> type{CV_32FC2, CV_32SC2, CV_64FC2};
for (size_t i = 0; i < type.size(); ++i) {
for (val = 8; val <= valmax; val *= 2) {
n = cycle_index;
Mat mat_src1(val, val, type[i]);
Mat mat_src2(val, val, type[i]);
Mat mat_dest(val, val, type[i]);
Mat mat_dest1(val, val, type[i]);
test.SetDataRange(mat_src1, 32);
test.SetDataRange(mat_src2, 32);
test.SetDataRange(mat_dest, 32);
test.SetDataRange(mat_src1, 32);
test.SetDataRange(mat_src2, 32);
test.SetDataRange(mat_dest, 32);
aclMat aclmat_src1(val, val, type[i], mat_src2.data, acl_context);
aclMat aclmat_src2(val, val, type[i], mat_src1.data, acl_context);
aclMat aclmat_dest(val, val, type[i], mat_dest.data, acl_context);
aclMat aclmat_src1(val, val, type[i], mat_src2.data, acl_context);
aclMat aclmat_src2(val, val, type[i], mat_src1.data, acl_context);
aclMat aclmat_dest(val, val, type[i], mat_dest.data, acl_context);
begin = static_cast<double>(getTickCount());
while (n--)
cv::max(mat_src1, mat_src2, mat_dest);
end = static_cast<double>(getTickCount());
time = (end - begin) / getTickFrequency() / cycle_index;
begin = static_cast<double>(getTickCount());
while (n--) cv::max(mat_src1, mat_src2, mat_dest);
end = static_cast<double>(getTickCount());
time = (end - begin) / getTickFrequency() / cycle_index;
n = (cycle_index - 1);
cv::acl::max(aclmat_src1, aclmat_src2, aclmat_dest);
wait_stream(acl_context);
begin = static_cast<double>(getTickCount());
while (n--)
cv::acl::max(aclmat_src1, aclmat_src2, aclmat_dest, 1);
wait_stream(acl_context, 1);
end = static_cast<double>(getTickCount());
acltime = (end - begin) / getTickFrequency() / (cycle_index - 1);
n = (cycle_index - 1);
cv::acl::max(aclmat_src1, aclmat_src2, aclmat_dest);
wait_stream(acl_context);
begin = static_cast<double>(getTickCount());
while (n--) cv::acl::max(aclmat_src1, aclmat_src2, aclmat_dest, 1);
wait_stream(acl_context, 1);
end = static_cast<double>(getTickCount());
acltime = (end - begin) / getTickFrequency() / (cycle_index - 1);
aclmat_dest.download(mat_dest1);
bool ret = test.Test_Diff(mat_dest, mat_dest1);
ASSERT_TRUE(ret);
if (val < 128)
cout << "Shape: " << val << " x " << val << "\t\t";
else
cout << "Shape: " << val << " x " << val << "\t";
cout << "CpuTimes: " << time << "\tAclTimes: " << acltime << "\tRate: " << time / acltime << endl;
}
aclmat_dest.download(mat_dest1);
bool ret = test.Test_Diff(mat_dest, mat_dest1);
ASSERT_TRUE(ret);
if (val < 128)
cout << "Shape: " << val << " x " << val << "\t\t";
else
cout << "Shape: " << val << " x " << val << "\t";
cout << "CpuTimes: " << time << "\tAclTimes: " << acltime
<< "\tRate: " << time / acltime << endl;
}
}
}
void PERF_TEST::Test_Min(aclCxt *acl_context)
{
int val, n;
int valmax = 8192;
int cycle_index = 10;
double begin, end, time, acltime;
Common_Test test;
//vector<int> type{CV_32FC3};
vector<int> type{CV_32FC3,CV_32SC3, CV_64FC3};
for (size_t i = 0; i < type.size(); ++i)
{
for (val = 8; val <= valmax; val *= 2)
{
n = cycle_index;
Mat mat_src1(val, val, type[i]);
Mat mat_src2(val, val, type[i]);
Mat mat_dest(val, val, type[i]);
Mat mat_dest1(val, val, type[i]);
void PERF_TEST::Test_Min(aclCxt *acl_context) {
int val, n;
int valmax = 8192;
int cycle_index = 10;
double begin, end, time, acltime;
Common_Test test;
// vector<int> type{CV_32FC3};
vector<int> type{CV_32FC3, CV_32SC3, CV_64FC3};
for (size_t i = 0; i < type.size(); ++i) {
for (val = 8; val <= valmax; val *= 2) {
n = cycle_index;
Mat mat_src1(val, val, type[i]);
Mat mat_src2(val, val, type[i]);
Mat mat_dest(val, val, type[i]);
Mat mat_dest1(val, val, type[i]);
test.SetDataRange(mat_src1, 32);
test.SetDataRange(mat_src2, 32);
test.SetDataRange(mat_dest, 32);
test.SetDataRange(mat_src1, 32);
test.SetDataRange(mat_src2, 32);
test.SetDataRange(mat_dest, 32);
aclMat aclmat_src1(val, val, type[i], mat_src2.data, acl_context);
aclMat aclmat_src2(val, val, type[i], mat_src1.data, acl_context);
aclMat aclmat_dest(val, val, type[i], mat_dest.data, acl_context);
aclMat aclmat_src1(val, val, type[i], mat_src2.data, acl_context);
aclMat aclmat_src2(val, val, type[i], mat_src1.data, acl_context);
aclMat aclmat_dest(val, val, type[i], mat_dest.data, acl_context);
begin = static_cast<double>(getTickCount());
while (n--)
cv::min(mat_src1, mat_src2, mat_dest);
end = static_cast<double>(getTickCount());
time = (end - begin) / getTickFrequency() / cycle_index;
begin = static_cast<double>(getTickCount());
while (n--) cv::min(mat_src1, mat_src2, mat_dest);
end = static_cast<double>(getTickCount());
time = (end - begin) / getTickFrequency() / cycle_index;
n = (cycle_index - 1);
cv::acl::min(aclmat_src1, aclmat_src2, aclmat_dest);
wait_stream(acl_context);
begin = static_cast<double>(getTickCount());
while (n--)
cv::acl::min(aclmat_src1, aclmat_src2, aclmat_dest, 1);
wait_stream(acl_context, 1);
end = static_cast<double>(getTickCount());
acltime = (end - begin) / getTickFrequency() / (cycle_index - 1);
n = (cycle_index - 1);
cv::acl::min(aclmat_src1, aclmat_src2, aclmat_dest);
wait_stream(acl_context);
begin = static_cast<double>(getTickCount());
while (n--) cv::acl::min(aclmat_src1, aclmat_src2, aclmat_dest, 1);
wait_stream(acl_context, 1);
end = static_cast<double>(getTickCount());
acltime = (end - begin) / getTickFrequency() / (cycle_index - 1);
aclmat_dest.download(mat_dest1);
bool ret = test.Test_Diff(mat_dest, mat_dest1);
ASSERT_TRUE(ret);
if (val < 128)
cout << "Shape: " << val << " x " << val << "\t\t";
else
cout << "Shape: " << val << " x " << val << "\t";
cout << "CpuTimes: " << time << "\tAclTimes: " << acltime << "\tRate: " << time / acltime << endl;
}
aclmat_dest.download(mat_dest1);
bool ret = test.Test_Diff(mat_dest, mat_dest1);
ASSERT_TRUE(ret);
if (val < 128)
cout << "Shape: " << val << " x " << val << "\t\t";
else
cout << "Shape: " << val << " x " << val << "\t";
cout << "CpuTimes: " << time << "\tAclTimes: " << acltime
<< "\tRate: " << time / acltime << endl;
}
}
}

View File

@@ -1,278 +1,239 @@
#include "test_common.hpp"
#include "test_perf.hpp"
/*
//disable
void PERF_TEST::Test_Lookuptable(aclCxt *acl_context_0)
{
int type = CV_8UC1;
Common_Test test;
Mat mat_src(1, 256, type);
Mat mat_dest(1, 256, type);
Mat lookuptable(1, 256, type);
using namespace cv;
using namespace cv::acl;
using namespace cvtest;
using namespace testing;
using namespace std;
test.SetDataRange(mat_src, 32);
test.SetDataRange(lookuptable, 32);
void PERF_TEST::Test_Merge(aclCxt *acl_context) {
int val, n;
int valmax = 8192;
int cycle_index = 10;
double begin, end, time, acltime;
Common_Test test;
aclMat aclmat_src(1, 256, type, mat_src.data, acl_context_0);
aclMat aclmat_dest(1, 256, type, mat_dest.data, acl_context_0);
aclMat lut(1, 256, type, lookuptable.data, acl_context_0);
// LUT(mat_src, lookuptable, mat_dest);
lookUpTable(aclmat_src, lut, aclmat_dest);
cout << mat_src << endl;
cout << lookuptable << endl;
cout << mat_dest << endl;
}
*/
vector<int> srcType{CV_8UC1, CV_32FC1, CV_32SC1};
// vector<int> destType{CV_32FC3};
vector<int> destType{CV_8UC3, CV_32FC3, CV_32SC3};
for (size_t i = 0; i < srcType.size(); ++i) {
test.PrintLog("Perf test : Function: merge()", srcType[i]);
for (val = 8; val <= valmax; val *= 2) {
n = cycle_index;
Mat mat_src1(val, val, srcType[i], Scalar(1));
Mat mat_src2(val, val, srcType[i], Scalar(2));
Mat mat_src3(val, val, srcType[i], Scalar(3));
Mat mat_dest(val, val, destType[i]);
Mat mat_dest1(val, val, destType[i]);
void PERF_TEST::Test_Merge(aclCxt *acl_context)
{
int val, n;
int valmax = 8192;
int cycle_index = 10;
double begin, end, time, acltime;
Common_Test test;
test.SetDataRange(mat_src1, 32);
test.SetDataRange(mat_src2, 32);
test.SetDataRange(mat_src3, 32);
vector<int> srcType{CV_8UC1,CV_32FC1, CV_32SC1};
//vector<int> destType{CV_32FC3};
vector<int> destType{CV_8UC3,CV_32FC3, CV_32SC3};
for (size_t i = 0; i < srcType.size(); ++i)
{
test.PrintLog("Perf test : Function: merge()", srcType[i]);
for (val = 8; val <= valmax; val *= 2)
{
n = cycle_index;
Mat mat_src1(val, val, srcType[i], Scalar(1));
Mat mat_src2(val, val, srcType[i], Scalar(2));
Mat mat_src3(val, val, srcType[i], Scalar(3));
Mat mat_dest(val, val, destType[i]);
Mat mat_dest1(val, val, destType[i]);
aclMat aclmat_src1(val, val, srcType[i], mat_src1.data, acl_context);
aclMat aclmat_src2(val, val, srcType[i], mat_src2.data, acl_context);
aclMat aclmat_src3(val, val, srcType[i], mat_src3.data, acl_context);
aclMat aclmat_dest(val, val, destType[i], mat_dest.data, acl_context);
test.SetDataRange(mat_src1, 32);
test.SetDataRange(mat_src2, 32);
test.SetDataRange(mat_src3, 32);
vector<Mat> src;
src.emplace_back(mat_src1);
src.emplace_back(mat_src2);
src.emplace_back(mat_src3);
aclMat aclmat_src1(val, val, srcType[i], mat_src1.data, acl_context);
aclMat aclmat_src2(val, val, srcType[i], mat_src2.data, acl_context);
aclMat aclmat_src3(val, val, srcType[i], mat_src3.data, acl_context);
aclMat aclmat_dest(val, val, destType[i], mat_dest.data, acl_context);
vector<aclMat> acl_src;
acl_src.emplace_back(aclmat_src1);
acl_src.emplace_back(aclmat_src2);
acl_src.emplace_back(aclmat_src3);
vector<Mat> src;
src.emplace_back(mat_src1);
src.emplace_back(mat_src2);
src.emplace_back(mat_src3);
begin = static_cast<double>(getTickCount());
while (n--) merge(src, mat_dest);
end = static_cast<double>(getTickCount());
time = (end - begin) / getTickFrequency() / cycle_index;
vector<aclMat> acl_src;
acl_src.emplace_back(aclmat_src1);
acl_src.emplace_back(aclmat_src2);
acl_src.emplace_back(aclmat_src3);
begin = static_cast<double>(getTickCount());
while (n--)
merge(src, mat_dest);
end = static_cast<double>(getTickCount());
time = (end - begin) / getTickFrequency() / cycle_index;
n = (cycle_index - 1);
merge(acl_src, aclmat_dest);
wait_stream(acl_context);
begin = static_cast<double>(getTickCount());
while (n--)
merge(acl_src, aclmat_dest, 1);
wait_stream(acl_context, 1);
end = static_cast<double>(getTickCount());
acltime = (end - begin) / getTickFrequency() / (cycle_index - 1);
aclmat_dest.download(mat_dest1);
bool ret = test.Test_Diff(mat_dest, mat_dest1);
ASSERT_TRUE(ret);
if (val < 128)
cout << "Shape: " << val << " x " << val << "\t\t";
else
cout << "Shape: " << val << " x " << val << "\t";
cout << "CpuTimes: " << time << "\tAclTimes: " << acltime << "\tRate: " << time / acltime << endl;
}
n = (cycle_index - 1);
merge(acl_src, aclmat_dest);
wait_stream(acl_context);
begin = static_cast<double>(getTickCount());
while (n--) merge(acl_src, aclmat_dest, 1);
wait_stream(acl_context, 1);
end = static_cast<double>(getTickCount());
acltime = (end - begin) / getTickFrequency() / (cycle_index - 1);
aclmat_dest.download(mat_dest1);
bool ret = test.Test_Diff(mat_dest, mat_dest1);
ASSERT_TRUE(ret);
if (val < 128)
cout << "Shape: " << val << " x " << val << "\t\t";
else
cout << "Shape: " << val << " x " << val << "\t";
cout << "CpuTimes: " << time << "\tAclTimes: " << acltime
<< "\tRate: " << time / acltime << endl;
}
}
}
void PERF_TEST::Test_Transpose(aclCxt *acl_context) {
int val, n;
int valmax = 8192;
int cycle_index = 10;
double begin, end, time, acltime;
Common_Test test;
void PERF_TEST::Test_Transpose(aclCxt *acl_context)
{
int val, n;
int valmax = 8192;
int cycle_index = 10;
double begin, end, time, acltime;
Common_Test test;
// vector<int> type{CV_32FC1};
vector<int> type{CV_32FC1, CV_32SC1};
for (size_t i = 0; i < type.size(); ++i) {
test.PrintLog("Perf test : Function: transpose()", type[i]);
for (val = 8; val <= valmax; val *= 2) {
n = cycle_index;
Mat mat_src(val, val, type[i]);
Mat mat_dest(val, val, type[i]);
Mat mat_dest1(val, val, type[i]);
//vector<int> type{CV_32FC1};
vector<int> type{CV_32FC1,CV_32SC1};
for (size_t i = 0; i < type.size(); ++i)
{
test.PrintLog("Perf test : Function: transpose()", type[i]);
for (val = 8; val <= valmax; val *= 2)
{
n = cycle_index;
Mat mat_src(val, val, type[i]);
Mat mat_dest(val, val, type[i]);
Mat mat_dest1(val, val, type[i]);
test.SetDataRange(mat_src, 32);
test.SetDataRange(mat_src, 32);
aclMat aclmat_src(val, val, type[i], mat_src.data, acl_context);
aclMat aclmat_dest(val, val, type[i], mat_dest.data, acl_context);
aclMat aclmat_src(val, val, type[i], mat_src.data, acl_context);
aclMat aclmat_dest(val, val, type[i], mat_dest.data, acl_context);
begin = static_cast<double>(getTickCount());
while (n--) transpose(mat_src, mat_dest);
end = static_cast<double>(getTickCount());
time = (end - begin) / getTickFrequency() / cycle_index;
begin = static_cast<double>(getTickCount());
while (n--)
transpose(mat_src, mat_dest);
end = static_cast<double>(getTickCount());
time = (end - begin) / getTickFrequency() / cycle_index;
n = (cycle_index - 1);
transpose(aclmat_src, aclmat_dest);
wait_stream(acl_context);
begin = static_cast<double>(getTickCount());
while (n--) transpose(aclmat_src, aclmat_dest, 1);
wait_stream(acl_context, 1);
end = static_cast<double>(getTickCount());
acltime = (end - begin) / getTickFrequency() / (cycle_index - 1);
n = (cycle_index - 1);
transpose(aclmat_src, aclmat_dest);
wait_stream(acl_context);
begin = static_cast<double>(getTickCount());
while (n--)
transpose(aclmat_src, aclmat_dest, 1);
wait_stream(acl_context, 1);
end = static_cast<double>(getTickCount());
acltime = (end - begin) / getTickFrequency() / (cycle_index - 1);
aclmat_dest.download(mat_dest1);
bool ret = test.Test_Diff(mat_dest, mat_dest1);
ASSERT_TRUE(ret);
if (val < 128)
cout << "Shape: " << val << " x " << val << "\t\t";
else
cout << "Shape: " << val << " x " << val << "\t";
cout << "CpuTimes: " << time << "\tAclTimes: " << acltime << "\tRate: " << time / acltime << endl;
}
aclmat_dest.download(mat_dest1);
bool ret = test.Test_Diff(mat_dest, mat_dest1);
ASSERT_TRUE(ret);
if (val < 128)
cout << "Shape: " << val << " x " << val << "\t\t";
else
cout << "Shape: " << val << " x " << val << "\t";
cout << "CpuTimes: " << time << "\tAclTimes: " << acltime
<< "\tRate: " << time / acltime << endl;
}
}
}
void PERF_TEST::Test_Split(aclCxt *acl_context)
{
int val, n;
int valmax = 8192;
int cycle_index = 10;
double begin, end, time, acltime;
Common_Test test;
void PERF_TEST::Test_Split(aclCxt *acl_context) {
int val, n;
int valmax = 8192;
int cycle_index = 10;
double begin, end, time, acltime;
Common_Test test;
//vector<int> srcType{CV_32FC3};
vector<int> srcType{CV_8UC3,CV_32FC3, CV_32SC3};
vector<int> destType{CV_8UC1,CV_32FC1, CV_32SC1};
for (size_t i = 0; i < srcType.size(); ++i)
{
test.PrintLog("Perf test : Function: split()", srcType[i]);
for (val = 8; val <= valmax; val *= 2)
{
n = cycle_index;
Mat mat_src(val, val, srcType[i]);
Mat mat_dest1(val, val, destType[i]);
Mat mat_dest2(val, val, destType[i]);
Mat mat_dest3(val, val, destType[i]);
// vector<int> srcType{CV_32FC3};
vector<int> srcType{CV_8UC3, CV_32FC3, CV_32SC3};
vector<int> destType{CV_8UC1, CV_32FC1, CV_32SC1};
for (size_t i = 0; i < srcType.size(); ++i) {
test.PrintLog("Perf test : Function: split()", srcType[i]);
for (val = 8; val <= valmax; val *= 2) {
n = cycle_index;
Mat mat_src(val, val, srcType[i]);
Mat mat_dest1(val, val, destType[i]);
Mat mat_dest2(val, val, destType[i]);
Mat mat_dest3(val, val, destType[i]);
test.SetDataRange(mat_src, 32);
test.SetDataRange(mat_src, 32);
aclMat aclmat_src(val, val, srcType[i], mat_src.data, acl_context);
aclMat aclmat_dest1;
aclMat aclmat_dest2;
aclMat aclmat_dest3;
aclMat aclmat_src(val, val, srcType[i], mat_src.data, acl_context);
aclMat aclmat_dest1;
aclMat aclmat_dest2;
aclMat aclmat_dest3;
vector<Mat> dest;
dest.emplace_back(mat_dest1);
dest.emplace_back(mat_dest2);
dest.emplace_back(mat_dest3);
vector<Mat> dest;
dest.emplace_back(mat_dest1);
dest.emplace_back(mat_dest2);
dest.emplace_back(mat_dest3);
vector<aclMat> acl_dest;
acl_dest.emplace_back(aclmat_dest1);
acl_dest.emplace_back(aclmat_dest2);
acl_dest.emplace_back(aclmat_dest3);
vector<aclMat> acl_dest;
acl_dest.emplace_back(aclmat_dest1);
acl_dest.emplace_back(aclmat_dest2);
acl_dest.emplace_back(aclmat_dest3);
begin = static_cast<double>(getTickCount());
while (n--)
split(mat_src, dest);
end = static_cast<double>(getTickCount());
time = (end - begin) / getTickFrequency() / cycle_index;
begin = static_cast<double>(getTickCount());
while (n--) split(mat_src, dest);
end = static_cast<double>(getTickCount());
time = (end - begin) / getTickFrequency() / cycle_index;
n = (cycle_index - 1);
split(aclmat_src, acl_dest);
wait_stream(acl_context);
begin = static_cast<double>(getTickCount());
while (n--)
split(aclmat_src, acl_dest, 1);
wait_stream(acl_context, 1);
end = static_cast<double>(getTickCount());
acltime = (end - begin) / getTickFrequency() / (cycle_index - 1);
n = (cycle_index - 1);
split(aclmat_src, acl_dest);
wait_stream(acl_context);
begin = static_cast<double>(getTickCount());
while (n--) split(aclmat_src, acl_dest, 1);
wait_stream(acl_context, 1);
end = static_cast<double>(getTickCount());
acltime = (end - begin) / getTickFrequency() / (cycle_index - 1);
(acl_dest.data())[0].download(mat_dest1);
(acl_dest.data())[1].download(mat_dest2);
(acl_dest.data())[2].download(mat_dest3);
(acl_dest.data())[0].download(mat_dest1);
(acl_dest.data())[1].download(mat_dest2);
(acl_dest.data())[2].download(mat_dest3);
bool ret = test.Test_Diff((dest.data())[0], mat_dest1);
ret &= test.Test_Diff((dest.data())[1], mat_dest2);
ret &= test.Test_Diff((dest.data())[2], mat_dest3);
ASSERT_TRUE(ret);
if (val < 128)
cout << "Shape: " << val << " x " << val << "\t\t";
else
cout << "Shape: " << val << " x " << val << "\t";
cout << "CpuTimes: " << time << "\tAclTimes: " << acltime << "\tRate: " << time / acltime << endl;
}
bool ret = test.Test_Diff((dest.data())[0], mat_dest1);
ret &= test.Test_Diff((dest.data())[1], mat_dest2);
ret &= test.Test_Diff((dest.data())[2], mat_dest3);
ASSERT_TRUE(ret);
if (val < 128)
cout << "Shape: " << val << " x " << val << "\t\t";
else
cout << "Shape: " << val << " x " << val << "\t";
cout << "CpuTimes: " << time << "\tAclTimes: " << acltime
<< "\tRate: " << time / acltime << endl;
}
}
}
void PERF_TEST::Test_Flip(aclCxt *acl_context)
{
int val, n;
int valmax = 8192;
int cycle_index = 100;
double begin, end, time, acltime;
Common_Test test;
void PERF_TEST::Test_Flip(aclCxt *acl_context) {
int val, n;
int valmax = 8192;
int cycle_index = 100;
double begin, end, time, acltime;
Common_Test test;
vector<int> type{CV_8UC1, CV_32FC1, CV_32SC1, CV_64FC1};
for (size_t i = 0; i < type.size(); ++i)
{
test.PrintLog("Perf test : Function: flip()", type[i]);
for (val = 8; val <= valmax; val *= 2)
{
n = cycle_index;
Mat mat_src(val, val, type[i]);
Mat mat_dest(val, val, type[i]);
Mat mat_dest1(val, val, type[i]);
vector<int> type{CV_8UC1, CV_32FC1, CV_32SC1, CV_64FC1};
for (size_t i = 0; i < type.size(); ++i) {
test.PrintLog("Perf test : Function: flip()", type[i]);
for (val = 8; val <= valmax; val *= 2) {
n = cycle_index;
Mat mat_src(val, val, type[i]);
Mat mat_dest(val, val, type[i]);
Mat mat_dest1(val, val, type[i]);
test.SetDataRange(mat_src, 32);
test.SetDataRange(mat_src, 32);
aclMat aclmat_src(val, val, type[i], mat_src.data, acl_context);
aclMat aclmat_dest(val, val, type[i], mat_dest.data, acl_context);
aclMat aclmat_src(val, val, type[i], mat_src.data, acl_context);
aclMat aclmat_dest(val, val, type[i], mat_dest.data, acl_context);
begin = static_cast<double>(getTickCount());
while (n--)
flip(mat_src, mat_dest, 0);
end = static_cast<double>(getTickCount());
time = (end - begin) / getTickFrequency() / cycle_index;
begin = static_cast<double>(getTickCount());
while (n--) flip(mat_src, mat_dest, 0);
end = static_cast<double>(getTickCount());
time = (end - begin) / getTickFrequency() / cycle_index;
n = (cycle_index - 1);
flip(aclmat_src, aclmat_dest, 0);
wait_stream(acl_context);
begin = static_cast<double>(getTickCount());
while (n--)
flip(aclmat_src, aclmat_dest, 0, 1);
wait_stream(acl_context, 1);
end = static_cast<double>(getTickCount());
acltime = (end - begin) / getTickFrequency() / (cycle_index - 1);
aclmat_dest.download(mat_dest1);
bool ret = test.Test_Diff(mat_dest, mat_dest1);
ASSERT_TRUE(ret);
if (val < 128)
cout << "Shape: " << val << " x " << val << "\t\t";
else
cout << "Shape: " << val << " x " << val << "\t";
cout << "CpuTimes: " << time << "\tAclTimes: " << acltime << "\tRate: " << time / acltime << endl;
}
n = (cycle_index - 1);
flip(aclmat_src, aclmat_dest, 0);
wait_stream(acl_context);
begin = static_cast<double>(getTickCount());
while (n--) flip(aclmat_src, aclmat_dest, 0, 1);
wait_stream(acl_context, 1);
end = static_cast<double>(getTickCount());
acltime = (end - begin) / getTickFrequency() / (cycle_index - 1);
aclmat_dest.download(mat_dest1);
bool ret = test.Test_Diff(mat_dest, mat_dest1);
ASSERT_TRUE(ret);
if (val < 128)
cout << "Shape: " << val << " x " << val << "\t\t";
else
cout << "Shape: " << val << " x " << val << "\t";
cout << "CpuTimes: " << time << "\tAclTimes: " << acltime
<< "\tRate: " << time / acltime << endl;
}
}
}

View File

@@ -3,31 +3,30 @@
#include "test_precomp.hpp"
class PERF_TEST
{
public:
CV_EXPORTS void Test_operator_add_perf(aclCxt *acl_context);
CV_EXPORTS void Test_operator_sub_perf(aclCxt *acl_context);
CV_EXPORTS void Test_operator_div_perf(aclCxt *acl_context);
CV_EXPORTS void Test_operator_mul_perf(aclCxt *acl_context);
CV_EXPORTS void Test_Abs(aclCxt *acl_context);
CV_EXPORTS void Test_Pow(aclCxt *acl_context);
CV_EXPORTS void Test_Sqrt(aclCxt *acl_context);
CV_EXPORTS void Test_Add(aclCxt *acl_context);
CV_EXPORTS void Test_Divide(aclCxt *acl_context);
CV_EXPORTS void Test_Exp(aclCxt *acl_context);
CV_EXPORTS void Test_Log(aclCxt *acl_context);
CV_EXPORTS void Test_Max(aclCxt *acl_context);
CV_EXPORTS void Test_Min(aclCxt *acl_context);
class PERF_TEST {
public:
CV_EXPORTS void Test_operator_add_perf(cv::acl::aclCxt *acl_context);
CV_EXPORTS void Test_operator_sub_perf(cv::acl::aclCxt *acl_context);
CV_EXPORTS void Test_operator_div_perf(cv::acl::aclCxt *acl_context);
CV_EXPORTS void Test_operator_mul_perf(cv::acl::aclCxt *acl_context);
CV_EXPORTS void Test_Abs(cv::acl::aclCxt *acl_context);
CV_EXPORTS void Test_Pow(cv::acl::aclCxt *acl_context);
CV_EXPORTS void Test_Sqrt(cv::acl::aclCxt *acl_context);
CV_EXPORTS void Test_Add(cv::acl::aclCxt *acl_context);
CV_EXPORTS void Test_Divide(cv::acl::aclCxt *acl_context);
CV_EXPORTS void Test_Exp(cv::acl::aclCxt *acl_context);
CV_EXPORTS void Test_Log(cv::acl::aclCxt *acl_context);
CV_EXPORTS void Test_Max(cv::acl::aclCxt *acl_context);
CV_EXPORTS void Test_Min(cv::acl::aclCxt *acl_context);
CV_EXPORTS void Test_MatMul(aclCxt *acl_context);
CV_EXPORTS void Test_Convolution(aclCxt *acl_context);
CV_EXPORTS void Test_MatMul(cv::acl::aclCxt *acl_context);
CV_EXPORTS void Test_Convolution(cv::acl::aclCxt *acl_context);
CV_EXPORTS void Test_Lookuptable(aclCxt *acl_context);
CV_EXPORTS void Test_Merge(aclCxt *acl_context);
CV_EXPORTS void Test_Split(aclCxt *acl_context);
CV_EXPORTS void Test_Transpose(aclCxt *acl_context);
CV_EXPORTS void Test_Flip(aclCxt *acl_context);
CV_EXPORTS void Test_Lookuptable(cv::acl::aclCxt *acl_context);
CV_EXPORTS void Test_Merge(cv::acl::aclCxt *acl_context);
CV_EXPORTS void Test_Split(cv::acl::aclCxt *acl_context);
CV_EXPORTS void Test_Transpose(cv::acl::aclCxt *acl_context);
CV_EXPORTS void Test_Flip(cv::acl::aclCxt *acl_context);
};
#endif

View File

@@ -1,27 +1,21 @@
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
// It is subject to the license terms in the LICENSE file found in the top-level
// directory of this distribution and at http://opencv.org/license.html.
#ifndef __OPENCV_TEST_PRECOMP_HPP__
#define __OPENCV_TEST_PRECOMP_HPP__
#include <iomanip>
#include <iostream>
#include <mutex>
#include <thread>
#include <iomanip>
#include "opencv2/core.hpp"
#include "opencv2/ts.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/videoio.hpp"
#include "sys/time.h"
#include "opencv2/acl/acl.hpp"
#include "acl/acl.h"
#include "acl/acl_op_compiler.h"
using namespace cv;
using namespace cv::acl;
using namespace cvtest;
using namespace testing;
using namespace std;
#include "opencv2/acl/acl.hpp"
#include "opencv2/core.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/ts.hpp"
#include "opencv2/videoio.hpp"
#include "sys/time.h"
#endif