mirror of
https://github.com/Ascend/ascend-opencv.git
synced 2025-10-09 02:00:28 +08:00
update version
This commit is contained in:
@@ -2,7 +2,8 @@
|
||||
//
|
||||
// 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
|
||||
@@ -44,14 +52,14 @@
|
||||
#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
|
||||
|
@@ -4,19 +4,14 @@
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "opencv2/core.hpp"
|
||||
#include "acl_type.hpp"
|
||||
#include "opencv2/core.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace cv
|
||||
{
|
||||
namespace acl
|
||||
{
|
||||
namespace cv {
|
||||
namespace acl {
|
||||
CV_EXPORTS Mutex &getInitMutex();
|
||||
//////////////////////////////// aclEnv ////////////////////////////////
|
||||
class CV_EXPORTS aclEnv
|
||||
{
|
||||
class CV_EXPORTS aclEnv {
|
||||
public:
|
||||
aclEnv();
|
||||
aclEnv(const char *config_path);
|
||||
@@ -24,13 +19,13 @@ namespace cv
|
||||
int get_device_count();
|
||||
int *refcount;
|
||||
~aclEnv();
|
||||
|
||||
private:
|
||||
uint32_t _device_count;
|
||||
};
|
||||
|
||||
//////////////////////////////// aclCxt ////////////////////////////////
|
||||
class CV_EXPORTS aclCxt
|
||||
{
|
||||
class CV_EXPORTS aclCxt {
|
||||
public:
|
||||
aclCxt();
|
||||
aclCxt(int device_id);
|
||||
@@ -41,6 +36,7 @@ namespace cv
|
||||
void create_stream(int count = 1);
|
||||
aclStream get_stream(const size_t index = 0);
|
||||
~aclCxt();
|
||||
|
||||
private:
|
||||
int32_t _device_id;
|
||||
aclrtContext *_context;
|
||||
@@ -49,7 +45,8 @@ namespace cv
|
||||
|
||||
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 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 */
|
||||
|
@@ -2,34 +2,39 @@
|
||||
#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
|
||||
{
|
||||
namespace cv {
|
||||
namespace acl {
|
||||
//////////////////////////////// aclMat ////////////////////////////////
|
||||
class CV_EXPORTS 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);
|
||||
//! 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);
|
||||
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 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);
|
||||
aclMat(const Mat &m, aclCxt *acl_context, ALIGNMENT config = MEMORY_UNALIGNED,
|
||||
MemMallocPolicy policy = MALLOC_NORMAL_ONLY);
|
||||
//! destructor - calls release()
|
||||
~aclMat();
|
||||
|
||||
@@ -40,10 +45,12 @@ namespace cv
|
||||
|
||||
//! 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);
|
||||
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;
|
||||
void download(Mat &m, aclStream stream,
|
||||
ALIGNMENT config = MEMORY_UNALIGNED) const;
|
||||
|
||||
operator Mat() const;
|
||||
aclMat clone() const;
|
||||
@@ -65,14 +72,20 @@ namespace cv
|
||||
//! moves/resizes the current aclMatrix ROI inside the parent aclMatrix.
|
||||
aclMat &adjustROI(int dtop, int dbottom, int dleft, int dright);
|
||||
|
||||
//! allocates new aclMatrix data unless the aclMatrix already has specified size and type.
|
||||
//! 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);
|
||||
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);
|
||||
|
||||
//! 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);
|
||||
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);
|
||||
|
||||
//! decreases reference counter;
|
||||
// deallocate the data when reference counter reaches 0.
|
||||
@@ -91,7 +104,6 @@ namespace cv
|
||||
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)
|
||||
@@ -126,8 +138,10 @@ namespace cv
|
||||
bool empty() 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);
|
||||
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);
|
||||
|
||||
/*! includes several bit-fields:
|
||||
- the magic signature
|
||||
@@ -157,17 +171,16 @@ namespace cv
|
||||
|
||||
// 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
|
||||
// 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
|
@@ -2,7 +2,8 @@
|
||||
//
|
||||
// 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
|
||||
@@ -48,22 +56,22 @@
|
||||
#define AclVerifyCall(expr) __aclSafeCall(res, __FILE__, __LINE__, __func__)
|
||||
|
||||
#include <iostream>
|
||||
#include "opencv2/core.hpp"
|
||||
#include "acl/acl.h"
|
||||
|
||||
namespace cv
|
||||
{
|
||||
namespace acl
|
||||
{
|
||||
#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)
|
||||
{
|
||||
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 << "Acl Called Error: "
|
||||
<< "file " << file << ", func " << function << ", line " << line
|
||||
<< " errorCode: " << err << std::endl;
|
||||
std::cerr.flush();
|
||||
}
|
||||
}
|
||||
@@ -71,30 +79,27 @@ namespace cv
|
||||
/* 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_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 enum Opdims { TWO_DIMS = 1, FOUR_DIMS } Opdims;
|
||||
|
||||
enum DeviceType
|
||||
{
|
||||
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
|
||||
{
|
||||
typedef enum MemMallocPolicy {
|
||||
MALLOC_HUGE_FIRST = 1,
|
||||
MALLOC_HUGE_ONLY,
|
||||
MALLOC_NORMAL_ONLY,
|
||||
@@ -103,14 +108,11 @@ namespace cv
|
||||
MALLOC_NORMAL_ONLY_P2P
|
||||
} MemMallocPolicy;
|
||||
|
||||
|
||||
CV_EXPORTS aclDataType type_transition(int depth);
|
||||
CV_EXPORTS aclrtMemMallocPolicy type_transition(MemMallocPolicy type);
|
||||
|
||||
inline aclDataType type_transition(int depth)
|
||||
{
|
||||
switch (depth)
|
||||
{
|
||||
inline aclDataType type_transition(int depth) {
|
||||
switch (depth) {
|
||||
case CV_8U:
|
||||
return ACL_UINT8;
|
||||
case CV_8S:
|
||||
@@ -131,10 +133,8 @@ namespace cv
|
||||
return ACL_DT_UNDEFINED;
|
||||
}
|
||||
|
||||
inline aclrtMemMallocPolicy type_transition(MemMallocPolicy type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
inline aclrtMemMallocPolicy type_transition(MemMallocPolicy type) {
|
||||
switch (type) {
|
||||
case MALLOC_HUGE_FIRST:
|
||||
return ACL_MEM_MALLOC_HUGE_FIRST;
|
||||
case MALLOC_HUGE_ONLY:
|
||||
|
@@ -3,19 +3,20 @@
|
||||
|
||||
#include "acl_mat.hpp"
|
||||
|
||||
namespace cv
|
||||
{
|
||||
namespace acl
|
||||
{
|
||||
namespace cv {
|
||||
namespace acl {
|
||||
// matrix multiplication
|
||||
CV_EXPORTS void MatMul(const aclMat& src1, const aclMat& src2, aclMat& dest, int stream_id = 0);
|
||||
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);
|
||||
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 cv */
|
||||
|
||||
|
||||
#endif
|
@@ -3,19 +3,15 @@
|
||||
|
||||
#include "acl_init.hpp"
|
||||
|
||||
namespace cv
|
||||
{
|
||||
namespace acl
|
||||
{
|
||||
namespace cv {
|
||||
namespace acl {
|
||||
///////////////////////////aclEnv//////////////////////////////////
|
||||
/**
|
||||
* acl init
|
||||
*/
|
||||
inline aclEnv::aclEnv()
|
||||
{}
|
||||
inline aclEnv::aclEnv() {}
|
||||
|
||||
inline aclEnv::aclEnv(const char* config_path)
|
||||
{
|
||||
inline aclEnv::aclEnv(const char *config_path) {
|
||||
uint32_t device_count;
|
||||
|
||||
AclSafeCall(aclInit(config_path));
|
||||
@@ -27,63 +23,50 @@ namespace cv
|
||||
refcount = static_cast<int *>(fastMalloc(sizeof(*refcount)));
|
||||
*refcount = 0;
|
||||
|
||||
clog << "aclInit() is success" << endl;
|
||||
std::clog << "aclInit() is success" << std::endl;
|
||||
}
|
||||
|
||||
inline int aclEnv::get_device_count()
|
||||
{
|
||||
return _device_count;
|
||||
}
|
||||
inline int aclEnv::get_device_count() { return _device_count; }
|
||||
|
||||
inline aclEnv::~aclEnv()
|
||||
{
|
||||
inline aclEnv::~aclEnv() {
|
||||
AclSafeCall(aclFinalize());
|
||||
clog << "aclFinalize() is success" << endl;
|
||||
std::clog << "aclFinalize() is success" << std::endl;
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////aclCxt////////////////////////////
|
||||
inline aclCxt::aclCxt(){};
|
||||
|
||||
inline aclCxt::aclCxt(int device_id) : _device_id(device_id)
|
||||
{
|
||||
inline aclCxt::aclCxt(int device_id) : _device_id(device_id) {
|
||||
_context = static_cast<aclrtContext *>(fastMalloc(sizeof(*_context)));
|
||||
AclSafeCall(aclrtCreateContext(_context, _device_id));
|
||||
|
||||
clog << "aclrtCreateContext() is success" << endl;
|
||||
std::clog << "aclrtCreateContext() is success" << std::endl;
|
||||
}
|
||||
|
||||
inline aclrtContext* aclCxt::get_context()
|
||||
{
|
||||
return _context;
|
||||
}
|
||||
inline aclrtContext *aclCxt::get_context() { return _context; }
|
||||
|
||||
/**
|
||||
* set current context
|
||||
*/
|
||||
inline void aclCxt::set_current_context()
|
||||
{
|
||||
inline void aclCxt::set_current_context() {
|
||||
AclSafeCall(aclrtSetCurrentContext(*_context));
|
||||
}
|
||||
|
||||
inline void aclCxt::create_stream(int count)
|
||||
{
|
||||
inline void aclCxt::create_stream(int count) {
|
||||
CV_Assert(count > 0);
|
||||
|
||||
int i;
|
||||
for(i = 0; i <count; i++)
|
||||
{
|
||||
for (i = 0; i < count; i++) {
|
||||
aclStream stream;
|
||||
AclSafeCall(aclrtCreateStream(&stream));
|
||||
|
||||
_acl_streams.push_back(stream);
|
||||
}
|
||||
|
||||
clog << "aclrtCreateStream() is success" << endl;
|
||||
std::clog << "aclrtCreateStream() is success" << std::endl;
|
||||
}
|
||||
|
||||
inline aclrtStream aclCxt::get_stream(const size_t index)
|
||||
{
|
||||
inline aclrtStream aclCxt::get_stream(const size_t index) {
|
||||
CV_Assert(index < _acl_streams.size());
|
||||
return _acl_streams[index];
|
||||
}
|
||||
@@ -91,24 +74,22 @@ namespace cv
|
||||
/**
|
||||
* destroy stream and context
|
||||
*/
|
||||
inline aclCxt::~aclCxt()
|
||||
{
|
||||
inline aclCxt::~aclCxt() {
|
||||
size_t i = 0;
|
||||
|
||||
AclSafeCall(aclrtSetCurrentContext(*_context));
|
||||
for (i = 0; i < _acl_streams.size(); i++)
|
||||
{
|
||||
for (i = 0; i < _acl_streams.size(); i++) {
|
||||
aclStream acl_stream = _acl_streams[i];
|
||||
AclSafeCall(aclrtDestroyStream(acl_stream));
|
||||
}
|
||||
|
||||
clog << "aclrtDestroyStream() is success" << endl;
|
||||
std::clog << "aclrtDestroyStream() is success" << std::endl;
|
||||
|
||||
// empty vector
|
||||
std::vector<aclrtStream>().swap(_acl_streams);
|
||||
AclSafeCall(aclrtDestroyContext(*_context));
|
||||
|
||||
clog << "aclrtDestroyContext() is success" << endl;
|
||||
std::clog << "aclrtDestroyContext() is success" << std::endl;
|
||||
}
|
||||
|
||||
} /* end of namespace acl */
|
||||
|
@@ -3,67 +3,120 @@
|
||||
|
||||
#include "acl_type.hpp"
|
||||
|
||||
namespace cv
|
||||
{
|
||||
namespace acl
|
||||
{
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
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)
|
||||
{
|
||||
}
|
||||
: 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
|
||||
* @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(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);
|
||||
: 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)
|
||||
{
|
||||
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);
|
||||
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)
|
||||
{
|
||||
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);
|
||||
if (m.rows > 0 && m.cols > 0) create(m.rows, m.cols, m.type(), config);
|
||||
upload(m, config);
|
||||
}
|
||||
|
||||
@@ -72,35 +125,39 @@ namespace cv
|
||||
* @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)
|
||||
{
|
||||
: 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);
|
||||
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);
|
||||
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));
|
||||
}
|
||||
@@ -110,44 +167,55 @@ namespace cv
|
||||
*
|
||||
*/
|
||||
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(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;
|
||||
if (refcount) CV_XADD(refcount, 1);
|
||||
if (rows <= 0 || cols <= 0) rows = cols = 0;
|
||||
|
||||
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)
|
||||
{
|
||||
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();
|
||||
inline aclMat &aclMat::operator=(const aclMat &m) {
|
||||
if (this != &m) {
|
||||
if (refcount) release();
|
||||
flags = m.flags;
|
||||
rows = m.rows;
|
||||
cols = m.cols;
|
||||
@@ -161,36 +229,30 @@ namespace cv
|
||||
acl_context = m.acl_context;
|
||||
totalSize = m.totalSize;
|
||||
data = m.data;
|
||||
if (m.refcount)
|
||||
CV_XADD(m.refcount, 1);
|
||||
if (m.refcount) CV_XADD(m.refcount, 1);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline aclMat& aclMat::operator=(const Mat &m)
|
||||
{
|
||||
inline aclMat &aclMat::operator=(const Mat &m) {
|
||||
upload(m);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline aclMat::operator Mat() const
|
||||
{
|
||||
inline aclMat::operator Mat() const {
|
||||
Mat m(rows, cols, type());
|
||||
download(m);
|
||||
return m;
|
||||
}
|
||||
|
||||
inline aclMat aclMat::clone() const
|
||||
{
|
||||
inline aclMat aclMat::clone() const {
|
||||
aclMat m;
|
||||
copyTo(m);
|
||||
return m;
|
||||
}
|
||||
|
||||
inline void aclMat::copyTo(aclMat& dest) const
|
||||
{
|
||||
if (this != &dest)
|
||||
{
|
||||
inline void aclMat::copyTo(aclMat &dest) const {
|
||||
if (this != &dest) {
|
||||
dest.rows = rows;
|
||||
dest.cols = cols;
|
||||
dest.step = step;
|
||||
@@ -201,8 +263,10 @@ namespace cv
|
||||
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));
|
||||
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);
|
||||
@@ -214,44 +278,36 @@ namespace cv
|
||||
}
|
||||
}
|
||||
|
||||
inline aclMat aclMat::row(int y) const
|
||||
{
|
||||
inline aclMat aclMat::row(int y) const {
|
||||
return aclMat(*this, Range(y, y + 1), Range::all());
|
||||
}
|
||||
|
||||
inline aclMat aclMat::col(int x) const
|
||||
{
|
||||
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
|
||||
{
|
||||
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
|
||||
{
|
||||
inline aclMat aclMat::rowRange(const Range &r) const {
|
||||
return aclMat(*this, r, Range::all());
|
||||
}
|
||||
|
||||
inline aclMat aclMat::colRange(int startcol, int endcol) const
|
||||
{
|
||||
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
|
||||
{
|
||||
inline aclMat aclMat::colRange(const Range &r) const {
|
||||
return aclMat(*this, Range::all(), r);
|
||||
}
|
||||
|
||||
inline void aclMat::locateROI( Size &wholeSize, Point &ofs ) const
|
||||
{
|
||||
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
|
||||
{
|
||||
else {
|
||||
ofs.y = (int)(offset / step);
|
||||
ofs.x = (int)((offset - step * ofs.y) / esz);
|
||||
CV_DbgAssert(data == (datastart + ofs.y * step + ofs.x * esz));
|
||||
@@ -260,14 +316,15 @@ namespace cv
|
||||
wholeSize.width = wholecols;
|
||||
}
|
||||
|
||||
inline aclMat &aclMat::adjustROI( int dtop, int dbottom, int dleft, int dright )
|
||||
{
|
||||
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);
|
||||
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;
|
||||
@@ -280,8 +337,7 @@ namespace cv
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline void aclMat::swap(aclMat &b)
|
||||
{
|
||||
inline void aclMat::swap(aclMat &b) {
|
||||
std::swap(flags, b.flags);
|
||||
std::swap(rows, b.rows);
|
||||
std::swap(cols, b.cols);
|
||||
@@ -297,86 +353,56 @@ namespace cv
|
||||
std::swap(totalSize, b.totalSize);
|
||||
}
|
||||
|
||||
inline aclMat aclMat::operator()( Range rRange, Range cRange ) const
|
||||
{
|
||||
inline aclMat aclMat::operator()(Range rRange, Range cRange) const {
|
||||
return aclMat(*this, rRange, cRange);
|
||||
}
|
||||
|
||||
inline aclMat aclMat::operator()( const Rect &roi ) const
|
||||
{
|
||||
inline aclMat aclMat::operator()(const Rect &roi) const {
|
||||
return aclMat(*this, roi);
|
||||
}
|
||||
|
||||
inline bool aclMat::isContinuous() const
|
||||
{
|
||||
inline bool aclMat::isContinuous() const {
|
||||
return (flags & Mat::CONTINUOUS_FLAG) != 0;
|
||||
}
|
||||
|
||||
inline size_t aclMat::elemSize() const
|
||||
{
|
||||
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
|
||||
{
|
||||
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
|
||||
{
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
inline void ensureSizeIsEnough(Size size, int type, ALIGNMENT config,
|
||||
aclMat &m) {
|
||||
ensureSizeIsEnough(size.height, size.width, type, m, config);
|
||||
}
|
||||
|
||||
|
@@ -7,19 +7,22 @@
|
||||
* mathfunctions;
|
||||
*/
|
||||
|
||||
namespace cv
|
||||
{
|
||||
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 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 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);
|
||||
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 */
|
||||
|
@@ -3,19 +3,16 @@
|
||||
|
||||
#include "acl_mat.hpp"
|
||||
|
||||
namespace cv
|
||||
{
|
||||
namespace acl
|
||||
{
|
||||
// Matrix lookup table
|
||||
//CV_EXPORTS void lookUpTable(const aclMat& src, const aclMat& lut, aclMat& dst);
|
||||
namespace cv {
|
||||
namespace acl {
|
||||
// Multiple channel merge
|
||||
CV_EXPORTS void merge(const vector<aclMat>& mv, aclMat& dst, int stream_id = 0);
|
||||
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, vector<aclMat>& mv, int stream_id = 0);
|
||||
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);
|
||||
CV_EXPORTS void flip(const aclMat &src, aclMat &dest, int flipCode = 0,
|
||||
int stream_id = 0);
|
||||
} /* end of namespace acl */
|
||||
|
||||
} /* end of namespace cv */
|
||||
|
@@ -4,17 +4,14 @@
|
||||
#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
|
||||
{
|
||||
namespace cv {
|
||||
namespace acl {
|
||||
class CV_EXPORTS OperatorDesc {
|
||||
public:
|
||||
/**
|
||||
* Constructor
|
||||
@@ -35,7 +32,8 @@ namespace cv
|
||||
* @param [in] format: format
|
||||
* @return OperatorDesc
|
||||
*/
|
||||
OperatorDesc &AddInputTensorDesc(aclDataType dataType, int numDims, const int64_t *dims, aclFormat format);
|
||||
OperatorDesc &AddInputTensorDesc(aclDataType dataType, int numDims,
|
||||
const int64_t *dims, aclFormat format);
|
||||
|
||||
/**
|
||||
* Add an output tensor description
|
||||
@@ -45,15 +43,13 @@ namespace cv
|
||||
* @param [in] format: format
|
||||
* @return OperatorDesc
|
||||
*/
|
||||
OperatorDesc &AddOutputTensorDesc(aclDataType dataType, int numDims, const int64_t *dims, aclFormat format);
|
||||
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)
|
||||
{
|
||||
bool AddTensorAttr(const char *attrName, AttrType type, T vaule) {
|
||||
if (opAttr == nullptr) return false;
|
||||
switch (type) {
|
||||
case OP_BOOL:
|
||||
aclopSetAttrBool(opAttr, attrName, vaule);
|
||||
break;
|
||||
@@ -74,17 +70,27 @@ namespace cv
|
||||
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);
|
||||
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, vector<aclDataBuffer *> &inputBuffers_, vector<aclDataBuffer *> &outputBuffers_, aclCxt *acl_context, int stream_id);
|
||||
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 string opType, int stream_id = 0);
|
||||
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 string opType, int stream_id = 0);
|
||||
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(vector<aclMat> &input, vector<aclMat> &output, OperatorDesc &opDesc, int stream_id);
|
||||
CV_EXPORTS void Runop(std::vector<aclMat> &input, std::vector<aclMat> &output,
|
||||
OperatorDesc &opDesc, int stream_id);
|
||||
|
||||
} /* end of namespace acl */
|
||||
|
||||
|
@@ -2,7 +2,8 @@
|
||||
//
|
||||
// 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
|
||||
@@ -42,35 +50,28 @@
|
||||
//M */
|
||||
#include "precomp.hpp"
|
||||
|
||||
|
||||
|
||||
namespace cv
|
||||
{
|
||||
namespace acl
|
||||
{
|
||||
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();
|
||||
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)
|
||||
{
|
||||
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);
|
||||
if (nullptr == global_aclenv) global_aclenv = new aclEnv(config_path);
|
||||
}
|
||||
return global_aclenv;
|
||||
}
|
||||
|
||||
void wait_stream(aclCxt * acl_context, const int stream_id)
|
||||
{
|
||||
void wait_stream(aclCxt *acl_context, const int stream_id) {
|
||||
aclrtSynchronizeStream(acl_context->get_stream(stream_id));
|
||||
}
|
||||
|
||||
@@ -81,8 +82,7 @@ namespace cv
|
||||
* @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)
|
||||
{
|
||||
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());
|
||||
@@ -99,18 +99,15 @@ namespace cv
|
||||
return acl_context;
|
||||
}
|
||||
|
||||
void release_device(aclCxt* context)
|
||||
{
|
||||
void release_device(aclCxt *context) {
|
||||
CV_Assert(context);
|
||||
delete context;
|
||||
context = nullptr;
|
||||
if (global_aclenv->refcount)
|
||||
{
|
||||
if (global_aclenv->refcount) {
|
||||
AutoLock lock(getInitMutex());
|
||||
CV_XADD(global_aclenv->refcount, -1);
|
||||
|
||||
if (*(global_aclenv->refcount) == 0)
|
||||
{
|
||||
if (*(global_aclenv->refcount) == 0) {
|
||||
delete global_aclenv;
|
||||
global_aclenv = nullptr;
|
||||
}
|
||||
|
@@ -1,111 +1,111 @@
|
||||
#include "precomp.hpp"
|
||||
|
||||
|
||||
#define ALIGN 64
|
||||
|
||||
namespace cv
|
||||
{
|
||||
namespace acl
|
||||
{
|
||||
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, 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, 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);
|
||||
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);
|
||||
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);
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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 (rows == _rows && cols == _cols && type() == _type && data) return;
|
||||
|
||||
if (data)
|
||||
release();
|
||||
if (data) release();
|
||||
|
||||
CV_DbgAssert(_rows >= 0 && _cols >= 0);
|
||||
|
||||
if (_rows > 0 && _cols > 0)
|
||||
{
|
||||
if (_rows > 0 && _cols > 0) {
|
||||
/* TO ENSURE */
|
||||
// flags = (_type & CV_MAT_TYPE_MASK) | MAGIC_VAL;
|
||||
flags = Mat::MAGIC_VAL + _type;
|
||||
@@ -115,14 +115,12 @@ namespace cv
|
||||
wholecols = _cols;
|
||||
size_t esz = elemSize();
|
||||
void *dev_ptr;
|
||||
if (config == ALIGNMENT::MEMORY_ALIGN)
|
||||
{
|
||||
if (config == ALIGNMENT::MEMORY_ALIGN) {
|
||||
if (channels() == 3)
|
||||
step = alignSize(cols * esz, ALIGN * channels());
|
||||
else
|
||||
step = alignSize(cols * esz);
|
||||
}
|
||||
else
|
||||
} else
|
||||
step = cols * esz;
|
||||
totalSize = step * rows;
|
||||
|
||||
@@ -138,16 +136,14 @@ namespace cv
|
||||
}
|
||||
}
|
||||
|
||||
void aclMat::createEx(Size size, int type, ALIGNMENT config, MemMallocPolicy policy)
|
||||
{
|
||||
void aclMat::createEx(Size size, int type, ALIGNMENT config,
|
||||
MemMallocPolicy policy) {
|
||||
createEx(size.height, size.width, type, config, policy);
|
||||
}
|
||||
|
||||
void aclMat::release()
|
||||
{
|
||||
void aclMat::release() {
|
||||
CV_XADD(refcount, -1);
|
||||
if (data && (*refcount == 0))
|
||||
{
|
||||
if (data && (*refcount == 0)) {
|
||||
aclrtFree(data);
|
||||
}
|
||||
data = nullptr;
|
||||
@@ -155,29 +151,28 @@ namespace cv
|
||||
dataend = nullptr;
|
||||
}
|
||||
|
||||
aclMat &aclMat::operator+=(const aclMat &m)
|
||||
{
|
||||
CV_Assert(this->rows == m.rows && this->cols == m.cols && this->type() == m.type());
|
||||
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());
|
||||
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());
|
||||
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)
|
||||
{
|
||||
aclMat &aclMat::operator*=(const aclMat &m) {
|
||||
CV_Assert(this->cols == m.rows && this->type() == m.type());
|
||||
vector<aclMat> input_Mat;
|
||||
vector<aclMat> output_Mat;
|
||||
@@ -189,7 +184,8 @@ namespace cv
|
||||
input_Mat.emplace_back(m);
|
||||
output_Mat.emplace_back(newMat);
|
||||
|
||||
OperatorDesc opDesc = CreateOpDesc("MatMul", input_Mat, output_Mat, ACL_FORMAT_NHWC, TWO_DIMS);
|
||||
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);
|
||||
@@ -197,7 +193,8 @@ namespace cv
|
||||
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));
|
||||
outputBuffers_.emplace_back(
|
||||
aclCreateDataBuffer(newMat.data, newMat.totalSize));
|
||||
|
||||
compileAndRunop(opDesc, inputBuffers_, outputBuffers_, this->acl_context, 0);
|
||||
|
||||
|
@@ -1,15 +1,16 @@
|
||||
#include "precomp.hpp"
|
||||
|
||||
namespace cv
|
||||
{
|
||||
namespace acl
|
||||
{
|
||||
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)
|
||||
{
|
||||
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;
|
||||
@@ -25,11 +26,13 @@ namespace cv
|
||||
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);
|
||||
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);
|
||||
compileAndRunop(opDesc, inputBuffers_, outputBuffers_, dest.acl_context,
|
||||
stream_id);
|
||||
|
||||
for (size_t i = 0; i < inputBuffers_.size(); i++)
|
||||
AclSafeCall(aclDestroyDataBuffer(inputBuffers_[i]));
|
||||
@@ -45,14 +48,21 @@ namespace cv
|
||||
* @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)
|
||||
{
|
||||
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;
|
||||
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};
|
||||
@@ -67,14 +77,19 @@ namespace cv
|
||||
opDesc.AddOutputTensorDesc(dataType, shape2.size(), shape2.data(), format);
|
||||
|
||||
auto opAttr = opDesc.opAttr;
|
||||
aclopSetAttrListInt(opAttr, "strides", stridesList.size(), stridesList.data());
|
||||
aclopSetAttrListInt(opAttr, "strides", stridesList.size(),
|
||||
stridesList.data());
|
||||
aclopSetAttrListInt(opAttr, "pads", padsList.size(), padsList.data());
|
||||
aclopSetAttrListInt(opAttr, "dilations", dilationsList.size(), dilationsList.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);
|
||||
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;
|
||||
|
||||
|
@@ -1,72 +1,68 @@
|
||||
#include "precomp.hpp"
|
||||
|
||||
namespace cv
|
||||
{
|
||||
namespace acl
|
||||
{
|
||||
aclMat abs(const aclMat& a, int stream_id)
|
||||
{
|
||||
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)
|
||||
{
|
||||
static void *power_data(double power, aclDataType type, size_t powersize) {
|
||||
void *dev_ptr;
|
||||
|
||||
switch(type)
|
||||
{
|
||||
case ACL_UINT8:
|
||||
{
|
||||
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);
|
||||
aclrtMemcpy(dev_ptr, powersize, static_cast<void *>(&power_8u), powersize,
|
||||
ACL_MEMCPY_HOST_TO_DEVICE);
|
||||
return dev_ptr;
|
||||
}
|
||||
case ACL_INT8:
|
||||
{
|
||||
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);
|
||||
aclrtMemcpy(dev_ptr, powersize, static_cast<void *>(&power_8s), powersize,
|
||||
ACL_MEMCPY_HOST_TO_DEVICE);
|
||||
return dev_ptr;
|
||||
}
|
||||
case ACL_FLOAT16:
|
||||
{
|
||||
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);
|
||||
aclrtMemcpy(dev_ptr, powersize, static_cast<void *>(&power_16f),
|
||||
powersize, ACL_MEMCPY_HOST_TO_DEVICE);
|
||||
return dev_ptr;
|
||||
}
|
||||
case ACL_INT32:
|
||||
{
|
||||
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);
|
||||
aclrtMemcpy(dev_ptr, powersize, static_cast<void *>(&power_32s),
|
||||
powersize, ACL_MEMCPY_HOST_TO_DEVICE);
|
||||
return dev_ptr;
|
||||
}
|
||||
case ACL_FLOAT:
|
||||
{
|
||||
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);
|
||||
aclrtMemcpy(dev_ptr, powersize, static_cast<void *>(&power_32f),
|
||||
powersize, ACL_MEMCPY_HOST_TO_DEVICE);
|
||||
return dev_ptr;
|
||||
}
|
||||
case ACL_DOUBLE:
|
||||
{
|
||||
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);
|
||||
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)
|
||||
{
|
||||
void pow(const aclMat &src, double power, aclMat &dest, int stream_id) {
|
||||
vector<aclMat> input_Mat;
|
||||
vector<aclMat> output_Mat;
|
||||
vector<aclDataBuffer *> inputBuffers_;
|
||||
@@ -79,7 +75,8 @@ namespace cv
|
||||
|
||||
OperatorDesc opDesc = CreateOpDesc("Pow", input_Mat, output_Mat);
|
||||
vector<int64_t> shape2{1};
|
||||
opDesc.AddInputTensorDesc(dataType, shape2.size(), shape2.data(), ACL_FORMAT_NHWC);
|
||||
opDesc.AddInputTensorDesc(dataType, shape2.size(), shape2.data(),
|
||||
ACL_FORMAT_NHWC);
|
||||
|
||||
size_t size = aclGetTensorDescSize(opDesc.inputDesc[1]);
|
||||
void *power_dev = power_data(power, dataType, size);
|
||||
@@ -89,7 +86,8 @@ namespace cv
|
||||
|
||||
outputBuffers_.emplace_back(aclCreateDataBuffer(dest.data, dest.totalSize));
|
||||
|
||||
compileAndRunop(opDesc, inputBuffers_, outputBuffers_, dest.acl_context, stream_id);
|
||||
compileAndRunop(opDesc, inputBuffers_, outputBuffers_, dest.acl_context,
|
||||
stream_id);
|
||||
|
||||
aclrtFree(power_dev);
|
||||
for (size_t i = 0; i < inputBuffers_.size(); i++)
|
||||
@@ -98,8 +96,8 @@ namespace cv
|
||||
AclSafeCall(aclDestroyDataBuffer(outputBuffers_[i]));
|
||||
}
|
||||
|
||||
void add(const aclMat& src, const aclMat& other_src, aclMat& dest, int 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);
|
||||
@@ -113,8 +111,8 @@ namespace cv
|
||||
TwoInAndOneOut(src, other_src, dest, "Add", stream_id);
|
||||
}
|
||||
|
||||
void divide(const aclMat& src, const aclMat& other_src, aclMat& dest, int stream_id)
|
||||
{
|
||||
void divide(const aclMat &src, const aclMat &other_src, aclMat &dest,
|
||||
int stream_id) {
|
||||
bool is_correct;
|
||||
|
||||
is_correct = (src.rows == other_src.rows);
|
||||
@@ -128,9 +126,9 @@ namespace cv
|
||||
TwoInAndOneOut(src, other_src, dest, "Div", 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 exp(const aclMat &src, aclMat &dest, int stream_id) {
|
||||
CV_Assert(src.rows == dest.rows && src.cols == dest.cols &&
|
||||
src.type() == dest.type());
|
||||
|
||||
vector<aclMat> input_Mat;
|
||||
vector<aclMat> output_Mat;
|
||||
@@ -149,15 +147,16 @@ namespace cv
|
||||
opDesc.AddTensorAttr("scale", OP_FLOAT, 1.0);
|
||||
opDesc.AddTensorAttr("shift", OP_FLOAT, 0.0);
|
||||
|
||||
compileAndRunop(opDesc, inputBuffers_, outputBuffers_, dest.acl_context, stream_id);
|
||||
compileAndRunop(opDesc, inputBuffers_, outputBuffers_, dest.acl_context,
|
||||
stream_id);
|
||||
|
||||
AclSafeCall(aclDestroyDataBuffer(inputBuffers_[0]));
|
||||
AclSafeCall(aclDestroyDataBuffer(outputBuffers_[0]));
|
||||
}
|
||||
|
||||
void log(const aclMat &src, aclMat &dest, int stream_id)
|
||||
{
|
||||
CV_Assert(src.rows == dest.rows && src.cols == dest.cols && src.type() == dest.type());
|
||||
void log(const aclMat &src, aclMat &dest, int stream_id) {
|
||||
CV_Assert(src.rows == dest.rows && src.cols == dest.cols &&
|
||||
src.type() == dest.type());
|
||||
|
||||
vector<aclMat> input_Mat;
|
||||
vector<aclMat> output_Mat;
|
||||
@@ -176,14 +175,15 @@ namespace cv
|
||||
opDesc.AddTensorAttr("scale", OP_FLOAT, 1.0);
|
||||
opDesc.AddTensorAttr("shift", OP_FLOAT, 0.0);
|
||||
|
||||
compileAndRunop(opDesc, inputBuffers_, outputBuffers_, dest.acl_context, stream_id);
|
||||
compileAndRunop(opDesc, inputBuffers_, outputBuffers_, dest.acl_context,
|
||||
stream_id);
|
||||
|
||||
AclSafeCall(aclDestroyDataBuffer(inputBuffers_[0]));
|
||||
AclSafeCall(aclDestroyDataBuffer(outputBuffers_[0]));
|
||||
}
|
||||
|
||||
void max(const aclMat &src, const aclMat &other_src, aclMat &dest, int stream_id)
|
||||
{
|
||||
void max(const aclMat &src, const aclMat &other_src, aclMat &dest,
|
||||
int stream_id) {
|
||||
bool is_correct;
|
||||
|
||||
is_correct = (src.rows == other_src.rows);
|
||||
@@ -197,8 +197,8 @@ namespace cv
|
||||
TwoInAndOneOut(src, other_src, dest, "Maximum", stream_id);
|
||||
}
|
||||
|
||||
void min(const aclMat &src, const aclMat &other_src, aclMat &dest, int stream_id)
|
||||
{
|
||||
void min(const aclMat &src, const aclMat &other_src, aclMat &dest,
|
||||
int stream_id) {
|
||||
bool is_correct;
|
||||
|
||||
is_correct = (src.rows == other_src.rows);
|
||||
@@ -212,9 +212,9 @@ namespace cv
|
||||
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());
|
||||
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);
|
||||
}
|
||||
|
@@ -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,34 +17,38 @@ 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)
|
||||
{
|
||||
#endif
|
||||
|
||||
static int merge_type(int depth, int channels) {
|
||||
switch (depth) {
|
||||
case CV_8U:
|
||||
return CV_8UC(channels);
|
||||
case CV_8S:
|
||||
@@ -108,8 +63,7 @@ namespace cv
|
||||
return -1;
|
||||
}
|
||||
|
||||
void merge(const vector<aclMat>& mv, aclMat& dest, int stream_id)
|
||||
{
|
||||
void merge(const vector<aclMat> &mv, aclMat &dest, int stream_id) {
|
||||
vector<aclDataBuffer *> inputBuffers_;
|
||||
vector<aclDataBuffer *> outputBuffers_;
|
||||
|
||||
@@ -117,19 +71,21 @@ namespace cv
|
||||
aclDataType dataType = type_transition(mv[0].depth());
|
||||
|
||||
vector<int64_t> inputShape{};
|
||||
opDesc.AddInputTensorDesc(ACL_INT32, inputShape.size(), inputShape.data(), ACL_FORMAT_ND);
|
||||
opDesc.AddInputTensorDesc(ACL_INT32, inputShape.size(), inputShape.data(),
|
||||
ACL_FORMAT_ND);
|
||||
|
||||
for (size_t i = 0; i < mv.size(); ++i)
|
||||
{
|
||||
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);
|
||||
opDesc.AddInputTensorDesc(dataType, inputShape.size(), inputShape.data(),
|
||||
ACL_FORMAT_NHWC);
|
||||
}
|
||||
|
||||
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);
|
||||
opDesc.AddOutputTensorDesc(dataType, outputShape.size(), outputShape.data(),
|
||||
ACL_FORMAT_NHWC);
|
||||
|
||||
ino64_t N = mv.size();
|
||||
aclopSetAttrInt(opDesc.opAttr, "N", N);
|
||||
@@ -152,14 +108,16 @@ namespace cv
|
||||
inputBuffers_.emplace_back(aclCreateDataBuffer(dev, size));
|
||||
|
||||
for (size_t i = 0; i < mv.size(); ++i)
|
||||
inputBuffers_.emplace_back(aclCreateDataBuffer(mv[i].data, mv[i].totalSize));
|
||||
inputBuffers_.emplace_back(
|
||||
aclCreateDataBuffer(mv[i].data, mv[i].totalSize));
|
||||
|
||||
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));
|
||||
|
||||
compileAndRunop(opDesc, inputBuffers_, outputBuffers_, dest.acl_context, stream_id);
|
||||
compileAndRunop(opDesc, inputBuffers_, outputBuffers_, dest.acl_context,
|
||||
stream_id);
|
||||
|
||||
for (size_t i = 0; i < inputBuffers_.size(); i++)
|
||||
AclSafeCall(aclDestroyDataBuffer(inputBuffers_[i]));
|
||||
@@ -169,16 +127,12 @@ namespace cv
|
||||
aclrtFree(dev);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief : Dynamic shape reasoning
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
void transpose(const aclMat& src, aclMat& dest, int stream_id)
|
||||
{
|
||||
void transpose(const aclMat &src, aclMat &dest, int stream_id) {
|
||||
vector<aclDataBuffer *> inputBuffers_;
|
||||
vector<aclDataBuffer *> outputBuffers_;
|
||||
vector<aclDataBuffer *> inputBuffers_host;
|
||||
@@ -187,13 +141,16 @@ namespace cv
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
opDesc.AddOutputTensorDesc(dataType, outputShape.size(), outputShape.data(),
|
||||
ACL_FORMAT_ND);
|
||||
|
||||
inputBuffers_.emplace_back(aclCreateDataBuffer(src.data, src.totalSize));
|
||||
|
||||
@@ -210,35 +167,29 @@ namespace cv
|
||||
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);
|
||||
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));
|
||||
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,
|
||||
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]));
|
||||
@@ -251,7 +202,6 @@ namespace cv
|
||||
AclSafeCall(aclrtFreeHost(host_data));
|
||||
}
|
||||
|
||||
|
||||
/* transposeD */
|
||||
#if 0
|
||||
void transpose(const aclMat& src, aclMat& dest)
|
||||
@@ -281,10 +231,8 @@ namespace cv
|
||||
}
|
||||
#endif
|
||||
|
||||
static int split_type(int depth)
|
||||
{
|
||||
switch (depth)
|
||||
{
|
||||
static int split_type(int depth) {
|
||||
switch (depth) {
|
||||
case CV_8U:
|
||||
return CV_8UC1;
|
||||
case CV_8S:
|
||||
@@ -299,8 +247,7 @@ namespace cv
|
||||
return -1;
|
||||
}
|
||||
|
||||
void split(const aclMat& src, vector<aclMat>& mv, int stream_id)
|
||||
{
|
||||
void split(const aclMat &src, vector<aclMat> &mv, int stream_id) {
|
||||
vector<aclDataBuffer *> inputBuffers_;
|
||||
vector<aclDataBuffer *> outputBuffers_;
|
||||
int split_dim = 3;
|
||||
@@ -311,12 +258,13 @@ namespace cv
|
||||
|
||||
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);
|
||||
opDesc.AddInputTensorDesc(dataType, inputShape1.size(), inputShape1.data(),
|
||||
ACL_FORMAT_ND);
|
||||
|
||||
for (int i = 0; i < num_split; ++i)
|
||||
{
|
||||
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);
|
||||
opDesc.AddOutputTensorDesc(dataType, outputShape.size(), outputShape.data(),
|
||||
ACL_FORMAT_ND);
|
||||
}
|
||||
|
||||
auto opAttr = opDesc.opAttr;
|
||||
@@ -326,21 +274,21 @@ namespace cv
|
||||
inputBuffers_.emplace_back(aclCreateDataBuffer(src.data, src.totalSize));
|
||||
|
||||
int type = split_type(src.depth());
|
||||
for (int i = 0; i < num_split; ++i)
|
||||
{
|
||||
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));
|
||||
outputBuffers_.emplace_back(
|
||||
aclCreateDataBuffer(mv[i].data, mv[i].totalSize));
|
||||
}
|
||||
|
||||
compileAndRunop(opDesc, inputBuffers_, outputBuffers_, src.acl_context, stream_id);
|
||||
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,8 +377,7 @@ namespace cv
|
||||
}
|
||||
#endif
|
||||
|
||||
static void flip_(const aclMat& src, aclMat& dest, int axis, int stream_id)
|
||||
{
|
||||
static void flip_(const aclMat &src, aclMat &dest, int axis, int stream_id) {
|
||||
vector<aclDataBuffer *> inputBuffers_;
|
||||
vector<aclDataBuffer *> outputBuffers_;
|
||||
|
||||
@@ -438,13 +385,16 @@ namespace cv
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
opDesc.AddOutputTensorDesc(dataType, outputShape.size(), outputShape.data(),
|
||||
ACL_FORMAT_ND);
|
||||
|
||||
inputBuffers_.emplace_back(aclCreateDataBuffer(src.data, src.totalSize));
|
||||
|
||||
@@ -456,7 +406,8 @@ namespace cv
|
||||
|
||||
outputBuffers_.emplace_back(aclCreateDataBuffer(dest.data, dest.totalSize));
|
||||
|
||||
compileAndRunop(opDesc, inputBuffers_, outputBuffers_, dest.acl_context, stream_id);
|
||||
compileAndRunop(opDesc, inputBuffers_, outputBuffers_, dest.acl_context,
|
||||
stream_id);
|
||||
|
||||
AclSafeCall(aclDestroyDataBuffer(inputBuffers_[0]));
|
||||
AclSafeCall(aclDestroyDataBuffer(inputBuffers_[1]));
|
||||
@@ -464,18 +415,16 @@ namespace cv
|
||||
AclSafeCall(aclrtFree(dev));
|
||||
}
|
||||
|
||||
void flip(const aclMat& src, aclMat& dest, int filpCode, int stream_id)
|
||||
{
|
||||
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) {
|
||||
} else if (filpCode > 0) {
|
||||
flip_(src, dest, 2, stream_id);
|
||||
}
|
||||
else {
|
||||
} 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);
|
||||
aclrtMemcpy(tmp.data, dest.totalSize, dest.data, dest.totalSize,
|
||||
ACL_MEMCPY_DEVICE_TO_DEVICE);
|
||||
flip_(tmp, dest, 1, stream_id);
|
||||
}
|
||||
}
|
||||
|
@@ -12,25 +12,20 @@
|
||||
#include "precomp.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace cv
|
||||
{
|
||||
namespace acl
|
||||
{
|
||||
OperatorDesc::OperatorDesc(std::string opType) : opType(std::move(opType))
|
||||
{
|
||||
using namespace cv;
|
||||
using namespace cv::acl;
|
||||
namespace cv {
|
||||
namespace acl {
|
||||
OperatorDesc::OperatorDesc(std::string opType) : opType(std::move(opType)) {
|
||||
opAttr = aclopCreateAttr();
|
||||
}
|
||||
|
||||
OperatorDesc::~OperatorDesc()
|
||||
{
|
||||
for (auto *desc : inputDesc)
|
||||
{
|
||||
OperatorDesc::~OperatorDesc() {
|
||||
for (auto* desc : inputDesc) {
|
||||
aclDestroyTensorDesc(desc);
|
||||
}
|
||||
|
||||
for (auto *desc : outputDesc)
|
||||
{
|
||||
for (auto* desc : outputDesc) {
|
||||
aclDestroyTensorDesc(desc);
|
||||
}
|
||||
|
||||
@@ -38,10 +33,8 @@ namespace cv
|
||||
}
|
||||
|
||||
OperatorDesc& OperatorDesc::AddInputTensorDesc(aclDataType dataType,
|
||||
int numDims,
|
||||
const int64_t *dims,
|
||||
aclFormat format)
|
||||
{
|
||||
int numDims, const int64_t* dims,
|
||||
aclFormat format) {
|
||||
aclTensorDesc* desc = aclCreateTensorDesc(dataType, numDims, dims, format);
|
||||
CV_Assert(desc);
|
||||
inputDesc.emplace_back(desc);
|
||||
@@ -51,8 +44,7 @@ namespace cv
|
||||
OperatorDesc& OperatorDesc::AddOutputTensorDesc(aclDataType dataType,
|
||||
int numDims,
|
||||
const int64_t* dims,
|
||||
aclFormat format)
|
||||
{
|
||||
aclFormat format) {
|
||||
aclTensorDesc* desc = aclCreateTensorDesc(dataType, numDims, dims, format);
|
||||
CV_Assert(desc);
|
||||
outputDesc.emplace_back(desc);
|
||||
@@ -63,8 +55,9 @@ namespace cv
|
||||
* @brief create operator describe
|
||||
*
|
||||
*/
|
||||
OperatorDesc CreateOpDesc(const string opType, const vector<aclMat>& input_Mat, vector<aclMat>& output_Mat, aclFormat format, Opdims config)
|
||||
{
|
||||
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;
|
||||
@@ -72,31 +65,27 @@ namespace cv
|
||||
|
||||
OperatorDesc opDesc(opType);
|
||||
for (i = 0; i < input_Mat.size(); ++i) {
|
||||
if (config == TWO_DIMS)
|
||||
{
|
||||
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)
|
||||
{
|
||||
} 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()};
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
} 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()};
|
||||
vector<int64_t> shape{1, output_Mat[i].rows, cols,
|
||||
output_Mat[i].channels()};
|
||||
opDesc.AddOutputTensorDesc(dataType, shape.size(), shape.data(), format);
|
||||
}
|
||||
}
|
||||
@@ -108,42 +97,38 @@ namespace cv
|
||||
* @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));
|
||||
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,
|
||||
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)
|
||||
{
|
||||
void Runop(vector<aclMat>& input, vector<aclMat>& output, OperatorDesc& opDesc,
|
||||
int stream_id) {
|
||||
size_t i;
|
||||
|
||||
vector<aclDataBuffer*> inputBuffers_;
|
||||
vector<aclDataBuffer*> outputBuffers_;
|
||||
|
||||
for (i = 0; i < input.size(); ++i)
|
||||
inputBuffers_.emplace_back(aclCreateDataBuffer(input[i].data, input[i].totalSize));
|
||||
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));
|
||||
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]));
|
||||
@@ -151,8 +136,8 @@ namespace cv
|
||||
AclSafeCall(aclDestroyDataBuffer(outputBuffers_[i]));
|
||||
}
|
||||
|
||||
void OneInAndOneOut(const aclMat& inputMat, aclMat& outputMat, const string opType, int stream_id)
|
||||
{
|
||||
void OneInAndOneOut(const aclMat& inputMat, aclMat& outputMat,
|
||||
const string opType, int stream_id) {
|
||||
vector<aclMat> input_Mat;
|
||||
vector<aclMat> output_Mat;
|
||||
|
||||
@@ -163,8 +148,8 @@ namespace cv
|
||||
Runop(input_Mat, output_Mat, opDesc, stream_id);
|
||||
}
|
||||
|
||||
void TwoInAndOneOut(const aclMat& inputMat, const aclMat& inputMatOther, aclMat& outputMat, const string opType, int 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;
|
||||
|
||||
|
@@ -2,7 +2,8 @@
|
||||
//
|
||||
// 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
|
||||
@@ -43,7 +50,6 @@
|
||||
#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
|
||||
|
150
acl/test/acl.cpp
150
acl/test/acl.cpp
@@ -1,24 +1,28 @@
|
||||
#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
|
||||
{
|
||||
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(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)
|
||||
{
|
||||
TEST(ACLMAT_CONSTRUCTOR, MEMORY_ALIGN) {
|
||||
AclMat_Test test;
|
||||
test.Test_constructor_ALIGN(acl_context_0);
|
||||
}
|
||||
@@ -26,12 +30,13 @@ namespace opencv_test
|
||||
/* 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);
|
||||
* 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)
|
||||
{
|
||||
TEST(ACLMAT_CONSTRUCTOR, MEMORY_UNALIGNED) {
|
||||
AclMat_Test test;
|
||||
test.Test_constructor_UNALIGNED(acl_context_0);
|
||||
}
|
||||
@@ -40,30 +45,30 @@ namespace opencv_test
|
||||
* test function:
|
||||
* aclMat(const aclMat &m);
|
||||
*/
|
||||
TEST(ACLMAT_CONSTRUCTOR, COPY_CONSTRUCTOR)
|
||||
{
|
||||
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);
|
||||
* 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)
|
||||
{
|
||||
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());
|
||||
* aclMat(const aclMat &m, const Range &rowRange, const Range &colRange =
|
||||
* Range::all());
|
||||
*
|
||||
*/
|
||||
TEST(ACLMAT_CONSTRUCTOR, RANGE)
|
||||
{
|
||||
TEST(ACLMAT_CONSTRUCTOR, RANGE) {
|
||||
AclMat_Test test;
|
||||
test.Test_constructor_RANGE(acl_context_0);
|
||||
}
|
||||
@@ -73,18 +78,17 @@ namespace opencv_test
|
||||
* aclMat(const aclMat &m, const Rect &roi);
|
||||
*
|
||||
*/
|
||||
TEST(ACLMAT_CONSTRUCTOR, 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);
|
||||
* aclMat (const Mat &m, aclCxt* acl_context, ALIGNMENT config =
|
||||
* MEMORY_UNALIGNED, aclrtMemMallocPolicy policy = ACL_MEM_MALLOC_HUGE_FIRST);
|
||||
*/
|
||||
TEST(ACLMAT_CONSTRUCTOR, MAT)
|
||||
{
|
||||
TEST(ACLMAT_CONSTRUCTOR, MAT) {
|
||||
AclMat_Test test;
|
||||
test.Test_constructor_MAT(acl_context_0);
|
||||
}
|
||||
@@ -92,11 +96,11 @@ namespace opencv_test
|
||||
/* 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);
|
||||
* CV_EXPORTS void upload(const Mat &m, aclStream stream, ALIGNMENT config =
|
||||
* MEMORY_UNALIGNED);
|
||||
*
|
||||
*/
|
||||
TEST(ACLMAT_FUNCTION, DATA_TRANSFER)
|
||||
{
|
||||
TEST(ACLMAT_FUNCTION, DATA_TRANSFER) {
|
||||
AclMat_Test test;
|
||||
test.Test_DATA_TRANSFER(acl_context_0);
|
||||
}
|
||||
@@ -104,11 +108,11 @@ namespace opencv_test
|
||||
/* 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;
|
||||
* CV_EXPORTS void download(Mat &m, aclStream stream, ALIGNMENT config =
|
||||
* MEMORY_UNALIGNED) const;
|
||||
*
|
||||
*/
|
||||
TEST(ACLMAT_FUNCTION, DATA_TRANSFERASYNC)
|
||||
{
|
||||
TEST(ACLMAT_FUNCTION, DATA_TRANSFERASYNC) {
|
||||
AclMat_Test test;
|
||||
test.Test_DATA_TRANSFERASYNC(acl_context_0);
|
||||
}
|
||||
@@ -117,8 +121,7 @@ namespace opencv_test
|
||||
* test function:
|
||||
* void locateROI(Size &wholeSize, Point &ofs) const;
|
||||
*/
|
||||
TEST(ACLMAT_FUNCTION, LOCATEROI)
|
||||
{
|
||||
TEST(ACLMAT_FUNCTION, LOCATEROI) {
|
||||
AclMat_Test test;
|
||||
test.Test_locateROI(acl_context_0);
|
||||
}
|
||||
@@ -128,8 +131,7 @@ namespace opencv_test
|
||||
* void swap(aclMat &mat);
|
||||
*
|
||||
*/
|
||||
TEST(ACLMAT_FUNCTION, SWAP)
|
||||
{
|
||||
TEST(ACLMAT_FUNCTION, SWAP) {
|
||||
AclMat_Test test;
|
||||
test.Test_swap(acl_context_0);
|
||||
}
|
||||
@@ -139,8 +141,7 @@ namespace opencv_test
|
||||
* operator+=()
|
||||
*
|
||||
*/
|
||||
TEST(ACLMAT_FUNCTION, OPERATOR_ADD)
|
||||
{
|
||||
TEST(ACLMAT_FUNCTION, OPERATOR_ADD) {
|
||||
AclMat_Test test;
|
||||
test.Test_operator_add(acl_context_0);
|
||||
}
|
||||
@@ -150,8 +151,7 @@ namespace opencv_test
|
||||
* operator-=()
|
||||
*
|
||||
*/
|
||||
TEST(ACLMAT_FUNCTION, OPERATOR_SUB)
|
||||
{
|
||||
TEST(ACLMAT_FUNCTION, OPERATOR_SUB) {
|
||||
AclMat_Test test;
|
||||
test.Test_operator_sub(acl_context_0);
|
||||
}
|
||||
@@ -161,8 +161,7 @@ namespace opencv_test
|
||||
* operator*=()
|
||||
*
|
||||
*/
|
||||
TEST(ACLMAT_FUNCTION, OPERATOR_MUL)
|
||||
{
|
||||
TEST(ACLMAT_FUNCTION, OPERATOR_MUL) {
|
||||
AclMat_Test test;
|
||||
test.Test_operator_mul(acl_context_0);
|
||||
}
|
||||
@@ -172,128 +171,107 @@ namespace opencv_test
|
||||
* operator/=()
|
||||
*
|
||||
*/
|
||||
TEST(ACLMAT_FUNCTION, OPERATOR_DIV)
|
||||
{
|
||||
TEST(ACLMAT_FUNCTION, OPERATOR_DIV) {
|
||||
AclMat_Test test;
|
||||
test.Test_operator_div(acl_context_0);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////Perf_test////////////////////////////////////////////////////////
|
||||
|
||||
TEST(Operator, add)
|
||||
{
|
||||
TEST(Operator, add) {
|
||||
PERF_TEST test;
|
||||
test.Test_operator_add_perf(acl_context_0);
|
||||
}
|
||||
|
||||
TEST(Operator, sub)
|
||||
{
|
||||
TEST(Operator, sub) {
|
||||
PERF_TEST test;
|
||||
test.Test_operator_sub_perf(acl_context_0);
|
||||
}
|
||||
|
||||
TEST(Operator, div)
|
||||
{
|
||||
TEST(Operator, div) {
|
||||
PERF_TEST test;
|
||||
test.Test_operator_div_perf(acl_context_0);
|
||||
}
|
||||
|
||||
TEST(Operator, mul)
|
||||
{
|
||||
TEST(Operator, mul) {
|
||||
PERF_TEST test;
|
||||
test.Test_operator_mul_perf(acl_context_0);
|
||||
}
|
||||
|
||||
TEST(Mathfunction, abs)
|
||||
{
|
||||
TEST(Mathfunction, abs) {
|
||||
PERF_TEST test;
|
||||
test.Test_Abs(acl_context_0);
|
||||
}
|
||||
|
||||
TEST(Mathfunction, pow)
|
||||
{
|
||||
TEST(Mathfunction, pow) {
|
||||
PERF_TEST test;
|
||||
test.Test_Pow(acl_context_0);
|
||||
}
|
||||
|
||||
TEST(Mathfunction, sqrt)
|
||||
{
|
||||
TEST(Mathfunction, sqrt) {
|
||||
PERF_TEST test;
|
||||
test.Test_Sqrt(acl_context_0);
|
||||
}
|
||||
|
||||
TEST(Mathfunction, add)
|
||||
{
|
||||
TEST(Mathfunction, add) {
|
||||
PERF_TEST test;
|
||||
test.Test_Add(acl_context_0);
|
||||
}
|
||||
|
||||
TEST(Mathfunction, divide)
|
||||
{
|
||||
TEST(Mathfunction, divide) {
|
||||
PERF_TEST test;
|
||||
test.Test_Divide(acl_context_0);
|
||||
}
|
||||
|
||||
TEST(Mathfunction, exp)
|
||||
{
|
||||
TEST(Mathfunction, exp) {
|
||||
PERF_TEST test;
|
||||
test.Test_Exp(acl_context_0);
|
||||
}
|
||||
|
||||
TEST(Mathfunction, log)
|
||||
{
|
||||
TEST(Mathfunction, log) {
|
||||
PERF_TEST test;
|
||||
test.Test_Log(acl_context_0);
|
||||
}
|
||||
|
||||
TEST(Mathfunction, max)
|
||||
{
|
||||
TEST(Mathfunction, max) {
|
||||
PERF_TEST test;
|
||||
test.Test_Max(acl_context_0);
|
||||
}
|
||||
|
||||
TEST(Mathfunction, min)
|
||||
{
|
||||
TEST(Mathfunction, min) {
|
||||
PERF_TEST test;
|
||||
test.Test_Min(acl_context_0);
|
||||
}
|
||||
|
||||
TEST(Gemm, MatMul)
|
||||
{
|
||||
TEST(Gemm, MatMul) {
|
||||
PERF_TEST test;
|
||||
test.Test_MatMul(acl_context_0);
|
||||
}
|
||||
|
||||
TEST(Gemm, Convolution)
|
||||
{
|
||||
TEST(Gemm, Convolution) {
|
||||
PERF_TEST test;
|
||||
test.Test_Convolution(acl_context_0);
|
||||
}
|
||||
|
||||
TEST(Matrices, merge)
|
||||
{
|
||||
TEST(Matrices, merge) {
|
||||
PERF_TEST test;
|
||||
test.Test_Merge(acl_context_0);
|
||||
}
|
||||
|
||||
TEST(Matrices, split)
|
||||
{
|
||||
TEST(Matrices, split) {
|
||||
PERF_TEST test;
|
||||
test.Test_Split(acl_context_0);
|
||||
}
|
||||
|
||||
|
||||
TEST(Matrices, transpose)
|
||||
{
|
||||
TEST(Matrices, transpose) {
|
||||
PERF_TEST test;
|
||||
test.Test_Transpose(acl_context_0);
|
||||
}
|
||||
|
||||
TEST(Matrices, flip)
|
||||
{
|
||||
TEST(Matrices, flip) {
|
||||
PERF_TEST test;
|
||||
test.Test_Flip(acl_context_0);
|
||||
release_device(acl_context_0);
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
} // namespace opencv_test
|
@@ -1,2 +1 @@
|
||||
{
|
||||
}
|
||||
{}
|
@@ -1,9 +1,13 @@
|
||||
#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)
|
||||
{
|
||||
void PERF_TEST::Test_operator_add_perf(aclCxt *acl_context) {
|
||||
int val, n;
|
||||
int valmax = 8192;
|
||||
int cycle_index = 10;
|
||||
@@ -11,11 +15,9 @@ void PERF_TEST::Test_operator_add_perf(aclCxt *acl_context)
|
||||
Common_Test test;
|
||||
|
||||
vector<int> type{CV_8UC1, CV_32FC1, CV_32SC1, CV_64FC1};
|
||||
for (size_t i = 0; i < type.size(); ++i)
|
||||
{
|
||||
for (size_t i = 0; i < type.size(); ++i) {
|
||||
test.PrintLog("Perf test : Function: operator+=()", type[i]);
|
||||
for (val = 8; val <= valmax; val *= 2)
|
||||
{
|
||||
for (val = 8; val <= valmax; val *= 2) {
|
||||
n = cycle_index;
|
||||
Mat mat_src(val, val, type[i]);
|
||||
Mat mat_dest(val, val, type[i]);
|
||||
@@ -28,8 +30,7 @@ void PERF_TEST::Test_operator_add_perf(aclCxt *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;
|
||||
while (n--) mat_dest += mat_src;
|
||||
end = static_cast<double>(getTickCount());
|
||||
time = (end - begin) / getTickFrequency() / cycle_index;
|
||||
|
||||
@@ -37,8 +38,7 @@ void PERF_TEST::Test_operator_add_perf(aclCxt *acl_context)
|
||||
aclmat_dest += aclmat_src;
|
||||
wait_stream(acl_context);
|
||||
begin = static_cast<double>(getTickCount());
|
||||
while (n--)
|
||||
aclmat_dest += aclmat_src;
|
||||
while (n--) aclmat_dest += aclmat_src;
|
||||
wait_stream(acl_context);
|
||||
end = static_cast<double>(getTickCount());
|
||||
acltime = (end - begin) / getTickFrequency() / (cycle_index - 1);
|
||||
@@ -50,13 +50,13 @@ void PERF_TEST::Test_operator_add_perf(aclCxt *acl_context)
|
||||
cout << "Shape: " << val << " x " << val << "\t\t";
|
||||
else
|
||||
cout << "Shape: " << val << " x " << val << "\t";
|
||||
cout << "CpuTimes: " << time << "\tAclTimes: " << acltime << "\tRate: " << time / acltime << endl;
|
||||
cout << "CpuTimes: " << time << "\tAclTimes: " << acltime
|
||||
<< "\tRate: " << time / acltime << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PERF_TEST::Test_operator_sub_perf(aclCxt *acl_context)
|
||||
{
|
||||
void PERF_TEST::Test_operator_sub_perf(aclCxt *acl_context) {
|
||||
int val, n;
|
||||
int valmax = 8192;
|
||||
int cycle_index = 10;
|
||||
@@ -65,11 +65,9 @@ void PERF_TEST::Test_operator_sub_perf(aclCxt *acl_context)
|
||||
|
||||
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)
|
||||
{
|
||||
for (size_t i = 0; i < type.size(); ++i) {
|
||||
test.PrintLog("Perf test : Function: operator-=()", type[i]);
|
||||
for (val = 8; val <= valmax; val *= 2)
|
||||
{
|
||||
for (val = 8; val <= valmax; val *= 2) {
|
||||
n = cycle_index;
|
||||
Mat mat_src(val, val, type[i]);
|
||||
Mat mat_dest(val, val, type[i]);
|
||||
@@ -82,8 +80,7 @@ void PERF_TEST::Test_operator_sub_perf(aclCxt *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;
|
||||
while (n--) mat_dest -= mat_src;
|
||||
end = static_cast<double>(getTickCount());
|
||||
time = (end - begin) / getTickFrequency() / cycle_index;
|
||||
|
||||
@@ -91,8 +88,7 @@ void PERF_TEST::Test_operator_sub_perf(aclCxt *acl_context)
|
||||
aclmat_dest -= aclmat_src;
|
||||
wait_stream(acl_context);
|
||||
begin = static_cast<double>(getTickCount());
|
||||
while (n--)
|
||||
aclmat_dest -= aclmat_src;
|
||||
while (n--) aclmat_dest -= aclmat_src;
|
||||
wait_stream(acl_context);
|
||||
end = static_cast<double>(getTickCount());
|
||||
acltime = (end - begin) / getTickFrequency() / (cycle_index - 1);
|
||||
@@ -104,14 +100,13 @@ void PERF_TEST::Test_operator_sub_perf(aclCxt *acl_context)
|
||||
cout << "Shape: " << val << " x " << val << "\t\t";
|
||||
else
|
||||
cout << "Shape: " << val << " x " << val << "\t";
|
||||
cout << "CpuTimes: " << time << "\tAclTimes: " << acltime << "\tRate: " << time / acltime << endl;
|
||||
cout << "CpuTimes: " << time << "\tAclTimes: " << acltime
|
||||
<< "\tRate: " << time / acltime << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void PERF_TEST::Test_operator_div_perf(aclCxt *acl_context)
|
||||
{
|
||||
void PERF_TEST::Test_operator_div_perf(aclCxt *acl_context) {
|
||||
int val, n;
|
||||
int valmax = 8192;
|
||||
int cycle_index = 10;
|
||||
@@ -120,11 +115,9 @@ void PERF_TEST::Test_operator_div_perf(aclCxt *acl_context)
|
||||
|
||||
// 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 (size_t i = 0; i < type.size(); ++i) {
|
||||
test.PrintLog("Perf test : Function: operator/=()", type[i]);
|
||||
for (val = 8; val <= valmax; val *= 2)
|
||||
{
|
||||
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));
|
||||
@@ -134,8 +127,7 @@ void PERF_TEST::Test_operator_div_perf(aclCxt *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;
|
||||
while (n--) mat_dest /= mat_src;
|
||||
end = static_cast<double>(getTickCount());
|
||||
time = (end - begin) / getTickFrequency() / cycle_index;
|
||||
|
||||
@@ -143,8 +135,7 @@ void PERF_TEST::Test_operator_div_perf(aclCxt *acl_context)
|
||||
aclmat_dest /= aclmat_src;
|
||||
wait_stream(acl_context);
|
||||
begin = static_cast<double>(getTickCount());
|
||||
while (n--)
|
||||
aclmat_dest /= aclmat_src;
|
||||
while (n--) aclmat_dest /= aclmat_src;
|
||||
wait_stream(acl_context);
|
||||
end = static_cast<double>(getTickCount());
|
||||
acltime = (end - begin) / getTickFrequency() / (cycle_index - 1);
|
||||
@@ -156,14 +147,13 @@ void PERF_TEST::Test_operator_div_perf(aclCxt *acl_context)
|
||||
cout << "Shape: " << val << " x " << val << "\t\t";
|
||||
else
|
||||
cout << "Shape: " << val << " x " << val << "\t";
|
||||
cout << "CpuTimes: " << time << "\tAclTimes: " << acltime << "\tRate: " << time / acltime << endl;
|
||||
cout << "CpuTimes: " << time << "\tAclTimes: " << acltime
|
||||
<< "\tRate: " << time / acltime << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void PERF_TEST::Test_operator_mul_perf(aclCxt *acl_context)
|
||||
{
|
||||
void PERF_TEST::Test_operator_mul_perf(aclCxt *acl_context) {
|
||||
int val, n;
|
||||
int valmax = 4096;
|
||||
int cycle_index = 10;
|
||||
@@ -171,10 +161,8 @@ void PERF_TEST::Test_operator_mul_perf(aclCxt *acl_context)
|
||||
Common_Test test;
|
||||
vector<int> type{CV_32FC1};
|
||||
|
||||
for (size_t i = 0; i < type.size(); ++i)
|
||||
{
|
||||
for (val = 8; val <= valmax; val *= 2)
|
||||
{
|
||||
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]);
|
||||
@@ -187,8 +175,7 @@ void PERF_TEST::Test_operator_mul_perf(aclCxt *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;
|
||||
while (n--) mat_dest *= mat_src;
|
||||
end = static_cast<double>(getTickCount());
|
||||
time = (end - begin) / getTickFrequency() / cycle_index;
|
||||
|
||||
@@ -196,8 +183,7 @@ void PERF_TEST::Test_operator_mul_perf(aclCxt *acl_context)
|
||||
aclmat_dest *= aclmat_src;
|
||||
wait_stream(acl_context);
|
||||
begin = static_cast<double>(getTickCount());
|
||||
while (n--)
|
||||
aclmat_dest *= aclmat_src;
|
||||
while (n--) aclmat_dest *= aclmat_src;
|
||||
wait_stream(acl_context);
|
||||
end = static_cast<double>(getTickCount());
|
||||
acltime = (end - begin) / getTickFrequency() / (cycle_index - 1);
|
||||
@@ -209,8 +195,8 @@ void PERF_TEST::Test_operator_mul_perf(aclCxt *acl_context)
|
||||
cout << "Shape: " << val << " x " << val << "\t\t";
|
||||
else
|
||||
cout << "Shape: " << val << " x " << val << "\t";
|
||||
cout << "CpuTimes: " << time << "\tAclTimes: " << acltime << "\tRate: " << time / acltime << endl;
|
||||
cout << "CpuTimes: " << time << "\tAclTimes: " << acltime
|
||||
<< "\tRate: " << time / acltime << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,18 +1,20 @@
|
||||
#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() {
|
||||
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 Common_Test::Test_Diff(const aclMat &aclmat, const Mat &mat,
|
||||
ALIGNMENT config) {
|
||||
bool is_correct;
|
||||
|
||||
if (config == ALIGNMENT::MEMORY_UNALIGNED)
|
||||
{
|
||||
if (config == ALIGNMENT::MEMORY_UNALIGNED) {
|
||||
is_correct = (aclmat.rows == mat.rows);
|
||||
is_correct &= (aclmat.cols == mat.cols);
|
||||
is_correct &= (aclmat.channels() == mat.channels());
|
||||
@@ -20,14 +22,13 @@ bool Common_Test::Test_Diff(const aclMat& aclmat, const Mat& mat, ALIGNMENT conf
|
||||
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));
|
||||
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
|
||||
{
|
||||
} else {
|
||||
is_correct = (aclmat.rows == mat.rows);
|
||||
is_correct &= (aclmat.cols == mat.cols);
|
||||
is_correct &= (aclmat.channels() == mat.channels());
|
||||
@@ -63,8 +64,7 @@ bool Common_Test::Test_Diff(const aclMat& aclmat, const aclMat& aclmat_other) {
|
||||
return is_correct;
|
||||
}
|
||||
|
||||
bool Common_Test::Test_Diff(const Mat &mat, const Mat &mat_other)
|
||||
{
|
||||
bool Common_Test::Test_Diff(const Mat &mat, const Mat &mat_other) {
|
||||
bool is_correct;
|
||||
|
||||
is_correct = (mat.rows == mat_other.rows);
|
||||
@@ -75,86 +75,101 @@ bool Common_Test::Test_Diff(const Mat &mat, const Mat &mat_other)
|
||||
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 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 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]);
|
||||
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 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]);
|
||||
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 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));
|
||||
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 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));
|
||||
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)
|
||||
{
|
||||
void Common_Test::MatShow(cv::Mat &m, string str) {
|
||||
cout << str.c_str() << endl;
|
||||
cout << m;
|
||||
cout << endl
|
||||
<< endl
|
||||
<< endl;
|
||||
cout << endl << endl << endl;
|
||||
}
|
||||
|
||||
void Common_Test::StatShow(cv::Mat &mat_src, aclMat &aclmat_dst)
|
||||
{
|
||||
cout << "//////////////////////////////// MatStat ////////////////////////////////" << 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.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 << "dataend - datastart: " << mat_src.dataend - mat_src.datastart
|
||||
<< endl;
|
||||
|
||||
cout << "//////////////////////////////// aclMatStat ////////////////////////////////" << 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 << "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;
|
||||
@@ -261,41 +276,39 @@ size_t Common_Test::RandDom_(int 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 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 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 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 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 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;
|
||||
}
|
||||
|
@@ -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);
|
||||
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 bool SetDataRange(cv::Mat& src, int dataRange = 0xff);
|
||||
};
|
||||
|
||||
|
||||
#endif
|
@@ -1,73 +1,80 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////
|
||||
/* M/////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// 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.
|
||||
// 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.
|
||||
//
|
||||
//
|
||||
// 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, 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.
|
||||
// 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,
|
||||
// are permitted provided that the following conditions are met:
|
||||
// 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
|
||||
// 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,
|
||||
// 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
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// 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.
|
||||
// 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, 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 and on any theory of liability, whether in
|
||||
// contract, strict liability, 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*/
|
||||
|
||||
|
||||
|
||||
#include "test_common.hpp"
|
||||
#include "test_correctness.hpp"
|
||||
|
||||
AclMat_Test::AclMat_Test() {
|
||||
#include "test_common.hpp"
|
||||
|
||||
}
|
||||
using namespace cv;
|
||||
using namespace cv::acl;
|
||||
using namespace cvtest;
|
||||
using namespace testing;
|
||||
using namespace std;
|
||||
|
||||
AclMat_Test::~AclMat_Test() {
|
||||
AclMat_Test::AclMat_Test() {}
|
||||
|
||||
}
|
||||
AclMat_Test::~AclMat_Test() {}
|
||||
|
||||
/* thread function */
|
||||
void thread_handler(void) {
|
||||
aclCxt *acl_context_0 = set_device("/home/perfxlab4/OpenCV_ACL/modules/acl/test/acl.json", 0, 1);
|
||||
aclCxt *acl_context_0 =
|
||||
set_device("/home/perfxlab4/OpenCV_ACL/modules/acl/test/acl.json", 0, 1);
|
||||
release_device(acl_context_0);
|
||||
}
|
||||
|
||||
void AclMat_Test::Test_set_device() {
|
||||
/* Current thread */
|
||||
aclCxt *acl_context_0 = set_device("/home/perfxlab4/OpenCV_ACL/modules/acl/test/acl.json", 0, 1);
|
||||
aclCxt *acl_context_0 =
|
||||
set_device("/home/perfxlab4/OpenCV_ACL/modules/acl/test/acl.json", 0, 1);
|
||||
|
||||
/* Different scope */
|
||||
{
|
||||
aclCxt *acl_context_1 = set_device("/home/perfxlab4/OpenCV_ACL/modules/acl/test/acl.json", 2, 3);
|
||||
aclCxt *acl_context_1 = set_device(
|
||||
"/home/perfxlab4/OpenCV_ACL/modules/acl/test/acl.json", 2, 3);
|
||||
release_device(acl_context_1);
|
||||
}
|
||||
|
||||
@@ -97,7 +104,9 @@ void AclMat_Test::Test_constructor_UNALIGNED(aclCxt *acl_context) {
|
||||
}
|
||||
}
|
||||
}
|
||||
clog << "Test_constructor_UNALIGNED: -> aclMat(rows, cols, type, acl_context, config, policy) <- is success" << endl;
|
||||
clog << "Test_constructor_UNALIGNED: -> aclMat(rows, cols, type, "
|
||||
"acl_context, config, policy) <- is success"
|
||||
<< endl;
|
||||
|
||||
for (type = 0; type < typeMax; type++) {
|
||||
for (rows = 1; rows < rowsMax; rows++) {
|
||||
@@ -111,7 +120,9 @@ void AclMat_Test::Test_constructor_UNALIGNED(aclCxt *acl_context) {
|
||||
}
|
||||
}
|
||||
}
|
||||
clog << "Test_constructor_UNALIGNED: -> aclMat(size, type, acl_context, config, policy) <- is success" << endl;
|
||||
clog << "Test_constructor_UNALIGNED: -> aclMat(size, type, acl_context, "
|
||||
"config, policy) <- is success"
|
||||
<< endl;
|
||||
}
|
||||
|
||||
void AclMat_Test::Test_constructor_ALIGN(aclCxt *acl_context) {
|
||||
@@ -134,23 +145,26 @@ void AclMat_Test::Test_constructor_ALIGN(aclCxt *acl_context) {
|
||||
}
|
||||
}
|
||||
}
|
||||
clog << "Test_constructor_ALIGN: -> aclMat(rows, cols, type, acl_context, config, policy) <- is success" << endl;
|
||||
clog << "Test_constructor_ALIGN: -> aclMat(rows, cols, type, acl_context, "
|
||||
"config, policy) <- is success"
|
||||
<< endl;
|
||||
|
||||
for (type = 0; type < typeMax; type++) {
|
||||
for (rows = 1; rows < rowsMax; rows++) {
|
||||
for (cols = 1; cols < colsMax; cols++) {
|
||||
Mat mat_src(cv::Size(cols, rows), type);
|
||||
test.SetDataRange(mat_src, 32);
|
||||
aclMat aclmat_src(cv::Size(cols, rows), type, acl_context, MEMORY_ALIGN);
|
||||
aclMat aclmat_src(cv::Size(cols, rows), type, acl_context,
|
||||
MEMORY_ALIGN);
|
||||
aclmat_src.upload(mat_src, MEMORY_ALIGN);
|
||||
ret = test.Test_Diff(aclmat_src, mat_src, MEMORY_ALIGN);
|
||||
ASSERT_TRUE(ret);
|
||||
}
|
||||
}
|
||||
}
|
||||
clog << "Test_constructor_ALIGN: -> aclMat(size, type, acl_context, config, policy) <- is success" << endl;
|
||||
|
||||
|
||||
clog << "Test_constructor_ALIGN: -> aclMat(size, type, acl_context, config, "
|
||||
"policy) <- is success"
|
||||
<< endl;
|
||||
}
|
||||
|
||||
void AclMat_Test::Test_constructor(aclCxt *acl_context_0) {
|
||||
@@ -176,14 +190,16 @@ void AclMat_Test::Test_constructor(aclCxt *acl_context_0) {
|
||||
for (type = 0; type < typeMax; type++) {
|
||||
for (rows = 1; rows < rowsMax; rows++) {
|
||||
for (cols = 1; cols < colsMax; cols++) {
|
||||
aclMat aclmat_src(cv::Size(cols, rows), type, acl_context_0, MEMORY_ALIGN);
|
||||
aclMat aclmat_src(cv::Size(cols, rows), type, acl_context_0,
|
||||
MEMORY_ALIGN);
|
||||
aclMat aclmat_dest(aclmat_src);
|
||||
ret = test.Test_Diff(aclmat_src, aclmat_dest);
|
||||
ASSERT_TRUE(ret);
|
||||
}
|
||||
}
|
||||
}
|
||||
clog << "Test_constructor: -> aclMat(const aclMat& other) <- is success" << endl;
|
||||
clog << "Test_constructor: -> aclMat(const aclMat& other) <- is success"
|
||||
<< endl;
|
||||
}
|
||||
|
||||
void AclMat_Test::Test_constructor_DATA(aclCxt *acl_context_0) {
|
||||
@@ -208,7 +224,9 @@ void AclMat_Test::Test_constructor_DATA(aclCxt *acl_context_0) {
|
||||
}
|
||||
}
|
||||
}
|
||||
cerr << "Test_constructor_DATA: -> aclMat(rows, cols, type, data, acl_context)) <- is success" << endl;
|
||||
cerr << "Test_constructor_DATA: -> aclMat(rows, cols, type, data, "
|
||||
"acl_context)) <- is success"
|
||||
<< endl;
|
||||
|
||||
for (type = 0; type < typeMax; type++) {
|
||||
for (rows = 1; rows < rowsMax; rows++) {
|
||||
@@ -217,7 +235,8 @@ void AclMat_Test::Test_constructor_DATA(aclCxt *acl_context_0) {
|
||||
Mat mat_dest(cv::Size(cols, rows), type);
|
||||
test.SetDataRange(mat_src);
|
||||
|
||||
aclMat aclmat_src(cv::Size(cols, rows), type, mat_src.data, acl_context_0);
|
||||
aclMat aclmat_src(cv::Size(cols, rows), type, mat_src.data,
|
||||
acl_context_0);
|
||||
aclmat_src.download(mat_dest);
|
||||
ret = test.Test_Diff(mat_src, mat_dest);
|
||||
ASSERT_TRUE(ret);
|
||||
@@ -225,7 +244,9 @@ void AclMat_Test::Test_constructor_DATA(aclCxt *acl_context_0) {
|
||||
}
|
||||
}
|
||||
|
||||
cerr << "Test_constructor_DATA: -> aclMat(size, type, data, acl_context)) <- is success" << endl;
|
||||
cerr << "Test_constructor_DATA: -> aclMat(size, type, data, acl_context)) <- "
|
||||
"is success"
|
||||
<< endl;
|
||||
}
|
||||
|
||||
void AclMat_Test::Test_constructor_RANGE(aclCxt *acl_context_0) {
|
||||
@@ -246,18 +267,22 @@ void AclMat_Test::Test_constructor_RANGE(aclCxt *acl_context_0) {
|
||||
test.SetDataRange(mat_src);
|
||||
test.SetDataRange(mat_dest);
|
||||
|
||||
Mat mat_rangesrc(mat_src, cv::Range(2, rangerows), cv::Range(2, rangecols));
|
||||
Mat mat_rangedest(mat_dest, cv::Range(2, rangerows), cv::Range(2, rangecols));
|
||||
Mat mat_rangesrc(mat_src, cv::Range(2, rangerows),
|
||||
cv::Range(2, rangecols));
|
||||
Mat mat_rangedest(mat_dest, cv::Range(2, rangerows),
|
||||
cv::Range(2, rangecols));
|
||||
aclMat aclmat_src(rows, cols, type, mat_src.data, acl_context_0);
|
||||
aclMat aclmat_range(aclmat_src, cv::Range(2, rangerows), cv::Range(2, rangecols));
|
||||
aclMat aclmat_range(aclmat_src, cv::Range(2, rangerows),
|
||||
cv::Range(2, rangecols));
|
||||
aclmat_range.download(mat_rangedest);
|
||||
ret = test.Test_Diff(mat_rangesrc, mat_rangedest);
|
||||
ASSERT_TRUE(ret);
|
||||
}
|
||||
}
|
||||
}
|
||||
clog << "Test_constructor_RANGE: -> aclMat(aclmat_src, rowragne, colrange)) <- is success" << endl;
|
||||
|
||||
clog << "Test_constructor_RANGE: -> aclMat(aclmat_src, rowragne, colrange)) "
|
||||
"<- is success"
|
||||
<< endl;
|
||||
}
|
||||
|
||||
void AclMat_Test::Test_constructor_ROI(aclCxt *acl_context_0) {
|
||||
@@ -325,7 +350,8 @@ void AclMat_Test::Test_constructor_ROI(aclCxt *acl_context_0) {
|
||||
ASSERT_TRUE(ret);
|
||||
}
|
||||
|
||||
clog << "Test_constructor_ROI: -> aclMat(aclmat_src, roi)) <- is success" << endl;
|
||||
clog << "Test_constructor_ROI: -> aclMat(aclmat_src, roi)) <- is success"
|
||||
<< endl;
|
||||
}
|
||||
|
||||
void AclMat_Test::Test_constructor_MAT(aclCxt *acl_context_0) {
|
||||
@@ -350,8 +376,9 @@ void AclMat_Test::Test_constructor_MAT(aclCxt *acl_context_0) {
|
||||
}
|
||||
}
|
||||
}
|
||||
clog << "Test_constructor_MAT: -> aclMat(mat_src, acl_context_0)) <- is success" << endl;
|
||||
|
||||
clog << "Test_constructor_MAT: -> aclMat(mat_src, acl_context_0)) <- is "
|
||||
"success"
|
||||
<< endl;
|
||||
}
|
||||
|
||||
void AclMat_Test::Test_DATA_TRANSFER(aclCxt *acl_context_0) {
|
||||
@@ -362,12 +389,9 @@ void AclMat_Test::Test_DATA_TRANSFER(aclCxt *acl_context_0) {
|
||||
const int colsMax = 1048;
|
||||
const int typeMax = 7;
|
||||
|
||||
for (type = 0; type < typeMax; type++)
|
||||
{
|
||||
for (rows = 1000; rows < rowsMax; rows++)
|
||||
{
|
||||
for (cols = 1000; cols < colsMax; cols++)
|
||||
{
|
||||
for (type = 0; type < typeMax; type++) {
|
||||
for (rows = 1000; rows < rowsMax; rows++) {
|
||||
for (cols = 1000; cols < colsMax; cols++) {
|
||||
Mat mat_src(rows, cols, type);
|
||||
Mat mat_dest(rows, cols, type);
|
||||
|
||||
@@ -382,14 +406,12 @@ void AclMat_Test::Test_DATA_TRANSFER(aclCxt *acl_context_0) {
|
||||
}
|
||||
}
|
||||
}
|
||||
clog << "Test_DATA_TRANSFER_UNALIGNED: -> upload(), download() <- is success" << endl;
|
||||
clog << "Test_DATA_TRANSFER_UNALIGNED: -> upload(), download() <- is success"
|
||||
<< endl;
|
||||
|
||||
for (type = 0; type < typeMax; type++)
|
||||
{
|
||||
for (rows = 1000; rows < rowsMax; rows++)
|
||||
{
|
||||
for (cols = 1000; cols < colsMax; cols++)
|
||||
{
|
||||
for (type = 0; type < typeMax; type++) {
|
||||
for (rows = 1000; rows < rowsMax; rows++) {
|
||||
for (cols = 1000; cols < colsMax; cols++) {
|
||||
Mat mat_src(rows, cols, type);
|
||||
Mat mat_dest(rows, cols, type);
|
||||
|
||||
@@ -404,7 +426,8 @@ void AclMat_Test::Test_DATA_TRANSFER(aclCxt *acl_context_0) {
|
||||
}
|
||||
}
|
||||
}
|
||||
clog << "Test_DATA_TRANSFER_ALIGN: -> upload(), download() <- is success" << endl;
|
||||
clog << "Test_DATA_TRANSFER_ALIGN: -> upload(), download() <- is success"
|
||||
<< endl;
|
||||
}
|
||||
|
||||
void AclMat_Test::Test_DATA_TRANSFERASYNC(aclCxt *acl_context_0) {
|
||||
@@ -415,12 +438,9 @@ void AclMat_Test::Test_DATA_TRANSFERASYNC(aclCxt *acl_context_0) {
|
||||
const int colsMax = 1048;
|
||||
const int typeMax = 7;
|
||||
|
||||
for (type = 0; type < typeMax; type++)
|
||||
{
|
||||
for (rows = 1000; rows < rowsMax; rows++)
|
||||
{
|
||||
for (cols = 1000; cols < colsMax; cols++)
|
||||
{
|
||||
for (type = 0; type < typeMax; type++) {
|
||||
for (rows = 1000; rows < rowsMax; rows++) {
|
||||
for (cols = 1000; cols < colsMax; cols++) {
|
||||
Mat mat_src(rows, cols, type);
|
||||
Mat mat_dest(rows, cols, type);
|
||||
|
||||
@@ -435,14 +455,13 @@ void AclMat_Test::Test_DATA_TRANSFERASYNC(aclCxt *acl_context_0) {
|
||||
}
|
||||
}
|
||||
}
|
||||
clog << "Test_DATA_TRANSFERASYNC_UNALIGNED: -> upload(), download() <- is success" << endl;
|
||||
clog << "Test_DATA_TRANSFERASYNC_UNALIGNED: -> upload(), download() <- is "
|
||||
"success"
|
||||
<< endl;
|
||||
|
||||
for (type = 0; type < typeMax; type++)
|
||||
{
|
||||
for (rows = 1000; rows < rowsMax; rows++)
|
||||
{
|
||||
for (cols = 1000; cols < colsMax; cols++)
|
||||
{
|
||||
for (type = 0; type < typeMax; type++) {
|
||||
for (rows = 1000; rows < rowsMax; rows++) {
|
||||
for (cols = 1000; cols < colsMax; cols++) {
|
||||
Mat mat_src(rows, cols, type);
|
||||
Mat mat_dest(rows, cols, type);
|
||||
|
||||
@@ -450,15 +469,17 @@ void AclMat_Test::Test_DATA_TRANSFERASYNC(aclCxt *acl_context_0) {
|
||||
test.SetDataRange(mat_dest);
|
||||
|
||||
aclMat aclmat_src(rows, cols, type, acl_context_0, MEMORY_ALIGN);
|
||||
aclmat_src.upload(mat_src, aclmat_src.acl_context->get_stream(0), MEMORY_ALIGN);
|
||||
aclmat_src.download(mat_dest, aclmat_src.acl_context->get_stream(0), MEMORY_ALIGN);
|
||||
aclmat_src.upload(mat_src, aclmat_src.acl_context->get_stream(0),
|
||||
MEMORY_ALIGN);
|
||||
aclmat_src.download(mat_dest, aclmat_src.acl_context->get_stream(0),
|
||||
MEMORY_ALIGN);
|
||||
ret = test.Test_Diff(mat_src, mat_dest);
|
||||
ASSERT_TRUE(ret);
|
||||
}
|
||||
}
|
||||
}
|
||||
clog << "Test_DATA_TRANSFERASYNC_ALIGN: -> upload(), download() <- is success" << endl;
|
||||
|
||||
clog << "Test_DATA_TRANSFERASYNC_ALIGN: -> upload(), download() <- is success"
|
||||
<< endl;
|
||||
}
|
||||
|
||||
static inline void dataSwap(int &data1, int &data2) {
|
||||
@@ -480,8 +501,7 @@ void AclMat_Test::Test_locateROI(aclCxt *acl_context_0) {
|
||||
cv::Size size, size1;
|
||||
cv::Point ofs, ofs1;
|
||||
|
||||
for (int x = 0; x < rows * cols; ++x)
|
||||
{
|
||||
for (int x = 0; x < rows * cols; ++x) {
|
||||
rangex = (rangex = test.RandDom_()) > 0 ? rangex : 1;
|
||||
rangey = (rangey = test.RandDom_()) > 0 ? rangey : 1;
|
||||
rangex1 = (rangex1 = test.RandDom_()) > 0 ? rangex1 : 1;
|
||||
@@ -491,11 +511,13 @@ void AclMat_Test::Test_locateROI(aclCxt *acl_context_0) {
|
||||
dataSwap(rangey, rangey1);
|
||||
|
||||
Mat mat_src(rows, cols, type);
|
||||
Mat mat_range(mat_src, cv::Range(rangex1, rangex+1), cv::Range(rangey1, rangey+1));
|
||||
Mat mat_range(mat_src, cv::Range(rangex1, rangex + 1),
|
||||
cv::Range(rangey1, rangey + 1));
|
||||
mat_range.locateROI(size, ofs);
|
||||
|
||||
aclMat aclmat_src(rows, cols, type, acl_context_0);
|
||||
aclMat aclmat_range(aclmat_src, cv::Range(rangex1, rangex+1), cv::Range(rangey1, rangey+1));
|
||||
aclMat aclmat_range(aclmat_src, cv::Range(rangex1, rangex + 1),
|
||||
cv::Range(rangey1, rangey + 1));
|
||||
aclmat_range.locateROI(size1, ofs1);
|
||||
|
||||
ASSERT_EQ(size.height, size1.height);
|
||||
@@ -504,7 +526,6 @@ void AclMat_Test::Test_locateROI(aclCxt *acl_context_0) {
|
||||
ASSERT_EQ(ofs.y, ofs1.y);
|
||||
}
|
||||
clog << "Test_loacteROI: -> locateROI() <- is success" << endl;
|
||||
|
||||
}
|
||||
|
||||
void AclMat_Test::Test_swap(aclCxt *acl_context_0) {
|
||||
@@ -515,12 +536,9 @@ void AclMat_Test::Test_swap(aclCxt *acl_context_0) {
|
||||
const int colsMax = 1048;
|
||||
const int typeMax = 7;
|
||||
|
||||
for (type = 0; type < typeMax; type++)
|
||||
{
|
||||
for (rows = 1024; rows < rowsMax; rows++)
|
||||
{
|
||||
for (cols = 1024; cols < colsMax; cols++)
|
||||
{
|
||||
for (type = 0; type < typeMax; type++) {
|
||||
for (rows = 1024; rows < rowsMax; rows++) {
|
||||
for (cols = 1024; cols < colsMax; cols++) {
|
||||
Mat mat_src(rows, cols, type);
|
||||
Mat mat_dest(rows, cols, type);
|
||||
|
||||
@@ -556,13 +574,10 @@ void AclMat_Test::Test_operator_add(aclCxt *acl_context) {
|
||||
const int colsMax = 1048;
|
||||
|
||||
vector<int> type{CV_8UC1, CV_8UC3, CV_32FC1, CV_32FC3, CV_32SC1, CV_32SC3};
|
||||
for (size_t i = 0; i < type.size(); ++i)
|
||||
{
|
||||
for (size_t i = 0; i < type.size(); ++i) {
|
||||
test.PrintLog("Correctness test: Functoin: operator+=()", type[i]);
|
||||
for (rows = 1024; rows < rowsMax; rows++)
|
||||
{
|
||||
for (cols = 1024; cols < colsMax; cols++)
|
||||
{
|
||||
for (rows = 1024; rows < rowsMax; rows++) {
|
||||
for (cols = 1024; cols < colsMax; cols++) {
|
||||
Mat mat_src(rows, cols, type[i]);
|
||||
Mat mat_dest(rows, cols, type[i]);
|
||||
Mat mat_dest1(rows, cols, type[i]);
|
||||
@@ -570,8 +585,10 @@ void AclMat_Test::Test_operator_add(aclCxt *acl_context) {
|
||||
test.SetDataRange(mat_src, 32);
|
||||
test.SetDataRange(mat_dest, 32);
|
||||
|
||||
aclMat aclmat_src(rows, cols, type[i], mat_src.data, acl_context, MEMORY_ALIGN);
|
||||
aclMat aclmat_dest(rows, cols, type[i], mat_dest.data, acl_context, MEMORY_ALIGN);
|
||||
aclMat aclmat_src(rows, cols, type[i], mat_src.data, acl_context,
|
||||
MEMORY_ALIGN);
|
||||
aclMat aclmat_dest(rows, cols, type[i], mat_dest.data, acl_context,
|
||||
MEMORY_ALIGN);
|
||||
|
||||
mat_dest += mat_src;
|
||||
|
||||
@@ -584,7 +601,6 @@ void AclMat_Test::Test_operator_add(aclCxt *acl_context) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void AclMat_Test::Test_operator_sub(aclCxt *acl_context) {
|
||||
@@ -594,20 +610,20 @@ void AclMat_Test::Test_operator_sub(aclCxt *acl_context) {
|
||||
const int rowsMax = 1048;
|
||||
const int colsMax = 1048;
|
||||
|
||||
vector<int> type{CV_8UC1, CV_8UC3, CV_32FC1, CV_32FC3, CV_32SC1, CV_32SC3, CV_64FC1};
|
||||
for (size_t i = 0; i < type.size(); ++i)
|
||||
{
|
||||
vector<int> type{CV_8UC1, CV_8UC3, CV_32FC1, CV_32FC3,
|
||||
CV_32SC1, CV_32SC3, CV_64FC1};
|
||||
for (size_t i = 0; i < type.size(); ++i) {
|
||||
test.PrintLog("Correctness test: Functoin: operator-=()", type[i]);
|
||||
for (rows = 1024; rows < rowsMax; rows++)
|
||||
{
|
||||
for (cols = 1024; cols < colsMax; cols++)
|
||||
{
|
||||
for (rows = 1024; rows < rowsMax; rows++) {
|
||||
for (cols = 1024; cols < colsMax; cols++) {
|
||||
Mat mat_src(rows, cols, type[i], Scalar(1, 2, 3));
|
||||
Mat mat_dest(rows, cols, type[i], Scalar(4, 6, 8));
|
||||
Mat mat_dest1(rows, cols, type[i]);
|
||||
|
||||
aclMat aclmat_src(rows, cols, type[i], mat_src.data, acl_context, MEMORY_ALIGN);
|
||||
aclMat aclmat_dest(rows, cols, type[i], mat_dest.data, acl_context, MEMORY_ALIGN);
|
||||
aclMat aclmat_src(rows, cols, type[i], mat_src.data, acl_context,
|
||||
MEMORY_ALIGN);
|
||||
aclMat aclmat_dest(rows, cols, type[i], mat_dest.data, acl_context,
|
||||
MEMORY_ALIGN);
|
||||
|
||||
mat_dest -= mat_src;
|
||||
|
||||
@@ -620,7 +636,6 @@ void AclMat_Test::Test_operator_sub(aclCxt *acl_context) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void AclMat_Test::Test_operator_div(aclCxt *acl_context) {
|
||||
@@ -630,20 +645,20 @@ void AclMat_Test::Test_operator_div(aclCxt *acl_context) {
|
||||
const int rowsMax = 1048;
|
||||
const int colsMax = 1048;
|
||||
|
||||
vector<int> type{CV_8UC1, CV_8UC3, CV_32FC1, CV_32FC3, CV_32SC1, CV_32SC3, CV_64FC1};
|
||||
for (size_t i = 0; i < type.size(); ++i)
|
||||
{
|
||||
vector<int> type{CV_8UC1, CV_8UC3, CV_32FC1, CV_32FC3,
|
||||
CV_32SC1, CV_32SC3, CV_64FC1};
|
||||
for (size_t i = 0; i < type.size(); ++i) {
|
||||
test.PrintLog("Correctness test: Functoin: operator/=()", type[i]);
|
||||
for (rows = 1024; rows < rowsMax; rows++)
|
||||
{
|
||||
for (cols = 1024; cols < colsMax; cols++)
|
||||
{
|
||||
for (rows = 1024; rows < rowsMax; rows++) {
|
||||
for (cols = 1024; cols < colsMax; cols++) {
|
||||
Mat mat_src(rows, cols, type[i], Scalar(1, 2, 4));
|
||||
Mat mat_dest(rows, cols, type[i], Scalar(4, 6, 8));
|
||||
Mat mat_dest1(rows, cols, type[i]);
|
||||
|
||||
aclMat aclmat_src(rows, cols, type[i], mat_src.data, acl_context, MEMORY_ALIGN);
|
||||
aclMat aclmat_dest(rows, cols, type[i], mat_dest.data, acl_context, MEMORY_ALIGN);
|
||||
aclMat aclmat_src(rows, cols, type[i], mat_src.data, acl_context,
|
||||
MEMORY_ALIGN);
|
||||
aclMat aclmat_dest(rows, cols, type[i], mat_dest.data, acl_context,
|
||||
MEMORY_ALIGN);
|
||||
|
||||
mat_dest /= mat_src;
|
||||
|
||||
@@ -665,11 +680,9 @@ void AclMat_Test::Test_operator_mul(aclCxt *acl_context) {
|
||||
const int valMax = 1048;
|
||||
|
||||
vector<int> type{CV_32FC1};
|
||||
for (size_t i = 0; i < type.size(); ++i)
|
||||
{
|
||||
for (size_t i = 0; i < type.size(); ++i) {
|
||||
test.PrintLog("Correctness test: Functoin: operator*=()", type[i]);
|
||||
for (val = 1024; val < valMax; val++)
|
||||
{
|
||||
for (val = 1024; val < valMax; val++) {
|
||||
Mat mat_src(val, val, type[i]);
|
||||
Mat mat_dest(val, val, type[i]);
|
||||
Mat mat_dest1(val, val, type[i]);
|
||||
@@ -690,9 +703,4 @@ void AclMat_Test::Test_operator_mul(aclCxt *acl_context) {
|
||||
ASSERT_TRUE(ret);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
@@ -2,25 +2,36 @@
|
||||
#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) */
|
||||
/* 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) */
|
||||
/* 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()) */
|
||||
/* 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) */
|
||||
/* 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);
|
||||
|
@@ -1,8 +1,13 @@
|
||||
#include "test_common.hpp"
|
||||
#include "test_perf.hpp"
|
||||
|
||||
void PERF_TEST::Test_MatMul(aclCxt *acl_context)
|
||||
{
|
||||
using namespace cv;
|
||||
using namespace cv::acl;
|
||||
using namespace cvtest;
|
||||
using namespace testing;
|
||||
using namespace std;
|
||||
|
||||
void PERF_TEST::Test_MatMul(aclCxt *acl_context) {
|
||||
int val, n;
|
||||
int valmax = 4096;
|
||||
int cycle_index = 10; // 100;
|
||||
@@ -10,10 +15,8 @@ void PERF_TEST::Test_MatMul(aclCxt *acl_context)
|
||||
Common_Test test;
|
||||
vector<int> type{CV_32FC1};
|
||||
|
||||
for (size_t i = 0; i < type.size(); ++i)
|
||||
{
|
||||
for (val = 8; val <= valmax; val *= 2)
|
||||
{
|
||||
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]);
|
||||
@@ -29,8 +32,7 @@ void PERF_TEST::Test_MatMul(aclCxt *acl_context)
|
||||
|
||||
n = cycle_index;
|
||||
begin = static_cast<double>(getTickCount());
|
||||
while (n--)
|
||||
mat_dest = mat_src * mat_src1;
|
||||
while (n--) mat_dest = mat_src * mat_src1;
|
||||
end = static_cast<double>(getTickCount());
|
||||
time = (end - begin) / getTickFrequency() / cycle_index;
|
||||
|
||||
@@ -38,8 +40,7 @@ void PERF_TEST::Test_MatMul(aclCxt *acl_context)
|
||||
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);
|
||||
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);
|
||||
@@ -51,14 +52,13 @@ void PERF_TEST::Test_MatMul(aclCxt *acl_context)
|
||||
cout << "Shape: " << val << " x " << val << "\t\t";
|
||||
else
|
||||
cout << "Shape: " << val << " x " << val << "\t";
|
||||
cout << "CpuTimes: " << time << "\tAclTimes: " << acltime << "\tRate: " << time / acltime << endl;
|
||||
cout << "CpuTimes: " << time << "\tAclTimes: " << acltime
|
||||
<< "\tRate: " << time / acltime << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void PERF_TEST::Test_Convolution(aclCxt *acl_context)
|
||||
{
|
||||
void PERF_TEST::Test_Convolution(aclCxt *acl_context) {
|
||||
int val, n;
|
||||
int valmax = 4096;
|
||||
int cycle_index = 10;
|
||||
@@ -66,10 +66,8 @@ void PERF_TEST::Test_Convolution(aclCxt *acl_context)
|
||||
Common_Test test;
|
||||
vector<int> type{CV_32FC1};
|
||||
|
||||
for (size_t i = 0; i < type.size(); ++i)
|
||||
{
|
||||
for (val = 8; val <= valmax; val *= 2)
|
||||
{
|
||||
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});
|
||||
@@ -80,8 +78,7 @@ void PERF_TEST::Test_Convolution(aclCxt *acl_context)
|
||||
|
||||
n = cycle_index;
|
||||
begin = static_cast<double>(getTickCount());
|
||||
while (n--)
|
||||
filter2D(mat_src, mat_dest, -1, mat_kernel);
|
||||
while (n--) filter2D(mat_src, mat_dest, -1, mat_kernel);
|
||||
end = static_cast<double>(getTickCount());
|
||||
time = (end - begin) / getTickFrequency() / cycle_index;
|
||||
|
||||
@@ -107,7 +104,8 @@ void PERF_TEST::Test_Convolution(aclCxt *acl_context)
|
||||
cout << "Shape: " << val << " x " << val << "\t\t";
|
||||
else
|
||||
cout << "Shape: " << val << " x " << val << "\t";
|
||||
cout << "CpuTimes: " << time << "\tAclTimes: " << acltime << "\tRate: " << time / acltime << endl;
|
||||
cout << "CpuTimes: " << time << "\tAclTimes: " << acltime
|
||||
<< "\tRate: " << time / acltime << endl;
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,6 +1,6 @@
|
||||
// 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)
|
||||
|
@@ -1,8 +1,13 @@
|
||||
#include "test_common.hpp"
|
||||
#include "test_perf.hpp"
|
||||
|
||||
void PERF_TEST::Test_Abs(aclCxt *acl_context)
|
||||
{
|
||||
using namespace cv;
|
||||
using namespace cv::acl;
|
||||
using namespace cvtest;
|
||||
using namespace testing;
|
||||
using namespace std;
|
||||
|
||||
void PERF_TEST::Test_Abs(aclCxt *acl_context) {
|
||||
int val, n;
|
||||
int valmax = 8192;
|
||||
int cycle_index = 10;
|
||||
@@ -11,11 +16,9 @@ void PERF_TEST::Test_Abs(aclCxt *acl_context)
|
||||
|
||||
// vector<int> type{CV_32FC1};
|
||||
vector<int> type{CV_32FC1, CV_32SC1};
|
||||
for (size_t i = 0; i < type.size(); ++i)
|
||||
{
|
||||
for (size_t i = 0; i < type.size(); ++i) {
|
||||
test.PrintLog("Perf test : Function: Abs()", type[i]);
|
||||
for (val = 8; val <= valmax; val *= 2)
|
||||
{
|
||||
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});
|
||||
@@ -25,8 +28,7 @@ void PERF_TEST::Test_Abs(aclCxt *acl_context)
|
||||
aclMat aclmat_dest(val, val, type[i], mat_dest.data, acl_context);
|
||||
|
||||
begin = static_cast<double>(getTickCount());
|
||||
while (n--)
|
||||
mat_dest = abs(mat_src);
|
||||
while (n--) mat_dest = abs(mat_src);
|
||||
end = static_cast<double>(getTickCount());
|
||||
time = (end - begin) / getTickFrequency() / cycle_index;
|
||||
|
||||
@@ -34,8 +36,7 @@ void PERF_TEST::Test_Abs(aclCxt *acl_context)
|
||||
aclmat_dest = abs(aclmat_src, 0);
|
||||
wait_stream(acl_context, 0);
|
||||
begin = static_cast<double>(getTickCount());
|
||||
while (n--)
|
||||
aclmat_dest = abs(aclmat_src, 1);
|
||||
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);
|
||||
@@ -47,13 +48,13 @@ void PERF_TEST::Test_Abs(aclCxt *acl_context)
|
||||
cout << "Shape: " << val << " x " << val << "\t\t";
|
||||
else
|
||||
cout << "Shape: " << val << " x " << val << "\t";
|
||||
cout << "CpuTimes: " << time << "\tAclTimes: " << acltime << "\tRate: " << time / acltime << endl;
|
||||
cout << "CpuTimes: " << time << "\tAclTimes: " << acltime
|
||||
<< "\tRate: " << time / acltime << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PERF_TEST::Test_Pow(aclCxt *acl_context)
|
||||
{
|
||||
void PERF_TEST::Test_Pow(aclCxt *acl_context) {
|
||||
int val, n;
|
||||
int valmax = 8192;
|
||||
int cycle_index = 10;
|
||||
@@ -62,11 +63,9 @@ void PERF_TEST::Test_Pow(aclCxt *acl_context)
|
||||
|
||||
// vector<int> type{CV_32FC1};
|
||||
vector<int> type{CV_8UC1, CV_32FC1, CV_32SC1};
|
||||
for (size_t i = 0; i < type.size(); ++i)
|
||||
{
|
||||
for (size_t i = 0; i < type.size(); ++i) {
|
||||
test.PrintLog("Perf test : Function: Pow()", type[i]);
|
||||
for (val = 8; val <= valmax; val *= 2)
|
||||
{
|
||||
for (val = 8; val <= valmax; val *= 2) {
|
||||
n = cycle_index;
|
||||
int power = test.RandDom_(6);
|
||||
Mat mat_src(val, val, type[i]);
|
||||
@@ -79,8 +78,7 @@ void PERF_TEST::Test_Pow(aclCxt *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);
|
||||
while (n--) pow(mat_src, power, mat_dest);
|
||||
end = static_cast<double>(getTickCount());
|
||||
time = (end - begin) / getTickFrequency() / cycle_index;
|
||||
|
||||
@@ -88,8 +86,7 @@ void PERF_TEST::Test_Pow(aclCxt *acl_context)
|
||||
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);
|
||||
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);
|
||||
@@ -99,13 +96,13 @@ void PERF_TEST::Test_Pow(aclCxt *acl_context)
|
||||
cout << "Shape: " << val << " x " << val << "\t\t";
|
||||
else
|
||||
cout << "Shape: " << val << " x " << val << "\t";
|
||||
cout << "CpuTimes: " << time << "\tAclTimes: " << acltime << "\tRate: " << time / acltime << endl;
|
||||
cout << "CpuTimes: " << time << "\tAclTimes: " << acltime
|
||||
<< "\tRate: " << time / acltime << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PERF_TEST::Test_Sqrt(aclCxt *acl_context)
|
||||
{
|
||||
void PERF_TEST::Test_Sqrt(aclCxt *acl_context) {
|
||||
int val, n;
|
||||
int valmax = 8192;
|
||||
int cycle_index = 10;
|
||||
@@ -113,10 +110,8 @@ void PERF_TEST::Test_Sqrt(aclCxt *acl_context)
|
||||
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)
|
||||
{
|
||||
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]);
|
||||
@@ -129,8 +124,7 @@ void PERF_TEST::Test_Sqrt(aclCxt *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);
|
||||
while (n--) sqrt(mat_src, mat_dest);
|
||||
end = static_cast<double>(getTickCount());
|
||||
time = (end - begin) / getTickFrequency() / cycle_index;
|
||||
|
||||
@@ -138,8 +132,7 @@ void PERF_TEST::Test_Sqrt(aclCxt *acl_context)
|
||||
sqrt(aclmat_src, aclmat_dest);
|
||||
wait_stream(acl_context);
|
||||
begin = static_cast<double>(getTickCount());
|
||||
while (n--)
|
||||
sqrt(aclmat_src, aclmat_dest, 1);
|
||||
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);
|
||||
@@ -149,14 +142,13 @@ void PERF_TEST::Test_Sqrt(aclCxt *acl_context)
|
||||
cout << "Shape: " << val << " x " << val << "\t\t";
|
||||
else
|
||||
cout << "Shape: " << val << " x " << val << "\t";
|
||||
cout << "CpuTimes: " << time << "\tAclTimes: " << acltime << "\tRate: " << time / acltime << endl;
|
||||
cout << "CpuTimes: " << time << "\tAclTimes: " << acltime
|
||||
<< "\tRate: " << time / acltime << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void PERF_TEST::Test_Add(aclCxt *acl_context)
|
||||
{
|
||||
void PERF_TEST::Test_Add(aclCxt *acl_context) {
|
||||
int val, n;
|
||||
int valmax = 8192;
|
||||
int cycle_index = 10;
|
||||
@@ -164,10 +156,8 @@ void PERF_TEST::Test_Add(aclCxt *acl_context)
|
||||
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)
|
||||
{
|
||||
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]);
|
||||
@@ -183,8 +173,7 @@ void PERF_TEST::Test_Add(aclCxt *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);
|
||||
while (n--) add(mat_src1, mat_src2, mat_dest);
|
||||
end = static_cast<double>(getTickCount());
|
||||
time = (end - begin) / getTickFrequency() / cycle_index;
|
||||
|
||||
@@ -192,8 +181,7 @@ void PERF_TEST::Test_Add(aclCxt *acl_context)
|
||||
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);
|
||||
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);
|
||||
@@ -205,14 +193,13 @@ void PERF_TEST::Test_Add(aclCxt *acl_context)
|
||||
cout << "Shape: " << val << " x " << val << "\t\t";
|
||||
else
|
||||
cout << "Shape: " << val << " x " << val << "\t";
|
||||
cout << "CpuTimes: " << time << "\tAclTimes: " << acltime << "\tRate: " << time / acltime << endl;
|
||||
cout << "CpuTimes: " << time << "\tAclTimes: " << acltime
|
||||
<< "\tRate: " << time / acltime << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void PERF_TEST::Test_Divide(aclCxt *acl_context)
|
||||
{
|
||||
void PERF_TEST::Test_Divide(aclCxt *acl_context) {
|
||||
int val, n;
|
||||
int valmax = 8192;
|
||||
int cycle_index = 10;
|
||||
@@ -220,10 +207,8 @@ void PERF_TEST::Test_Divide(aclCxt *acl_context)
|
||||
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)
|
||||
{
|
||||
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]);
|
||||
@@ -239,8 +224,7 @@ void PERF_TEST::Test_Divide(aclCxt *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);
|
||||
while (n--) divide(mat_src1, mat_src2, mat_dest);
|
||||
end = static_cast<double>(getTickCount());
|
||||
time = (end - begin) / getTickFrequency() / cycle_index;
|
||||
|
||||
@@ -248,8 +232,7 @@ void PERF_TEST::Test_Divide(aclCxt *acl_context)
|
||||
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);
|
||||
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);
|
||||
@@ -261,13 +244,13 @@ void PERF_TEST::Test_Divide(aclCxt *acl_context)
|
||||
cout << "Shape: " << val << " x " << val << "\t\t";
|
||||
else
|
||||
cout << "Shape: " << val << " x " << val << "\t";
|
||||
cout << "CpuTimes: " << time << "\tAclTimes: " << acltime << "\tRate: " << time / acltime << endl;
|
||||
cout << "CpuTimes: " << time << "\tAclTimes: " << acltime
|
||||
<< "\tRate: " << time / acltime << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PERF_TEST::Test_Exp(aclCxt *acl_context)
|
||||
{
|
||||
void PERF_TEST::Test_Exp(aclCxt *acl_context) {
|
||||
int val, n;
|
||||
int valmax = 8192;
|
||||
int cycle_index = 10;
|
||||
@@ -276,10 +259,8 @@ void PERF_TEST::Test_Exp(aclCxt *acl_context)
|
||||
|
||||
// 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)
|
||||
{
|
||||
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]);
|
||||
@@ -292,8 +273,7 @@ void PERF_TEST::Test_Exp(aclCxt *acl_context)
|
||||
aclMat aclmat_dest(val, val, type[i], mat_dest.data, acl_context);
|
||||
|
||||
begin = static_cast<double>(getTickCount());
|
||||
while (n--)
|
||||
exp(mat_src, mat_dest);
|
||||
while (n--) exp(mat_src, mat_dest);
|
||||
end = static_cast<double>(getTickCount());
|
||||
time = (end - begin) / getTickFrequency() / cycle_index;
|
||||
|
||||
@@ -301,8 +281,7 @@ void PERF_TEST::Test_Exp(aclCxt *acl_context)
|
||||
exp(aclmat_src, aclmat_dest);
|
||||
wait_stream(acl_context);
|
||||
begin = static_cast<double>(getTickCount());
|
||||
while (n--)
|
||||
exp(aclmat_src, aclmat_dest, 1);
|
||||
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);
|
||||
@@ -312,14 +291,13 @@ void PERF_TEST::Test_Exp(aclCxt *acl_context)
|
||||
cout << "Shape: " << val << " x " << val << "\t\t";
|
||||
else
|
||||
cout << "Shape: " << val << " x " << val << "\t";
|
||||
cout << "CpuTimes: " << time << "\tAclTimes: " << acltime << "\tRate: " << time / acltime << endl;
|
||||
cout << "CpuTimes: " << time << "\tAclTimes: " << acltime
|
||||
<< "\tRate: " << time / acltime << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void PERF_TEST::Test_Log(aclCxt *acl_context)
|
||||
{
|
||||
void PERF_TEST::Test_Log(aclCxt *acl_context) {
|
||||
int val, n;
|
||||
int valmax = 8192;
|
||||
int cycle_index = 10;
|
||||
@@ -327,10 +305,8 @@ void PERF_TEST::Test_Log(aclCxt *acl_context)
|
||||
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)
|
||||
{
|
||||
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]);
|
||||
@@ -343,8 +319,7 @@ void PERF_TEST::Test_Log(aclCxt *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);
|
||||
while (n--) log(mat_src, mat_dest);
|
||||
end = static_cast<double>(getTickCount());
|
||||
time = (end - begin) / getTickFrequency() / cycle_index;
|
||||
|
||||
@@ -352,8 +327,7 @@ void PERF_TEST::Test_Log(aclCxt *acl_context)
|
||||
log(aclmat_src, aclmat_dest, 1);
|
||||
wait_stream(acl_context);
|
||||
begin = static_cast<double>(getTickCount());
|
||||
while (n--)
|
||||
log(aclmat_src, aclmat_dest, 1);
|
||||
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);
|
||||
@@ -363,14 +337,13 @@ void PERF_TEST::Test_Log(aclCxt *acl_context)
|
||||
cout << "Shape: " << val << " x " << val << "\t\t";
|
||||
else
|
||||
cout << "Shape: " << val << " x " << val << "\t";
|
||||
cout << "CpuTimes: " << time << "\tAclTimes: " << acltime << "\tRate: " << time / acltime << endl;
|
||||
cout << "CpuTimes: " << time << "\tAclTimes: " << acltime
|
||||
<< "\tRate: " << time / acltime << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void PERF_TEST::Test_Max(aclCxt *acl_context)
|
||||
{
|
||||
void PERF_TEST::Test_Max(aclCxt *acl_context) {
|
||||
int val, n;
|
||||
int valmax = 8192;
|
||||
int cycle_index = 10;
|
||||
@@ -378,10 +351,8 @@ void PERF_TEST::Test_Max(aclCxt *acl_context)
|
||||
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)
|
||||
{
|
||||
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]);
|
||||
@@ -397,8 +368,7 @@ void PERF_TEST::Test_Max(aclCxt *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);
|
||||
while (n--) cv::max(mat_src1, mat_src2, mat_dest);
|
||||
end = static_cast<double>(getTickCount());
|
||||
time = (end - begin) / getTickFrequency() / cycle_index;
|
||||
|
||||
@@ -406,8 +376,7 @@ void PERF_TEST::Test_Max(aclCxt *acl_context)
|
||||
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);
|
||||
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);
|
||||
@@ -419,13 +388,13 @@ void PERF_TEST::Test_Max(aclCxt *acl_context)
|
||||
cout << "Shape: " << val << " x " << val << "\t\t";
|
||||
else
|
||||
cout << "Shape: " << val << " x " << val << "\t";
|
||||
cout << "CpuTimes: " << time << "\tAclTimes: " << acltime << "\tRate: " << time / acltime << endl;
|
||||
cout << "CpuTimes: " << time << "\tAclTimes: " << acltime
|
||||
<< "\tRate: " << time / acltime << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PERF_TEST::Test_Min(aclCxt *acl_context)
|
||||
{
|
||||
void PERF_TEST::Test_Min(aclCxt *acl_context) {
|
||||
int val, n;
|
||||
int valmax = 8192;
|
||||
int cycle_index = 10;
|
||||
@@ -433,10 +402,8 @@ void PERF_TEST::Test_Min(aclCxt *acl_context)
|
||||
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)
|
||||
{
|
||||
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]);
|
||||
@@ -452,8 +419,7 @@ void PERF_TEST::Test_Min(aclCxt *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);
|
||||
while (n--) cv::min(mat_src1, mat_src2, mat_dest);
|
||||
end = static_cast<double>(getTickCount());
|
||||
time = (end - begin) / getTickFrequency() / cycle_index;
|
||||
|
||||
@@ -461,8 +427,7 @@ void PERF_TEST::Test_Min(aclCxt *acl_context)
|
||||
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);
|
||||
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);
|
||||
@@ -474,8 +439,8 @@ void PERF_TEST::Test_Min(aclCxt *acl_context)
|
||||
cout << "Shape: " << val << " x " << val << "\t\t";
|
||||
else
|
||||
cout << "Shape: " << val << " x " << val << "\t";
|
||||
cout << "CpuTimes: " << time << "\tAclTimes: " << acltime << "\tRate: " << time / acltime << endl;
|
||||
cout << "CpuTimes: " << time << "\tAclTimes: " << acltime
|
||||
<< "\tRate: " << time / acltime << endl;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -1,49 +1,26 @@
|
||||
#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);
|
||||
|
||||
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;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
void PERF_TEST::Test_Merge(aclCxt *acl_context)
|
||||
{
|
||||
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;
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
for (size_t i = 0; i < srcType.size(); ++i) {
|
||||
test.PrintLog("Perf test : Function: merge()", srcType[i]);
|
||||
for (val = 8; val <= valmax; val *= 2)
|
||||
{
|
||||
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));
|
||||
@@ -71,8 +48,7 @@ void PERF_TEST::Test_Merge(aclCxt *acl_context)
|
||||
acl_src.emplace_back(aclmat_src3);
|
||||
|
||||
begin = static_cast<double>(getTickCount());
|
||||
while (n--)
|
||||
merge(src, mat_dest);
|
||||
while (n--) merge(src, mat_dest);
|
||||
end = static_cast<double>(getTickCount());
|
||||
time = (end - begin) / getTickFrequency() / cycle_index;
|
||||
|
||||
@@ -80,8 +56,7 @@ void PERF_TEST::Test_Merge(aclCxt *acl_context)
|
||||
merge(acl_src, aclmat_dest);
|
||||
wait_stream(acl_context);
|
||||
begin = static_cast<double>(getTickCount());
|
||||
while (n--)
|
||||
merge(acl_src, aclmat_dest, 1);
|
||||
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);
|
||||
@@ -92,14 +67,13 @@ void PERF_TEST::Test_Merge(aclCxt *acl_context)
|
||||
cout << "Shape: " << val << " x " << val << "\t\t";
|
||||
else
|
||||
cout << "Shape: " << val << " x " << val << "\t";
|
||||
cout << "CpuTimes: " << time << "\tAclTimes: " << acltime << "\tRate: " << time / acltime << endl;
|
||||
cout << "CpuTimes: " << time << "\tAclTimes: " << acltime
|
||||
<< "\tRate: " << time / acltime << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void PERF_TEST::Test_Transpose(aclCxt *acl_context)
|
||||
{
|
||||
void PERF_TEST::Test_Transpose(aclCxt *acl_context) {
|
||||
int val, n;
|
||||
int valmax = 8192;
|
||||
int cycle_index = 10;
|
||||
@@ -108,11 +82,9 @@ void PERF_TEST::Test_Transpose(aclCxt *acl_context)
|
||||
|
||||
// vector<int> type{CV_32FC1};
|
||||
vector<int> type{CV_32FC1, CV_32SC1};
|
||||
for (size_t i = 0; i < type.size(); ++i)
|
||||
{
|
||||
for (size_t i = 0; i < type.size(); ++i) {
|
||||
test.PrintLog("Perf test : Function: transpose()", type[i]);
|
||||
for (val = 8; val <= valmax; val *= 2)
|
||||
{
|
||||
for (val = 8; val <= valmax; val *= 2) {
|
||||
n = cycle_index;
|
||||
Mat mat_src(val, val, type[i]);
|
||||
Mat mat_dest(val, val, type[i]);
|
||||
@@ -124,8 +96,7 @@ void PERF_TEST::Test_Transpose(aclCxt *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);
|
||||
while (n--) transpose(mat_src, mat_dest);
|
||||
end = static_cast<double>(getTickCount());
|
||||
time = (end - begin) / getTickFrequency() / cycle_index;
|
||||
|
||||
@@ -133,8 +104,7 @@ void PERF_TEST::Test_Transpose(aclCxt *acl_context)
|
||||
transpose(aclmat_src, aclmat_dest);
|
||||
wait_stream(acl_context);
|
||||
begin = static_cast<double>(getTickCount());
|
||||
while (n--)
|
||||
transpose(aclmat_src, aclmat_dest, 1);
|
||||
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);
|
||||
@@ -146,13 +116,13 @@ void PERF_TEST::Test_Transpose(aclCxt *acl_context)
|
||||
cout << "Shape: " << val << " x " << val << "\t\t";
|
||||
else
|
||||
cout << "Shape: " << val << " x " << val << "\t";
|
||||
cout << "CpuTimes: " << time << "\tAclTimes: " << acltime << "\tRate: " << time / acltime << endl;
|
||||
cout << "CpuTimes: " << time << "\tAclTimes: " << acltime
|
||||
<< "\tRate: " << time / acltime << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PERF_TEST::Test_Split(aclCxt *acl_context)
|
||||
{
|
||||
void PERF_TEST::Test_Split(aclCxt *acl_context) {
|
||||
int val, n;
|
||||
int valmax = 8192;
|
||||
int cycle_index = 10;
|
||||
@@ -162,11 +132,9 @@ void PERF_TEST::Test_Split(aclCxt *acl_context)
|
||||
// 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)
|
||||
{
|
||||
for (size_t i = 0; i < srcType.size(); ++i) {
|
||||
test.PrintLog("Perf test : Function: split()", srcType[i]);
|
||||
for (val = 8; val <= valmax; val *= 2)
|
||||
{
|
||||
for (val = 8; val <= valmax; val *= 2) {
|
||||
n = cycle_index;
|
||||
Mat mat_src(val, val, srcType[i]);
|
||||
Mat mat_dest1(val, val, destType[i]);
|
||||
@@ -191,8 +159,7 @@ void PERF_TEST::Test_Split(aclCxt *acl_context)
|
||||
acl_dest.emplace_back(aclmat_dest3);
|
||||
|
||||
begin = static_cast<double>(getTickCount());
|
||||
while (n--)
|
||||
split(mat_src, dest);
|
||||
while (n--) split(mat_src, dest);
|
||||
end = static_cast<double>(getTickCount());
|
||||
time = (end - begin) / getTickFrequency() / cycle_index;
|
||||
|
||||
@@ -200,8 +167,7 @@ void PERF_TEST::Test_Split(aclCxt *acl_context)
|
||||
split(aclmat_src, acl_dest);
|
||||
wait_stream(acl_context);
|
||||
begin = static_cast<double>(getTickCount());
|
||||
while (n--)
|
||||
split(aclmat_src, acl_dest, 1);
|
||||
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);
|
||||
@@ -218,15 +184,13 @@ void PERF_TEST::Test_Split(aclCxt *acl_context)
|
||||
cout << "Shape: " << val << " x " << val << "\t\t";
|
||||
else
|
||||
cout << "Shape: " << val << " x " << val << "\t";
|
||||
cout << "CpuTimes: " << time << "\tAclTimes: " << acltime << "\tRate: " << time / acltime << endl;
|
||||
|
||||
cout << "CpuTimes: " << time << "\tAclTimes: " << acltime
|
||||
<< "\tRate: " << time / acltime << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void PERF_TEST::Test_Flip(aclCxt *acl_context)
|
||||
{
|
||||
void PERF_TEST::Test_Flip(aclCxt *acl_context) {
|
||||
int val, n;
|
||||
int valmax = 8192;
|
||||
int cycle_index = 100;
|
||||
@@ -234,11 +198,9 @@ void PERF_TEST::Test_Flip(aclCxt *acl_context)
|
||||
Common_Test test;
|
||||
|
||||
vector<int> type{CV_8UC1, CV_32FC1, CV_32SC1, CV_64FC1};
|
||||
for (size_t i = 0; i < type.size(); ++i)
|
||||
{
|
||||
for (size_t i = 0; i < type.size(); ++i) {
|
||||
test.PrintLog("Perf test : Function: flip()", type[i]);
|
||||
for (val = 8; val <= valmax; val *= 2)
|
||||
{
|
||||
for (val = 8; val <= valmax; val *= 2) {
|
||||
n = cycle_index;
|
||||
Mat mat_src(val, val, type[i]);
|
||||
Mat mat_dest(val, val, type[i]);
|
||||
@@ -250,8 +212,7 @@ void PERF_TEST::Test_Flip(aclCxt *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);
|
||||
while (n--) flip(mat_src, mat_dest, 0);
|
||||
end = static_cast<double>(getTickCount());
|
||||
time = (end - begin) / getTickFrequency() / cycle_index;
|
||||
|
||||
@@ -259,8 +220,7 @@ void PERF_TEST::Test_Flip(aclCxt *acl_context)
|
||||
flip(aclmat_src, aclmat_dest, 0);
|
||||
wait_stream(acl_context);
|
||||
begin = static_cast<double>(getTickCount());
|
||||
while (n--)
|
||||
flip(aclmat_src, aclmat_dest, 0, 1);
|
||||
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);
|
||||
@@ -272,7 +232,8 @@ void PERF_TEST::Test_Flip(aclCxt *acl_context)
|
||||
cout << "Shape: " << val << " x " << val << "\t\t";
|
||||
else
|
||||
cout << "Shape: " << val << " x " << val << "\t";
|
||||
cout << "CpuTimes: " << time << "\tAclTimes: " << acltime << "\tRate: " << time / acltime << endl;
|
||||
cout << "CpuTimes: " << time << "\tAclTimes: " << acltime
|
||||
<< "\tRate: " << time / acltime << endl;
|
||||
}
|
||||
}
|
||||
}
|
@@ -3,31 +3,30 @@
|
||||
|
||||
#include "test_precomp.hpp"
|
||||
|
||||
class PERF_TEST
|
||||
{
|
||||
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);
|
||||
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
|
@@ -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
|
||||
|
Reference in New Issue
Block a user