mirror of
https://github.com/Ascend/ascend-opencv.git
synced 2025-10-09 10:10:08 +08:00
update version
This commit is contained in:
@@ -1,9 +1,9 @@
|
|||||||
#if(NOT HAVE_ACL)
|
# if(NOT HAVE_ACL)
|
||||||
# ocv_module_disable(acl)
|
# ocv_module_disable(acl)
|
||||||
# return()
|
# return()
|
||||||
#endif()
|
# endif()
|
||||||
|
|
||||||
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" "-DENABLE_DVPP_INTERFACE")
|
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" "-DENABLE_DVPP_INTERFACE")
|
||||||
|
|
||||||
set(acl_lib "/usr/local/Ascend/ascend-toolkit/latest/acllib/lib64/stub/")
|
set(acl_lib "/usr/local/Ascend/ascend-toolkit/latest/acllib/lib64/stub/")
|
||||||
set(acl_lib "/usr/local/Ascend/ascend-toolkit/latest/fwkacllib/lib64/stub/")
|
set(acl_lib "/usr/local/Ascend/ascend-toolkit/latest/fwkacllib/lib64/stub/")
|
||||||
|
@@ -1,8 +1,9 @@
|
|||||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
/* M///////////////////////////////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
// 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,
|
// If you do not agree to this license, do not download, install,
|
||||||
// copy or use the software.
|
// copy or use the software.
|
||||||
//
|
//
|
||||||
@@ -10,28 +11,35 @@
|
|||||||
// License Agreement
|
// License Agreement
|
||||||
// For Open Source Computer Vision Library
|
// 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, Advanced Micro Devices, Inc., all rights reserved.
|
||||||
// Copyright (C) 2010-2012, Multicoreware, Inc., all rights reserved.
|
// Copyright (C) 2010-2012, Multicoreware, Inc., all rights reserved.
|
||||||
// Third party copyrights are property of their respective owners.
|
// 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:
|
// are permitted provided that the following conditions are met:
|
||||||
//
|
//
|
||||||
// * Redistribution's of source code must retain the above copyright notice,
|
// * Redistribution's of source code must retain the above copyright notice,
|
||||||
// this list of conditions and the following disclaimer.
|
// 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
|
// this list of conditions and the following disclaimer in the documentation
|
||||||
// and/or other materials provided with the distribution.
|
// 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.
|
// 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
|
// any express or implied warranties, including, but not limited to, the implied
|
||||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
// warranties of merchantability and fitness for a particular purpose are
|
||||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
disclaimed.
|
||||||
|
// In no event shall the Intel Corporation or contributors be liable for any
|
||||||
|
direct,
|
||||||
// indirect, incidental, special, exemplary, or consequential damages
|
// indirect, incidental, special, exemplary, or consequential damages
|
||||||
// (including, but not limited to, procurement of substitute goods or services;
|
// (including, but not limited to, procurement of substitute goods or services;
|
||||||
// loss of use, data, or profits; or business interruption) however caused
|
// loss of use, data, or profits; or business interruption) however caused
|
||||||
@@ -39,19 +47,19 @@
|
|||||||
// or tort (including negligence or otherwise) arising in any way out of
|
// 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.
|
// the use of this software, even if advised of the possibility of such damage.
|
||||||
//
|
//
|
||||||
//M*/
|
//M */
|
||||||
|
|
||||||
#ifndef OPENCV_ACL_HPP
|
#ifndef OPENCV_ACL_HPP
|
||||||
#define OPENCV_ACL_HPP
|
#define OPENCV_ACL_HPP
|
||||||
|
|
||||||
#include "acl_type.hpp"
|
|
||||||
#include "acl_init.hpp"
|
#include "acl_init.hpp"
|
||||||
#include "acl_mat.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 "mathfuncs.hpp"
|
||||||
#include "matrices.hpp"
|
#include "matrices.hpp"
|
||||||
#include "gemm.hpp"
|
#include "operator_desc.hpp"
|
||||||
#include "mat_core.hpp"
|
|
||||||
#include "init_core.hpp"
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@@ -4,55 +4,52 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "opencv2/core.hpp"
|
|
||||||
#include "acl_type.hpp"
|
#include "acl_type.hpp"
|
||||||
|
#include "opencv2/core.hpp"
|
||||||
|
|
||||||
using namespace std;
|
namespace cv {
|
||||||
|
namespace acl {
|
||||||
|
CV_EXPORTS Mutex &getInitMutex();
|
||||||
|
//////////////////////////////// aclEnv ////////////////////////////////
|
||||||
|
class CV_EXPORTS aclEnv {
|
||||||
|
public:
|
||||||
|
aclEnv();
|
||||||
|
aclEnv(const char *config_path);
|
||||||
|
static aclEnv *get_acl_env(const char *config_path);
|
||||||
|
int get_device_count();
|
||||||
|
int *refcount;
|
||||||
|
~aclEnv();
|
||||||
|
|
||||||
namespace cv
|
private:
|
||||||
{
|
uint32_t _device_count;
|
||||||
namespace acl
|
};
|
||||||
{
|
|
||||||
CV_EXPORTS Mutex &getInitMutex();
|
|
||||||
//////////////////////////////// aclEnv ////////////////////////////////
|
|
||||||
class CV_EXPORTS aclEnv
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
aclEnv();
|
|
||||||
aclEnv(const char* config_path);
|
|
||||||
static aclEnv* get_acl_env(const char* config_path);
|
|
||||||
int get_device_count();
|
|
||||||
int *refcount;
|
|
||||||
~aclEnv();
|
|
||||||
private:
|
|
||||||
uint32_t _device_count;
|
|
||||||
};
|
|
||||||
|
|
||||||
//////////////////////////////// aclCxt ////////////////////////////////
|
//////////////////////////////// aclCxt ////////////////////////////////
|
||||||
class CV_EXPORTS aclCxt
|
class CV_EXPORTS aclCxt {
|
||||||
{
|
public:
|
||||||
public:
|
aclCxt();
|
||||||
aclCxt();
|
aclCxt(int device_id);
|
||||||
aclCxt(int device_id);
|
|
||||||
|
|
||||||
aclrtContext* get_context();
|
aclrtContext *get_context();
|
||||||
void set_current_context();
|
void set_current_context();
|
||||||
|
|
||||||
void create_stream(int count = 1);
|
void create_stream(int count = 1);
|
||||||
aclStream get_stream(const size_t index = 0);
|
aclStream get_stream(const size_t index = 0);
|
||||||
~aclCxt();
|
~aclCxt();
|
||||||
private:
|
|
||||||
int32_t _device_id;
|
|
||||||
aclrtContext* _context;
|
|
||||||
std::vector<aclStream> _acl_streams;
|
|
||||||
};
|
|
||||||
|
|
||||||
CV_EXPORTS void wait_stream(aclCxt* context, const int stream_id = 0);
|
private:
|
||||||
//////////////////////////////// device ////////////////////////////////
|
int32_t _device_id;
|
||||||
CV_EXPORTS aclCxt *set_device(const char* config_path, int device_id = 0, int stream_count = 1);
|
aclrtContext *_context;
|
||||||
CV_EXPORTS void release_device(aclCxt* context);
|
std::vector<aclStream> _acl_streams;
|
||||||
|
};
|
||||||
|
|
||||||
} /* end of namespace acl */
|
CV_EXPORTS void wait_stream(aclCxt *context, const int stream_id = 0);
|
||||||
|
//////////////////////////////// device ////////////////////////////////
|
||||||
|
CV_EXPORTS aclCxt *set_device(const char *config_path, int device_id = 0,
|
||||||
|
int stream_count = 1);
|
||||||
|
CV_EXPORTS void release_device(aclCxt *context);
|
||||||
|
|
||||||
|
} /* end of namespace acl */
|
||||||
|
|
||||||
} /* end of namespace cv */
|
} /* end of namespace cv */
|
||||||
|
|
||||||
|
@@ -2,172 +2,185 @@
|
|||||||
#define OPENCV_ACL_MAT_HPP
|
#define OPENCV_ACL_MAT_HPP
|
||||||
|
|
||||||
#include "acl/acl.h"
|
#include "acl/acl.h"
|
||||||
#include "opencv2/core.hpp"
|
|
||||||
#include "acl_type.hpp"
|
|
||||||
#include "acl_init.hpp"
|
#include "acl_init.hpp"
|
||||||
|
#include "acl_type.hpp"
|
||||||
|
#include "opencv2/core.hpp"
|
||||||
|
|
||||||
|
namespace cv {
|
||||||
|
namespace acl {
|
||||||
|
//////////////////////////////// aclMat ////////////////////////////////
|
||||||
|
class CV_EXPORTS aclMat {
|
||||||
|
public:
|
||||||
|
//! default constructor
|
||||||
|
aclMat();
|
||||||
|
//! constructs aclMatrix of the specified size and type (_type is CV_8UC1,
|
||||||
|
//! CV_16FC1 etc.)
|
||||||
|
aclMat(int rows, int cols, int type, aclCxt *acl_context,
|
||||||
|
ALIGNMENT config = MEMORY_UNALIGNED,
|
||||||
|
MemMallocPolicy policy = MALLOC_NORMAL_ONLY);
|
||||||
|
aclMat(Size size, int type, aclCxt *acl_context,
|
||||||
|
ALIGNMENT config = MEMORY_UNALIGNED,
|
||||||
|
MemMallocPolicy policy = MALLOC_NORMAL_ONLY);
|
||||||
|
//! copy constructor
|
||||||
|
aclMat(const aclMat &m);
|
||||||
|
//! constructor for aclMatrix headers pointing to user-allocated data
|
||||||
|
aclMat(int rows, int cols, int type, void *data, aclCxt *acl_context,
|
||||||
|
ALIGNMENT config = MEMORY_UNALIGNED, size_t step = Mat::AUTO_STEP);
|
||||||
|
aclMat(Size size, int type, void *data, aclCxt *acl_context,
|
||||||
|
ALIGNMENT config = MEMORY_UNALIGNED, size_t step = Mat::AUTO_STEP);
|
||||||
|
//! creates a matrix header for a part of the bigger matrix
|
||||||
|
aclMat(const aclMat &m, const Range &rowRange,
|
||||||
|
const Range &colRange = Range::all());
|
||||||
|
aclMat(const aclMat &m, const Rect &roi);
|
||||||
|
//! builds aclMat from Mat. Perfom blocking upload to device.
|
||||||
|
aclMat(const Mat &m, aclCxt *acl_context, ALIGNMENT config = MEMORY_UNALIGNED,
|
||||||
|
MemMallocPolicy policy = MALLOC_NORMAL_ONLY);
|
||||||
|
//! destructor - calls release()
|
||||||
|
~aclMat();
|
||||||
|
|
||||||
namespace cv
|
//! assignment operators shallow copy
|
||||||
{
|
aclMat &operator=(const aclMat &m);
|
||||||
namespace acl
|
//! assignment operator. Perfom blocking upload to device.
|
||||||
{
|
aclMat &operator=(const Mat &m);
|
||||||
//////////////////////////////// aclMat ////////////////////////////////
|
|
||||||
class CV_EXPORTS aclMat
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
//! default constructor
|
|
||||||
aclMat();
|
|
||||||
//! constructs aclMatrix of the specified size and type (_type is CV_8UC1, CV_16FC1 etc.)
|
|
||||||
aclMat(int rows, int cols, int type, aclCxt *acl_context, ALIGNMENT config = MEMORY_UNALIGNED, MemMallocPolicy policy = MALLOC_NORMAL_ONLY);
|
|
||||||
aclMat(Size size, int type, aclCxt *acl_context, ALIGNMENT config = MEMORY_UNALIGNED, MemMallocPolicy policy = MALLOC_NORMAL_ONLY);
|
|
||||||
//! copy constructor
|
|
||||||
aclMat(const aclMat &m);
|
|
||||||
//! constructor for aclMatrix headers pointing to user-allocated data
|
|
||||||
aclMat(int rows, int cols, int type, void *data, aclCxt* acl_context, ALIGNMENT config = MEMORY_UNALIGNED, size_t step = Mat::AUTO_STEP);
|
|
||||||
aclMat(Size size, int type, void *data, aclCxt* acl_context, ALIGNMENT config = MEMORY_UNALIGNED, size_t step = Mat::AUTO_STEP);
|
|
||||||
//! creates a matrix header for a part of the bigger matrix
|
|
||||||
aclMat(const aclMat &m, const Range &rowRange, const Range &colRange = Range::all());
|
|
||||||
aclMat(const aclMat &m, const Rect &roi);
|
|
||||||
//! builds aclMat from Mat. Perfom blocking upload to device.
|
|
||||||
aclMat (const Mat &m, aclCxt* acl_context, ALIGNMENT config = MEMORY_UNALIGNED, MemMallocPolicy policy = MALLOC_NORMAL_ONLY);
|
|
||||||
//! destructor - calls release()
|
|
||||||
~aclMat();
|
|
||||||
|
|
||||||
//! assignment operators shallow copy
|
//! pefroms blocking upload data to aclMat.
|
||||||
aclMat &operator=(const aclMat &m);
|
void upload(const Mat &m, ALIGNMENT config = MEMORY_UNALIGNED);
|
||||||
//! assignment operator. Perfom blocking upload to device.
|
void upload(const Mat &m, aclStream stream,
|
||||||
aclMat &operator=(const Mat &m);
|
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;
|
||||||
|
|
||||||
//! pefroms blocking upload data to aclMat.
|
operator Mat() const;
|
||||||
void upload(const Mat &m, ALIGNMENT config = MEMORY_UNALIGNED);
|
aclMat clone() const;
|
||||||
void upload(const Mat &m, aclStream stream, ALIGNMENT config = MEMORY_UNALIGNED);
|
void copyTo(aclMat &dest) const;
|
||||||
//! downloads data from device to host memory. Blocking calls.
|
|
||||||
void download(Mat &m, ALIGNMENT config = MEMORY_UNALIGNED) const;
|
|
||||||
void download(Mat &m, aclStream stream, ALIGNMENT config = MEMORY_UNALIGNED) const;
|
|
||||||
|
|
||||||
operator Mat() const;
|
//! returns a new aclMatrix header for the specified row
|
||||||
aclMat clone() const;
|
aclMat row(int y) const;
|
||||||
void copyTo(aclMat& dest) const;
|
//! returns a new aclMatrix header for the specified column
|
||||||
|
aclMat col(int x) const;
|
||||||
|
//! ... for the specified row span
|
||||||
|
aclMat rowRange(int startrow, int endrow) const;
|
||||||
|
aclMat rowRange(const Range &r) const;
|
||||||
|
//! ... for the specified column span
|
||||||
|
aclMat colRange(int startcol, int endcol) const;
|
||||||
|
aclMat colRange(const Range &r) const;
|
||||||
|
|
||||||
//! returns a new aclMatrix header for the specified row
|
//! locates aclMatrix header within a parent aclMatrix. See below
|
||||||
aclMat row(int y) const;
|
void locateROI(Size &wholeSize, Point &ofs) const;
|
||||||
//! returns a new aclMatrix header for the specified column
|
//! moves/resizes the current aclMatrix ROI inside the parent aclMatrix.
|
||||||
aclMat col(int x) const;
|
aclMat &adjustROI(int dtop, int dbottom, int dleft, int dright);
|
||||||
//! ... for the specified row span
|
|
||||||
aclMat rowRange(int startrow, int endrow) const;
|
|
||||||
aclMat rowRange(const Range &r) const;
|
|
||||||
//! ... for the specified column span
|
|
||||||
aclMat colRange(int startcol, int endcol) const;
|
|
||||||
aclMat colRange(const Range &r) const;
|
|
||||||
|
|
||||||
//! locates aclMatrix header within a parent aclMatrix. See below
|
//! allocates new aclMatrix data unless the aclMatrix already has specified
|
||||||
void locateROI(Size &wholeSize, Point &ofs) const;
|
//! size and type.
|
||||||
//! moves/resizes the current aclMatrix ROI inside the parent aclMatrix.
|
// previous data is unreferenced if needed.
|
||||||
aclMat &adjustROI(int dtop, int dbottom, int dleft, int dright);
|
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 data unless the aclMatrix already has specified size and type.
|
//! allocates new aclMatrix with specified device memory type.
|
||||||
// previous data is unreferenced if needed.
|
void createEx(int rows, int cols, int type,
|
||||||
void create(int rows, int cols, int type, ALIGNMENT config = MEMORY_UNALIGNED, MemMallocPolicy policy = MALLOC_NORMAL_ONLY);
|
ALIGNMENT config = MEMORY_UNALIGNED,
|
||||||
void create(Size size, int type, ALIGNMENT config = MEMORY_UNALIGNED, MemMallocPolicy policy = MALLOC_NORMAL_ONLY);
|
MemMallocPolicy policy = MALLOC_NORMAL_ONLY);
|
||||||
|
void createEx(Size size, int type, ALIGNMENT config = MEMORY_UNALIGNED,
|
||||||
|
MemMallocPolicy policy = MALLOC_NORMAL_ONLY);
|
||||||
|
|
||||||
//! allocates new aclMatrix with specified device memory type.
|
//! decreases reference counter;
|
||||||
void createEx(int rows, int cols, int type, ALIGNMENT config = MEMORY_UNALIGNED, MemMallocPolicy policy = MALLOC_NORMAL_ONLY);
|
// deallocate the data when reference counter reaches 0.
|
||||||
void createEx(Size size, int type, ALIGNMENT config = MEMORY_UNALIGNED, MemMallocPolicy policy = MALLOC_NORMAL_ONLY);
|
void release();
|
||||||
|
|
||||||
//! decreases reference counter;
|
//! swaps with other smart pointer
|
||||||
// deallocate the data when reference counter reaches 0.
|
void swap(aclMat &mat);
|
||||||
void release();
|
|
||||||
|
|
||||||
//! swaps with other smart pointer
|
//! extracts a rectangular sub-aclMatrix
|
||||||
void swap(aclMat &mat);
|
// (this is a generalized form of row, rowRange etc.)
|
||||||
|
aclMat operator()(Range rowRange, Range colRange) const;
|
||||||
|
aclMat operator()(const Rect &roi) const;
|
||||||
|
|
||||||
//! extracts a rectangular sub-aclMatrix
|
aclMat &operator+=(const aclMat &m);
|
||||||
// (this is a generalized form of row, rowRange etc.)
|
aclMat &operator-=(const aclMat &m);
|
||||||
aclMat operator()( Range rowRange, Range colRange ) const;
|
aclMat &operator/=(const aclMat &m);
|
||||||
aclMat operator()( const Rect &roi ) const;
|
aclMat &operator*=(const aclMat &m);
|
||||||
|
|
||||||
aclMat& operator+=( const aclMat& m );
|
//! returns true if the aclMatrix data is continuous
|
||||||
aclMat& operator-=( const aclMat& m );
|
// (i.e. when there are no gaps between successive rows).
|
||||||
aclMat& operator/=( const aclMat& m );
|
// similar to CV_IS_aclMat_CONT(cvaclMat->type)
|
||||||
aclMat& operator*=( const aclMat& m );
|
bool isContinuous() const;
|
||||||
|
|
||||||
|
//! returns element size in bytes,
|
||||||
|
// similar to CV_ELEM_SIZE(cvMat->type)
|
||||||
|
size_t elemSize() const;
|
||||||
|
//! returns the size of element channel in bytes.
|
||||||
|
size_t elemSize1() const;
|
||||||
|
|
||||||
//! returns true if the aclMatrix data is continuous
|
//! returns element type, similar to CV_MAT_TYPE(cvMat->type)
|
||||||
// (i.e. when there are no gaps between successive rows).
|
int type() const;
|
||||||
// similar to CV_IS_aclMat_CONT(cvaclMat->type)
|
//! returns element type, i.e. 8UC3 returns 8UC4 because in acl
|
||||||
bool isContinuous() const;
|
//! 3 channels element actually use 4 channel space
|
||||||
|
int acltype() const;
|
||||||
|
//! returns element type, similar to CV_MAT_DEPTH(cvMat->type)
|
||||||
|
int depth() const;
|
||||||
|
|
||||||
//! returns element size in bytes,
|
//! returns element type, similar to CV_MAT_CN(cvMat->type)
|
||||||
// similar to CV_ELEM_SIZE(cvMat->type)
|
int channels() const;
|
||||||
size_t elemSize() const;
|
//! returns element type, return 4 for 3 channels element,
|
||||||
//! returns the size of element channel in bytes.
|
//! becuase 3 channels element actually use 4 channel space
|
||||||
size_t elemSize1() const;
|
int aclchannels() const;
|
||||||
|
|
||||||
//! returns element type, similar to CV_MAT_TYPE(cvMat->type)
|
//! returns step/elemSize1()
|
||||||
int type() const;
|
size_t step1() const;
|
||||||
//! returns element type, i.e. 8UC3 returns 8UC4 because in acl
|
//! returns aclMatrix size:
|
||||||
//! 3 channels element actually use 4 channel space
|
// width == number of columns, height == number of rows
|
||||||
int acltype() const;
|
Size size() const;
|
||||||
//! returns element type, similar to CV_MAT_DEPTH(cvMat->type)
|
//! returns true if aclMatrix data is NULL
|
||||||
int depth() const;
|
bool empty() const;
|
||||||
|
|
||||||
//! returns element type, similar to CV_MAT_CN(cvMat->type)
|
friend void swap(aclMat &a, aclMat &b);
|
||||||
int channels() const;
|
friend void ensureSizeIsEnough(int rows, int cols, int type, aclMat &m,
|
||||||
//! returns element type, return 4 for 3 channels element,
|
ALIGNMENT config = MEMORY_UNALIGNED);
|
||||||
//!becuase 3 channels element actually use 4 channel space
|
friend void ensureSizeIsEnough(Size size, int type, aclMat &m,
|
||||||
int aclchannels() const;
|
ALIGNMENT config = MEMORY_UNALIGNED);
|
||||||
|
|
||||||
//! returns step/elemSize1()
|
/*! includes several bit-fields:
|
||||||
size_t step1() const;
|
- the magic signature
|
||||||
//! returns aclMatrix size:
|
- continuity flag
|
||||||
// width == number of columns, height == number of rows
|
- depth
|
||||||
Size size() const;
|
- number of channels
|
||||||
//! returns true if aclMatrix data is NULL
|
*/
|
||||||
bool empty() const;
|
int flags;
|
||||||
|
//! the number of rows and columns
|
||||||
|
int rows, cols;
|
||||||
|
//! a distance between successive rows in bytes; includes the gap if any
|
||||||
|
size_t step;
|
||||||
|
//! pointer to the data(ACL memory object)
|
||||||
|
// uchar *data;
|
||||||
|
|
||||||
friend void swap(aclMat &a, aclMat &b);
|
//! OpenCL context associated with the aclMat object.
|
||||||
friend void ensureSizeIsEnough(int rows, int cols, int type, aclMat &m, ALIGNMENT config = MEMORY_UNALIGNED);
|
void *data; // TODO
|
||||||
friend void ensureSizeIsEnough(Size size, int type, aclMat &m, ALIGNMENT config = MEMORY_UNALIGNED);
|
|
||||||
|
|
||||||
/*! includes several bit-fields:
|
//! pointer to the reference counter;
|
||||||
- the magic signature
|
// when aclMatrix points to user-allocated data, the pointer is NULL
|
||||||
- continuity flag
|
int *refcount;
|
||||||
- depth
|
|
||||||
- number of channels
|
|
||||||
*/
|
|
||||||
int flags;
|
|
||||||
//! the number of rows and columns
|
|
||||||
int rows, cols;
|
|
||||||
//! a distance between successive rows in bytes; includes the gap if any
|
|
||||||
size_t step;
|
|
||||||
//! pointer to the data(ACL memory object)
|
|
||||||
//uchar *data;
|
|
||||||
|
|
||||||
//! OpenCL context associated with the aclMat object.
|
//! helper fields used in locateROI and adjustROI
|
||||||
void *data; // TODO
|
// datastart and dataend are not used in current version
|
||||||
|
uchar *datastart;
|
||||||
|
uchar *dataend;
|
||||||
|
|
||||||
//! pointer to the reference counter;
|
// add offset for handle ROI, calculated in byte
|
||||||
// when aclMatrix points to user-allocated data, the pointer is NULL
|
int offset;
|
||||||
int *refcount;
|
// add wholerows and wholecols for the whole matrix, datastart and dataend are
|
||||||
|
// no longer used
|
||||||
|
int wholerows;
|
||||||
|
int wholecols;
|
||||||
|
|
||||||
//! helper fields used in locateROI and adjustROI
|
aclCxt *acl_context;
|
||||||
//datastart and dataend are not used in current version
|
size_t totalSize;
|
||||||
uchar *datastart;
|
};
|
||||||
uchar *dataend;
|
} /* end of namespace acl */
|
||||||
|
|
||||||
//add offset for handle ROI, calculated in byte
|
|
||||||
int offset;
|
|
||||||
//add wholerows and wholecols for the whole matrix, datastart and dataend are no longer used
|
|
||||||
int wholerows;
|
|
||||||
int wholecols;
|
|
||||||
|
|
||||||
aclCxt *acl_context;
|
|
||||||
size_t totalSize;
|
|
||||||
|
|
||||||
};
|
|
||||||
} /* end of namespace acl */
|
|
||||||
|
|
||||||
} /* end of namespace cv */
|
} /* end of namespace cv */
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
@@ -1,8 +1,9 @@
|
|||||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
/* M///////////////////////////////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
// 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,
|
// If you do not agree to this license, do not download, install,
|
||||||
// copy or use the software.
|
// copy or use the software.
|
||||||
//
|
//
|
||||||
@@ -10,28 +11,35 @@
|
|||||||
// License Agreement
|
// License Agreement
|
||||||
// For Open Source Computer Vision Library
|
// 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, Advanced Micro Devices, Inc., all rights reserved.
|
||||||
// Copyright (C) 2010-2012, Multicoreware, Inc., all rights reserved.
|
// Copyright (C) 2010-2012, Multicoreware, Inc., all rights reserved.
|
||||||
// Third party copyrights are property of their respective owners.
|
// 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:
|
// are permitted provided that the following conditions are met:
|
||||||
//
|
//
|
||||||
// * Redistribution's of source code must retain the above copyright notice,
|
// * Redistribution's of source code must retain the above copyright notice,
|
||||||
// this list of conditions and the following disclaimer.
|
// 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
|
// this list of conditions and the following disclaimer in the documentation
|
||||||
// and/or other materials provided with the distribution.
|
// 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.
|
// 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
|
// any express or implied warranties, including, but not limited to, the implied
|
||||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
// warranties of merchantability and fitness for a particular purpose are
|
||||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
disclaimed.
|
||||||
|
// In no event shall the Intel Corporation or contributors be liable for any
|
||||||
|
direct,
|
||||||
// indirect, incidental, special, exemplary, or consequential damages
|
// indirect, incidental, special, exemplary, or consequential damages
|
||||||
// (including, but not limited to, procurement of substitute goods or services;
|
// (including, but not limited to, procurement of substitute goods or services;
|
||||||
// loss of use, data, or profits; or business interruption) however caused
|
// loss of use, data, or profits; or business interruption) however caused
|
||||||
@@ -39,7 +47,7 @@
|
|||||||
// or tort (including negligence or otherwise) arising in any way out of
|
// 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.
|
// the use of this software, even if advised of the possibility of such damage.
|
||||||
//
|
//
|
||||||
//M*/
|
//M */
|
||||||
|
|
||||||
#ifndef OPENCV_ACL_TYPE_HPP
|
#ifndef OPENCV_ACL_TYPE_HPP
|
||||||
#define OPENCV_ACL_TYPE_HPP
|
#define OPENCV_ACL_TYPE_HPP
|
||||||
@@ -48,110 +56,102 @@
|
|||||||
#define AclVerifyCall(expr) __aclSafeCall(res, __FILE__, __LINE__, __func__)
|
#define AclVerifyCall(expr) __aclSafeCall(res, __FILE__, __LINE__, __func__)
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "opencv2/core.hpp"
|
|
||||||
#include "acl/acl.h"
|
#include "acl/acl.h"
|
||||||
|
#include "opencv2/core.hpp"
|
||||||
|
|
||||||
namespace cv
|
namespace cv {
|
||||||
{
|
namespace acl {
|
||||||
namespace acl
|
/**
|
||||||
{
|
* An error is reported if the expression value is not 0
|
||||||
/**
|
*/
|
||||||
* 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 = "") {
|
||||||
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";
|
||||||
if(0 != err)
|
std::cerr << "Acl Called Error: "
|
||||||
{
|
<< "file " << file << ", func " << function << ", line " << line
|
||||||
const char* function = func ? func : "unknown function";
|
<< " errorCode: " << err << std::endl;
|
||||||
std::cerr << "Acl Called Error: " << "file " << file << ", func " << function << ", line " << line << " errorCode: " << err << std::endl;
|
std::cerr.flush();
|
||||||
std::cerr.flush();
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/* Memory alignment */
|
/* Memory alignment */
|
||||||
enum ALIGNMENT { MEMORY_UNALIGNED = 0, MEMORY_ALIGN = 1};
|
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 {
|
||||||
enum { MAGIC_MASK = 0xFFFF0000, TYPE_MASK = 0x00000FFF, DEPTH_MASK = 7 };
|
MAGIC_VAL = 0x42FF0000,
|
||||||
|
AUTO_STEP = 0,
|
||||||
|
CONTINUOUS_FLAG = CV_MAT_CONT_FLAG,
|
||||||
|
SUBMATRIX_FLAG = CV_SUBMAT_FLAG
|
||||||
|
};
|
||||||
|
enum { MAGIC_MASK = 0xFFFF0000, TYPE_MASK = 0x00000FFF, DEPTH_MASK = 7 };
|
||||||
|
|
||||||
typedef aclrtStream aclStream;
|
typedef aclrtStream aclStream;
|
||||||
|
|
||||||
typedef enum Opdims { TWO_DIMS = 1, FOUR_DIMS } Opdims;
|
typedef enum Opdims { TWO_DIMS = 1, FOUR_DIMS } Opdims;
|
||||||
|
|
||||||
enum DeviceType
|
enum DeviceType {
|
||||||
{
|
ACL_DEVICE_TYPE_DEFAULT = (1 << 0),
|
||||||
ACL_DEVICE_TYPE_DEFAULT = (1 << 0),
|
ACL_DEVICE_TYPE_200 = (1 << 1),
|
||||||
ACL_DEVICE_TYPE_200 = (1 << 1),
|
ACL_DEVICE_TYPE_ACCELERATOR = (1 << 3),
|
||||||
ACL_DEVICE_TYPE_ACCELERATOR = (1 << 3),
|
};
|
||||||
};
|
|
||||||
|
|
||||||
enum AttrType
|
enum AttrType { OP_BOOL = 1, OP_INT, OP_FLOAT, OP_STRING };
|
||||||
{
|
|
||||||
OP_BOOL = 1,
|
|
||||||
OP_INT,
|
|
||||||
OP_FLOAT,
|
|
||||||
OP_STRING
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef enum MemMallocPolicy
|
typedef enum MemMallocPolicy {
|
||||||
{
|
MALLOC_HUGE_FIRST = 1,
|
||||||
MALLOC_HUGE_FIRST = 1,
|
MALLOC_HUGE_ONLY,
|
||||||
MALLOC_HUGE_ONLY,
|
MALLOC_NORMAL_ONLY,
|
||||||
MALLOC_NORMAL_ONLY,
|
MALLOC_HUGE_FIRST_P2P,
|
||||||
MALLOC_HUGE_FIRST_P2P,
|
MALLOC_HUGE_ONLY_P2P,
|
||||||
MALLOC_HUGE_ONLY_P2P,
|
MALLOC_NORMAL_ONLY_P2P
|
||||||
MALLOC_NORMAL_ONLY_P2P
|
} MemMallocPolicy;
|
||||||
} MemMallocPolicy;
|
|
||||||
|
|
||||||
|
CV_EXPORTS aclDataType type_transition(int depth);
|
||||||
|
CV_EXPORTS aclrtMemMallocPolicy type_transition(MemMallocPolicy type);
|
||||||
|
|
||||||
CV_EXPORTS aclDataType type_transition(int depth);
|
inline aclDataType type_transition(int depth) {
|
||||||
CV_EXPORTS aclrtMemMallocPolicy type_transition(MemMallocPolicy type);
|
switch (depth) {
|
||||||
|
case CV_8U:
|
||||||
|
return ACL_UINT8;
|
||||||
|
case CV_8S:
|
||||||
|
return ACL_INT8;
|
||||||
|
case CV_16U:
|
||||||
|
return ACL_UINT16;
|
||||||
|
case CV_16S:
|
||||||
|
return ACL_INT16;
|
||||||
|
case CV_16F:
|
||||||
|
return ACL_FLOAT16;
|
||||||
|
case CV_32S:
|
||||||
|
return ACL_INT32;
|
||||||
|
case CV_32F:
|
||||||
|
return ACL_FLOAT;
|
||||||
|
case CV_64F:
|
||||||
|
return ACL_DOUBLE;
|
||||||
|
}
|
||||||
|
return ACL_DT_UNDEFINED;
|
||||||
|
}
|
||||||
|
|
||||||
inline aclDataType type_transition(int depth)
|
inline aclrtMemMallocPolicy type_transition(MemMallocPolicy type) {
|
||||||
{
|
switch (type) {
|
||||||
switch (depth)
|
case MALLOC_HUGE_FIRST:
|
||||||
{
|
return ACL_MEM_MALLOC_HUGE_FIRST;
|
||||||
case CV_8U:
|
case MALLOC_HUGE_ONLY:
|
||||||
return ACL_UINT8;
|
return ACL_MEM_MALLOC_HUGE_ONLY;
|
||||||
case CV_8S:
|
case MALLOC_NORMAL_ONLY:
|
||||||
return ACL_INT8;
|
return ACL_MEM_MALLOC_NORMAL_ONLY;
|
||||||
case CV_16U:
|
case MALLOC_HUGE_FIRST_P2P:
|
||||||
return ACL_UINT16;
|
return ACL_MEM_MALLOC_HUGE_FIRST_P2P;
|
||||||
case CV_16S:
|
case MALLOC_HUGE_ONLY_P2P:
|
||||||
return ACL_INT16;
|
return ACL_MEM_MALLOC_HUGE_ONLY_P2P;
|
||||||
case CV_16F:
|
case MALLOC_NORMAL_ONLY_P2P:
|
||||||
return ACL_FLOAT16;
|
return ACL_MEM_MALLOC_NORMAL_ONLY_P2P;
|
||||||
case CV_32S:
|
}
|
||||||
return ACL_INT32;
|
return ACL_MEM_MALLOC_HUGE_FIRST;
|
||||||
case CV_32F:
|
}
|
||||||
return ACL_FLOAT;
|
|
||||||
case CV_64F:
|
|
||||||
return ACL_DOUBLE;
|
|
||||||
}
|
|
||||||
return ACL_DT_UNDEFINED;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline aclrtMemMallocPolicy type_transition(MemMallocPolicy type)
|
} /* end of namespace acl */
|
||||||
{
|
|
||||||
switch (type)
|
|
||||||
{
|
|
||||||
case MALLOC_HUGE_FIRST:
|
|
||||||
return ACL_MEM_MALLOC_HUGE_FIRST;
|
|
||||||
case MALLOC_HUGE_ONLY:
|
|
||||||
return ACL_MEM_MALLOC_HUGE_ONLY;
|
|
||||||
case MALLOC_NORMAL_ONLY:
|
|
||||||
return ACL_MEM_MALLOC_NORMAL_ONLY;
|
|
||||||
case MALLOC_HUGE_FIRST_P2P:
|
|
||||||
return ACL_MEM_MALLOC_HUGE_FIRST_P2P;
|
|
||||||
case MALLOC_HUGE_ONLY_P2P:
|
|
||||||
return ACL_MEM_MALLOC_HUGE_ONLY_P2P;
|
|
||||||
case MALLOC_NORMAL_ONLY_P2P:
|
|
||||||
return ACL_MEM_MALLOC_NORMAL_ONLY_P2P;
|
|
||||||
}
|
|
||||||
return ACL_MEM_MALLOC_HUGE_FIRST;
|
|
||||||
}
|
|
||||||
|
|
||||||
} /* end of namespace acl */
|
|
||||||
|
|
||||||
} /* end of namespace cv */
|
} /* end of namespace cv */
|
||||||
|
|
||||||
|
@@ -3,19 +3,20 @@
|
|||||||
|
|
||||||
#include "acl_mat.hpp"
|
#include "acl_mat.hpp"
|
||||||
|
|
||||||
namespace cv
|
namespace cv {
|
||||||
{
|
namespace acl {
|
||||||
namespace acl
|
// matrix multiplication
|
||||||
{
|
CV_EXPORTS void MatMul(const aclMat &src1, const aclMat &src2, aclMat &dest,
|
||||||
// matrix multiplication
|
int stream_id = 0);
|
||||||
CV_EXPORTS void MatMul(const aclMat& src1, const aclMat& src2, aclMat& dest, int stream_id = 0);
|
// convolution
|
||||||
// convolution
|
CV_EXPORTS void Convolution(
|
||||||
CV_EXPORTS void Convolution(const aclMat& src, const aclMat& kernel, aclMat& dest, \
|
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);
|
const std::vector<int64_t> &stridesList = std::vector<int64_t>{1, 1, 1, 1},
|
||||||
|
const std::vector<int64_t> &padsList = std::vector<int64_t>{0, 0, 0, 0},
|
||||||
|
int stream_id = 0);
|
||||||
|
|
||||||
} /* end of namespace acl */
|
} /* end of namespace acl */
|
||||||
|
|
||||||
} /* end of namespace cv */
|
} /* end of namespace cv */
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
@@ -3,115 +3,96 @@
|
|||||||
|
|
||||||
#include "acl_init.hpp"
|
#include "acl_init.hpp"
|
||||||
|
|
||||||
namespace cv
|
namespace cv {
|
||||||
{
|
namespace acl {
|
||||||
namespace acl
|
///////////////////////////aclEnv//////////////////////////////////
|
||||||
{
|
/**
|
||||||
///////////////////////////aclEnv//////////////////////////////////
|
* acl init
|
||||||
/**
|
*/
|
||||||
* 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;
|
||||||
uint32_t device_count;
|
|
||||||
|
|
||||||
AclSafeCall(aclInit(config_path));
|
AclSafeCall(aclInit(config_path));
|
||||||
|
|
||||||
AclSafeCall(aclrtGetDeviceCount(&device_count));
|
AclSafeCall(aclrtGetDeviceCount(&device_count));
|
||||||
|
|
||||||
_device_count = device_count;
|
_device_count = device_count;
|
||||||
// Reference Counting
|
// Reference Counting
|
||||||
refcount = static_cast<int *>(fastMalloc(sizeof(*refcount)));
|
refcount = static_cast<int *>(fastMalloc(sizeof(*refcount)));
|
||||||
*refcount = 0;
|
*refcount = 0;
|
||||||
|
|
||||||
clog << "aclInit() is success" << endl;
|
std::clog << "aclInit() is success" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int aclEnv::get_device_count()
|
inline int aclEnv::get_device_count() { return _device_count; }
|
||||||
{
|
|
||||||
return _device_count;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline aclEnv::~aclEnv()
|
inline aclEnv::~aclEnv() {
|
||||||
{
|
AclSafeCall(aclFinalize());
|
||||||
AclSafeCall(aclFinalize());
|
std::clog << "aclFinalize() is success" << std::endl;
|
||||||
clog << "aclFinalize() is success" << endl;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
/////////////////////////////////////////aclCxt////////////////////////////
|
||||||
|
inline aclCxt::aclCxt(){};
|
||||||
|
|
||||||
/////////////////////////////////////////aclCxt////////////////////////////
|
inline aclCxt::aclCxt(int device_id) : _device_id(device_id) {
|
||||||
inline aclCxt::aclCxt() {};
|
_context = static_cast<aclrtContext *>(fastMalloc(sizeof(*_context)));
|
||||||
|
AclSafeCall(aclrtCreateContext(_context, _device_id));
|
||||||
|
|
||||||
inline aclCxt::aclCxt(int device_id) : _device_id(device_id)
|
std::clog << "aclrtCreateContext() is success" << std::endl;
|
||||||
{
|
}
|
||||||
_context = static_cast<aclrtContext *>(fastMalloc(sizeof(*_context)));
|
|
||||||
AclSafeCall(aclrtCreateContext(_context, _device_id));
|
|
||||||
|
|
||||||
clog << "aclrtCreateContext() is success" << endl;
|
inline aclrtContext *aclCxt::get_context() { return _context; }
|
||||||
}
|
|
||||||
|
|
||||||
inline aclrtContext* aclCxt::get_context()
|
/**
|
||||||
{
|
* set current context
|
||||||
return _context;
|
*/
|
||||||
}
|
inline void aclCxt::set_current_context() {
|
||||||
|
AclSafeCall(aclrtSetCurrentContext(*_context));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
inline void aclCxt::create_stream(int count) {
|
||||||
* set current context
|
CV_Assert(count > 0);
|
||||||
*/
|
|
||||||
inline void aclCxt::set_current_context()
|
|
||||||
{
|
|
||||||
AclSafeCall(aclrtSetCurrentContext(*_context));
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void aclCxt::create_stream(int count)
|
int i;
|
||||||
{
|
for (i = 0; i < count; i++) {
|
||||||
CV_Assert(count > 0);
|
aclStream stream;
|
||||||
|
AclSafeCall(aclrtCreateStream(&stream));
|
||||||
|
|
||||||
int i;
|
_acl_streams.push_back(stream);
|
||||||
for(i = 0; i <count; i++)
|
}
|
||||||
{
|
|
||||||
aclStream stream;
|
|
||||||
AclSafeCall(aclrtCreateStream(&stream));
|
|
||||||
|
|
||||||
_acl_streams.push_back(stream);
|
std::clog << "aclrtCreateStream() is success" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
clog << "aclrtCreateStream() is success" << endl;
|
inline aclrtStream aclCxt::get_stream(const size_t index) {
|
||||||
}
|
CV_Assert(index < _acl_streams.size());
|
||||||
|
return _acl_streams[index];
|
||||||
|
}
|
||||||
|
|
||||||
inline aclrtStream aclCxt::get_stream(const size_t index)
|
/**
|
||||||
{
|
* destroy stream and context
|
||||||
CV_Assert(index < _acl_streams.size());
|
*/
|
||||||
return _acl_streams[index];
|
inline aclCxt::~aclCxt() {
|
||||||
}
|
size_t i = 0;
|
||||||
|
|
||||||
/**
|
AclSafeCall(aclrtSetCurrentContext(*_context));
|
||||||
* destroy stream and context
|
for (i = 0; i < _acl_streams.size(); i++) {
|
||||||
*/
|
aclStream acl_stream = _acl_streams[i];
|
||||||
inline aclCxt::~aclCxt()
|
AclSafeCall(aclrtDestroyStream(acl_stream));
|
||||||
{
|
}
|
||||||
size_t i = 0;
|
|
||||||
|
|
||||||
AclSafeCall(aclrtSetCurrentContext(*_context));
|
std::clog << "aclrtDestroyStream() is success" << std::endl;
|
||||||
for (i = 0; i < _acl_streams.size(); i++)
|
|
||||||
{
|
|
||||||
aclStream acl_stream = _acl_streams[i];
|
|
||||||
AclSafeCall(aclrtDestroyStream(acl_stream));
|
|
||||||
}
|
|
||||||
|
|
||||||
clog << "aclrtDestroyStream() is success" << endl;
|
// empty vector
|
||||||
|
std::vector<aclrtStream>().swap(_acl_streams);
|
||||||
|
AclSafeCall(aclrtDestroyContext(*_context));
|
||||||
|
|
||||||
// empty vector
|
std::clog << "aclrtDestroyContext() is success" << std::endl;
|
||||||
std::vector<aclrtStream>().swap(_acl_streams);
|
}
|
||||||
AclSafeCall(aclrtDestroyContext(*_context));
|
|
||||||
|
|
||||||
clog << "aclrtDestroyContext() is success" << endl;
|
} /* end of namespace acl */
|
||||||
}
|
|
||||||
|
|
||||||
} /* end of namespace acl */
|
|
||||||
|
|
||||||
} /* end of namespace cv */
|
} /* end of namespace cv */
|
||||||
|
|
||||||
|
@@ -3,384 +3,410 @@
|
|||||||
|
|
||||||
#include "acl_type.hpp"
|
#include "acl_type.hpp"
|
||||||
|
|
||||||
namespace cv
|
namespace cv {
|
||||||
{
|
namespace acl {
|
||||||
namespace acl
|
//////////////////////////////// aclMat ////////////////////////////////
|
||||||
{
|
inline aclMat::aclMat()
|
||||||
////////////////////////////////////////////////////////////////////////
|
: flags(0),
|
||||||
//////////////////////////////// aclMat ////////////////////////////////
|
rows(0),
|
||||||
////////////////////////////////////////////////////////////////////////
|
cols(0),
|
||||||
|
step(0),
|
||||||
|
data(nullptr),
|
||||||
|
refcount(nullptr),
|
||||||
|
datastart(nullptr),
|
||||||
|
dataend(nullptr),
|
||||||
|
offset(0),
|
||||||
|
wholerows(0),
|
||||||
|
wholecols(0),
|
||||||
|
acl_context(0),
|
||||||
|
totalSize(0) {}
|
||||||
|
|
||||||
inline aclMat::aclMat()
|
/**
|
||||||
: flags(0), rows(0), cols(0), step(0), data(nullptr), refcount(nullptr),
|
* @param [in] _acl_context: Acl context
|
||||||
datastart(nullptr), dataend(nullptr), offset(0), wholerows(0), wholecols(0), acl_context(0), totalSize(0)
|
* @param [in] config: Byte aligned or not, Default MEMORY_UNALIGNED
|
||||||
{
|
* @param [in] policy: Acl Memory Application mode, Default
|
||||||
}
|
* ACL_MEM_MALLOC_NORMAL_ONLY
|
||||||
|
*/
|
||||||
|
inline aclMat::aclMat(int _rows, int _cols, int _type, aclCxt *_acl_context,
|
||||||
|
ALIGNMENT config, MemMallocPolicy policy)
|
||||||
|
: flags(0),
|
||||||
|
rows(0),
|
||||||
|
cols(0),
|
||||||
|
step(0),
|
||||||
|
data(nullptr),
|
||||||
|
refcount(nullptr),
|
||||||
|
datastart(nullptr),
|
||||||
|
dataend(nullptr),
|
||||||
|
offset(0),
|
||||||
|
wholerows(0),
|
||||||
|
wholecols(0),
|
||||||
|
acl_context(_acl_context),
|
||||||
|
totalSize(0) {
|
||||||
|
if (_rows > 0 && _cols > 0) create(_rows, _cols, _type, config, policy);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
inline aclMat::aclMat(Size _size, int _type, aclCxt *_acl_context,
|
||||||
* @param [in] _acl_context: Acl context
|
ALIGNMENT config, MemMallocPolicy policy)
|
||||||
* @param [in] config: Byte aligned or not, Default MEMORY_UNALIGNED
|
: flags(0),
|
||||||
* @param [in] policy: Acl Memory Application mode, Default ACL_MEM_MALLOC_NORMAL_ONLY
|
rows(0),
|
||||||
*/
|
cols(0),
|
||||||
inline aclMat::aclMat(int _rows, int _cols, int _type, aclCxt *_acl_context, ALIGNMENT config, MemMallocPolicy policy)
|
step(0),
|
||||||
: flags(0), rows(0), cols(0), step(0), data(nullptr), refcount(nullptr), datastart(nullptr),
|
data(nullptr),
|
||||||
dataend(nullptr), offset(0), wholerows(0), wholecols(0), acl_context(_acl_context), totalSize(0)
|
refcount(nullptr),
|
||||||
{
|
datastart(nullptr),
|
||||||
if (_rows > 0 && _cols > 0)
|
dataend(nullptr),
|
||||||
create(_rows, _cols, _type, config, policy);
|
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)
|
inline aclMat::aclMat(const aclMat &m)
|
||||||
: flags(0), rows(0), cols(0), step(0), data(nullptr), refcount(nullptr), datastart(nullptr),
|
: flags(m.flags),
|
||||||
dataend(nullptr), offset(0), wholerows(0), wholecols(0), acl_context(_acl_context), totalSize(0)
|
rows(m.rows),
|
||||||
{
|
cols(m.cols),
|
||||||
if (_size.height > 0 && _size.width > 0)
|
step(m.step),
|
||||||
create(_size, _type, config, policy);
|
data(m.data),
|
||||||
}
|
refcount(m.refcount),
|
||||||
|
datastart(m.datastart),
|
||||||
|
dataend(m.dataend),
|
||||||
|
offset(m.offset),
|
||||||
|
wholerows(m.wholerows),
|
||||||
|
wholecols(m.wholecols),
|
||||||
|
acl_context(m.acl_context),
|
||||||
|
totalSize(m.totalSize) {
|
||||||
|
if (refcount) CV_XADD(refcount, 1);
|
||||||
|
}
|
||||||
|
|
||||||
inline aclMat::aclMat(const aclMat &m)
|
inline aclMat::aclMat(int _rows, int _cols, int _type, void *_data,
|
||||||
: flags(m.flags), rows(m.rows), cols(m.cols), step(m.step), data(m.data), refcount(m.refcount),
|
aclCxt *_acl_context, ALIGNMENT config, size_t _step)
|
||||||
datastart(m.datastart), dataend(m.dataend), offset(m.offset), wholerows(m.wholerows), wholecols(m.wholecols),
|
: flags(0),
|
||||||
acl_context(m.acl_context), totalSize(m.totalSize)
|
rows(0),
|
||||||
{
|
cols(0),
|
||||||
if (refcount)
|
step(0),
|
||||||
CV_XADD(refcount, 1);
|
data(nullptr),
|
||||||
}
|
refcount(nullptr),
|
||||||
|
datastart(nullptr),
|
||||||
|
dataend(nullptr),
|
||||||
|
offset(0),
|
||||||
|
wholerows(0),
|
||||||
|
wholecols(0),
|
||||||
|
acl_context(_acl_context),
|
||||||
|
totalSize(0) {
|
||||||
|
cv::Mat m(_rows, _cols, _type, _data, _step);
|
||||||
|
if (m.rows > 0 && m.cols > 0) create(m.rows, m.cols, m.type(), config);
|
||||||
|
upload(m, config);
|
||||||
|
}
|
||||||
|
|
||||||
inline aclMat::aclMat(int _rows, int _cols, int _type, void *_data, aclCxt *_acl_context, ALIGNMENT config, size_t _step)
|
inline aclMat::aclMat(Size _size, int _type, void *_data, aclCxt *_acl_context,
|
||||||
: flags(0), rows(0), cols(0), step(0), data(nullptr), refcount(nullptr), datastart(nullptr),
|
ALIGNMENT config, size_t _step)
|
||||||
dataend(nullptr), offset(0), wholerows(0), wholecols(0), acl_context(_acl_context), totalSize(0)
|
: flags(0),
|
||||||
{
|
rows(0),
|
||||||
cv::Mat m(_rows, _cols, _type, _data, _step);
|
cols(0),
|
||||||
if (m.rows > 0 && m.cols > 0)
|
step(0),
|
||||||
create(m.rows, m.cols, m.type(), config);
|
data(nullptr),
|
||||||
upload(m, config);
|
refcount(nullptr),
|
||||||
}
|
datastart(nullptr),
|
||||||
|
dataend(nullptr),
|
||||||
|
offset(0),
|
||||||
|
wholerows(0),
|
||||||
|
wholecols(0),
|
||||||
|
acl_context(_acl_context),
|
||||||
|
totalSize(0) {
|
||||||
|
cv::Mat m(_size, _type, _data, _step);
|
||||||
|
if (m.rows > 0 && m.cols > 0) create(m.rows, m.cols, m.type(), config);
|
||||||
|
upload(m, config);
|
||||||
|
}
|
||||||
|
|
||||||
inline aclMat::aclMat(Size _size, int _type, void *_data, aclCxt *_acl_context, ALIGNMENT config, size_t _step)
|
/**
|
||||||
: flags(0), rows(0), cols(0), step(0), data(nullptr), refcount(nullptr), datastart(nullptr),
|
* @param [in] rRange: rows begin to end, Range(start, end)
|
||||||
dataend(nullptr), offset(0), wholerows(0), wholecols(0), acl_context(_acl_context), totalSize(0)
|
* @param [in] cRange: cols begin to end, Range(start, end)
|
||||||
{
|
*/
|
||||||
cv::Mat m(_size, _type, _data, _step);
|
inline aclMat::aclMat(const aclMat &m, const Range &rRange, const Range &cRange)
|
||||||
if (m.rows > 0 && m.cols > 0)
|
: flags(m.flags),
|
||||||
create(m.rows, m.cols, m.type(), config);
|
step(m.step),
|
||||||
upload(m, config);
|
refcount(m.refcount),
|
||||||
}
|
datastart(m.datastart),
|
||||||
|
dataend(m.dataend),
|
||||||
|
offset(m.offset),
|
||||||
|
wholerows(m.wholerows),
|
||||||
|
wholecols(m.wholecols),
|
||||||
|
acl_context(m.acl_context),
|
||||||
|
totalSize(m.totalSize) {
|
||||||
|
if (rRange == Range::all())
|
||||||
|
rows = m.rows;
|
||||||
|
else {
|
||||||
|
CV_Assert(0 <= rRange.start && rRange.start <= rRange.end &&
|
||||||
|
rRange.end <= m.rows);
|
||||||
|
rows = rRange.size();
|
||||||
|
offset += step * rRange.start;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
if (cRange == Range::all())
|
||||||
* @param [in] rRange: rows begin to end, Range(start, end)
|
cols = m.cols;
|
||||||
* @param [in] cRange: cols begin to end, Range(start, end)
|
else {
|
||||||
*/
|
CV_Assert(0 <= cRange.start && cRange.start <= cRange.end &&
|
||||||
inline aclMat::aclMat(const aclMat &m, const Range &rRange, const Range &cRange)
|
cRange.end <= m.cols);
|
||||||
: flags(m.flags), step(m.step), refcount(m.refcount), datastart(m.datastart), dataend(m.dataend),
|
cols = cRange.size();
|
||||||
offset(m.offset), wholerows(m.wholerows), wholecols(m.wholecols), acl_context(m.acl_context), totalSize(m.totalSize)
|
offset += cRange.start * elemSize();
|
||||||
{
|
flags &= cols < m.cols ? ~Mat::CONTINUOUS_FLAG : -1;
|
||||||
if (rRange == Range::all())
|
}
|
||||||
rows = m.rows;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
CV_Assert(0 <= rRange.start && rRange.start <= rRange.end && rRange.end <= m.rows);
|
|
||||||
rows = rRange.size();
|
|
||||||
offset += step * rRange.start;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cRange == Range::all())
|
if (rows == 1) flags |= Mat::CONTINUOUS_FLAG;
|
||||||
cols = m.cols;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
CV_Assert(0 <= cRange.start && cRange.start <= cRange.end && cRange.end <= m.cols);
|
|
||||||
cols = cRange.size();
|
|
||||||
offset += cRange.start * elemSize();
|
|
||||||
flags &= cols < m.cols ? ~Mat::CONTINUOUS_FLAG : -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (rows == 1)
|
if (refcount) CV_XADD(refcount, 1);
|
||||||
flags |= Mat::CONTINUOUS_FLAG;
|
if (rows <= 0 || cols <= 0) rows = cols = 0;
|
||||||
|
|
||||||
if (refcount)
|
data = static_cast<void *>((static_cast<uchar *>(m.data) + offset));
|
||||||
CV_XADD(refcount, 1);
|
}
|
||||||
if (rows <= 0 || cols <= 0)
|
|
||||||
rows = cols = 0;
|
|
||||||
|
|
||||||
data = static_cast<void *>((static_cast<uchar *>(m.data) + offset));
|
/**
|
||||||
}
|
* @param [in] roi: Matrix position, Rect(x, y, width, height)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
inline aclMat::aclMat(const aclMat &m, const Rect &roi)
|
||||||
|
: flags(m.flags),
|
||||||
|
rows(roi.height),
|
||||||
|
cols(roi.width),
|
||||||
|
step(m.step),
|
||||||
|
refcount(m.refcount),
|
||||||
|
datastart(m.datastart),
|
||||||
|
dataend(m.dataend),
|
||||||
|
offset(m.offset),
|
||||||
|
wholerows(m.wholerows),
|
||||||
|
wholecols(m.wholecols),
|
||||||
|
acl_context(m.acl_context),
|
||||||
|
totalSize(m.totalSize) {
|
||||||
|
flags &= roi.width < m.cols ? ~Mat::CONTINUOUS_FLAG : -1;
|
||||||
|
offset += roi.y * step + roi.x * elemSize();
|
||||||
|
CV_Assert(0 <= roi.x && 0 <= roi.width && roi.x + roi.width <= m.wholecols &&
|
||||||
|
0 <= roi.y && 0 <= roi.height && roi.y + roi.height <= m.wholerows);
|
||||||
|
if (refcount) CV_XADD(refcount, 1);
|
||||||
|
if (rows <= 0 || cols <= 0) rows = cols = 0;
|
||||||
|
|
||||||
/**
|
data = static_cast<void *>((static_cast<uchar *>(m.data) + offset));
|
||||||
* @param [in] roi: Matrix position, Rect(x, y, width, height)
|
}
|
||||||
*
|
|
||||||
*/
|
|
||||||
inline aclMat::aclMat(const aclMat &m, const Rect &roi)
|
|
||||||
: flags(m.flags), rows(roi.height), cols(roi.width), step(m.step), refcount(m.refcount), datastart(m.datastart),
|
|
||||||
dataend(m.dataend), offset(m.offset), wholerows(m.wholerows), wholecols(m.wholecols), acl_context(m.acl_context),
|
|
||||||
totalSize(m.totalSize)
|
|
||||||
{
|
|
||||||
flags &= roi.width < m.cols ? ~Mat::CONTINUOUS_FLAG : -1;
|
|
||||||
offset += roi.y * step + roi.x * elemSize();
|
|
||||||
CV_Assert(0 <= roi.x && 0 <= roi.width && roi.x + roi.width <= m.wholecols &&
|
|
||||||
0 <= roi.y && 0 <= roi.height && roi.y + roi.height <= m.wholerows);
|
|
||||||
if (refcount)
|
|
||||||
CV_XADD(refcount, 1);
|
|
||||||
if (rows <= 0 || cols <= 0)
|
|
||||||
rows = cols = 0;
|
|
||||||
|
|
||||||
data = static_cast<void *>((static_cast<uchar *>(m.data) + offset));
|
inline aclMat::aclMat(const Mat &m, aclCxt *_acl_context, ALIGNMENT config,
|
||||||
}
|
MemMallocPolicy policy)
|
||||||
|
: flags(0),
|
||||||
|
rows(m.rows),
|
||||||
|
cols(m.cols),
|
||||||
|
step(0),
|
||||||
|
data(nullptr),
|
||||||
|
refcount(nullptr),
|
||||||
|
datastart(nullptr),
|
||||||
|
dataend(nullptr),
|
||||||
|
offset(0),
|
||||||
|
wholerows(0),
|
||||||
|
wholecols(0),
|
||||||
|
acl_context(_acl_context),
|
||||||
|
totalSize(0) {
|
||||||
|
if (m.rows > 0 && m.cols > 0)
|
||||||
|
create(m.rows, m.cols, m.type(), config, policy);
|
||||||
|
upload(m, config);
|
||||||
|
}
|
||||||
|
|
||||||
inline aclMat::aclMat(const Mat &m, aclCxt *_acl_context, ALIGNMENT config, MemMallocPolicy policy)
|
inline aclMat::~aclMat() {
|
||||||
: flags(0), rows(m.rows), cols(m.cols), step(0), data(nullptr), refcount(nullptr), datastart(nullptr),
|
if (refcount) release();
|
||||||
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()
|
inline aclMat &aclMat::operator=(const aclMat &m) {
|
||||||
{
|
if (this != &m) {
|
||||||
if (refcount)
|
if (refcount) release();
|
||||||
release();
|
flags = m.flags;
|
||||||
}
|
rows = m.rows;
|
||||||
|
cols = m.cols;
|
||||||
|
step = m.step;
|
||||||
|
datastart = m.datastart;
|
||||||
|
dataend = m.dataend;
|
||||||
|
offset = m.offset;
|
||||||
|
wholerows = m.wholerows;
|
||||||
|
wholecols = m.wholecols;
|
||||||
|
refcount = m.refcount;
|
||||||
|
acl_context = m.acl_context;
|
||||||
|
totalSize = m.totalSize;
|
||||||
|
data = m.data;
|
||||||
|
if (m.refcount) CV_XADD(m.refcount, 1);
|
||||||
|
}
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
inline aclMat &aclMat::operator=(const aclMat &m)
|
inline aclMat &aclMat::operator=(const Mat &m) {
|
||||||
{
|
upload(m);
|
||||||
if (this != &m)
|
return *this;
|
||||||
{
|
}
|
||||||
|
|
||||||
if (refcount)
|
inline aclMat::operator Mat() const {
|
||||||
release();
|
Mat m(rows, cols, type());
|
||||||
flags = m.flags;
|
download(m);
|
||||||
rows = m.rows;
|
return m;
|
||||||
cols = m.cols;
|
}
|
||||||
step = m.step;
|
|
||||||
datastart = m.datastart;
|
|
||||||
dataend = m.dataend;
|
|
||||||
offset = m.offset;
|
|
||||||
wholerows = m.wholerows;
|
|
||||||
wholecols = m.wholecols;
|
|
||||||
refcount = m.refcount;
|
|
||||||
acl_context = m.acl_context;
|
|
||||||
totalSize = m.totalSize;
|
|
||||||
data = m.data;
|
|
||||||
if (m.refcount)
|
|
||||||
CV_XADD(m.refcount, 1);
|
|
||||||
}
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline aclMat& aclMat::operator=(const Mat &m)
|
inline aclMat aclMat::clone() const {
|
||||||
{
|
aclMat m;
|
||||||
upload(m);
|
copyTo(m);
|
||||||
return *this;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline aclMat::operator Mat() const
|
inline void aclMat::copyTo(aclMat &dest) const {
|
||||||
{
|
if (this != &dest) {
|
||||||
Mat m(rows, cols, type());
|
dest.rows = rows;
|
||||||
download(m);
|
dest.cols = cols;
|
||||||
return m;
|
dest.step = step;
|
||||||
}
|
dest.wholerows = wholerows;
|
||||||
|
dest.wholecols = wholecols;
|
||||||
|
dest.refcount = refcount;
|
||||||
|
dest.acl_context = acl_context;
|
||||||
|
dest.totalSize = totalSize;
|
||||||
|
|
||||||
inline aclMat aclMat::clone() const
|
void *dev_ptr;
|
||||||
{
|
AclSafeCall(
|
||||||
aclMat m;
|
aclrtMalloc(&dev_ptr, totalSize, type_transition(MALLOC_NORMAL_ONLY)));
|
||||||
copyTo(m);
|
AclSafeCall(aclrtMemcpy(dev_ptr, totalSize, data, totalSize,
|
||||||
return m;
|
ACL_MEMCPY_DEVICE_TO_DEVICE));
|
||||||
}
|
|
||||||
|
|
||||||
inline void aclMat::copyTo(aclMat& dest) const
|
dest.data = dev_ptr;
|
||||||
{
|
dest.datastart = static_cast<uchar *>(data);
|
||||||
if (this != &dest)
|
dest.dataend = static_cast<uchar *>(data) + totalSize;
|
||||||
{
|
dest.refcount = static_cast<int *>(fastMalloc(sizeof(*refcount)));
|
||||||
dest.rows = rows;
|
*refcount = 0;
|
||||||
dest.cols = cols;
|
CV_XADD(refcount, 1);
|
||||||
dest.step = step;
|
dest.flags |= Mat::CONTINUOUS_FLAG;
|
||||||
dest.wholerows = wholerows;
|
}
|
||||||
dest.wholecols = wholecols;
|
}
|
||||||
dest.refcount = refcount;
|
|
||||||
dest.acl_context = acl_context;
|
|
||||||
dest.totalSize = totalSize;
|
|
||||||
|
|
||||||
void *dev_ptr;
|
inline aclMat aclMat::row(int y) const {
|
||||||
AclSafeCall(aclrtMalloc(&dev_ptr, totalSize, type_transition(MALLOC_NORMAL_ONLY)));
|
return aclMat(*this, Range(y, y + 1), Range::all());
|
||||||
AclSafeCall(aclrtMemcpy(dev_ptr, totalSize, data, totalSize, ACL_MEMCPY_DEVICE_TO_DEVICE));
|
}
|
||||||
|
|
||||||
dest.data = dev_ptr;
|
inline aclMat aclMat::col(int x) const {
|
||||||
dest.datastart = static_cast<uchar *>(data);
|
return aclMat(*this, Range::all(), Range(x, x + 1));
|
||||||
dest.dataend = static_cast<uchar *>(data) + totalSize;
|
}
|
||||||
dest.refcount = static_cast<int *>(fastMalloc(sizeof(*refcount)));
|
|
||||||
*refcount = 0;
|
|
||||||
CV_XADD(refcount, 1);
|
|
||||||
dest.flags |= Mat::CONTINUOUS_FLAG;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
inline aclMat aclMat::row(int y) const
|
inline aclMat aclMat::rowRange(int startrow, int endrow) const {
|
||||||
{
|
return aclMat(*this, Range(startrow, endrow), Range::all());
|
||||||
return aclMat(*this, Range(y, y + 1), Range::all());
|
}
|
||||||
}
|
|
||||||
|
|
||||||
inline aclMat aclMat::col(int x) const
|
inline aclMat aclMat::rowRange(const Range &r) const {
|
||||||
{
|
return aclMat(*this, r, Range::all());
|
||||||
return aclMat(*this, Range::all(), Range(x, x + 1));
|
}
|
||||||
}
|
|
||||||
|
|
||||||
inline aclMat aclMat::rowRange(int startrow, int endrow) const
|
inline aclMat aclMat::colRange(int startcol, int endcol) const {
|
||||||
{
|
return aclMat(*this, Range::all(), Range(startcol, endcol));
|
||||||
return aclMat(*this, Range(startrow, endrow), Range::all());
|
}
|
||||||
}
|
|
||||||
|
|
||||||
inline aclMat aclMat::rowRange(const Range &r) const
|
inline aclMat aclMat::colRange(const Range &r) const {
|
||||||
{
|
return aclMat(*this, Range::all(), r);
|
||||||
return aclMat(*this, r, Range::all());
|
}
|
||||||
}
|
|
||||||
|
|
||||||
inline aclMat aclMat::colRange(int startcol, int endcol) const
|
inline void aclMat::locateROI(Size &wholeSize, Point &ofs) const {
|
||||||
{
|
size_t esz = elemSize();
|
||||||
return aclMat(*this, Range::all(), Range(startcol, endcol));
|
CV_DbgAssert(step > 0);
|
||||||
}
|
if (offset == 0)
|
||||||
|
ofs.x = ofs.y = 0;
|
||||||
|
else {
|
||||||
|
ofs.y = (int)(offset / step);
|
||||||
|
ofs.x = (int)((offset - step * ofs.y) / esz);
|
||||||
|
CV_DbgAssert(data == (datastart + ofs.y * step + ofs.x * esz));
|
||||||
|
}
|
||||||
|
wholeSize.height = wholerows;
|
||||||
|
wholeSize.width = wholecols;
|
||||||
|
}
|
||||||
|
|
||||||
inline aclMat aclMat::colRange(const Range &r) const
|
inline aclMat &aclMat::adjustROI(int dtop, int dbottom, int dleft, int dright) {
|
||||||
{
|
Size wholeSize;
|
||||||
return aclMat(*this, Range::all(), r);
|
Point ofs;
|
||||||
}
|
size_t esz = elemSize();
|
||||||
|
locateROI(wholeSize, ofs);
|
||||||
|
int row1 = std::max(ofs.y - dtop, 0),
|
||||||
|
row2 = std::min(ofs.y + rows + dbottom, wholeSize.height);
|
||||||
|
int col1 = std::max(ofs.x - dleft, 0),
|
||||||
|
col2 = std::min(ofs.x + cols + dright, wholeSize.width);
|
||||||
|
offset += (row1 - ofs.y) * step + (col1 - ofs.x) * esz;
|
||||||
|
rows = row2 - row1;
|
||||||
|
cols = col2 - col1;
|
||||||
|
if (esz * cols == step || rows == 1)
|
||||||
|
flags |= Mat::CONTINUOUS_FLAG;
|
||||||
|
else
|
||||||
|
flags &= ~Mat::CONTINUOUS_FLAG;
|
||||||
|
|
||||||
inline void aclMat::locateROI( Size &wholeSize, Point &ofs ) const
|
data = static_cast<void *>((static_cast<uchar *>(datastart) + offset));
|
||||||
{
|
return *this;
|
||||||
size_t esz = elemSize();
|
}
|
||||||
CV_DbgAssert(step > 0);
|
|
||||||
if(offset == 0)
|
|
||||||
ofs.x = ofs.y = 0;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ofs.y = (int)(offset / step);
|
|
||||||
ofs.x = (int)((offset - step * ofs.y) / esz);
|
|
||||||
CV_DbgAssert(data == (datastart + ofs.y * step + ofs.x * esz));
|
|
||||||
}
|
|
||||||
wholeSize.height = wholerows;
|
|
||||||
wholeSize.width = wholecols;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline aclMat &aclMat::adjustROI( int dtop, int dbottom, int dleft, int dright )
|
inline void aclMat::swap(aclMat &b) {
|
||||||
{
|
std::swap(flags, b.flags);
|
||||||
Size wholeSize;
|
std::swap(rows, b.rows);
|
||||||
Point ofs;
|
std::swap(cols, b.cols);
|
||||||
size_t esz = elemSize();
|
std::swap(step, b.step);
|
||||||
locateROI( wholeSize, ofs );
|
std::swap(data, b.data);
|
||||||
int row1 = std::max(ofs.y - dtop, 0), row2 = std::min(ofs.y + rows + dbottom, wholeSize.height);
|
std::swap(datastart, b.datastart);
|
||||||
int col1 = std::max(ofs.x - dleft, 0), col2 = std::min(ofs.x + cols + dright, wholeSize.width);
|
std::swap(dataend, b.dataend);
|
||||||
offset += (row1 - ofs.y) * step + (col1 - ofs.x) * esz;
|
std::swap(refcount, b.refcount);
|
||||||
rows = row2 - row1;
|
std::swap(offset, b.offset);
|
||||||
cols = col2 - col1;
|
std::swap(wholerows, b.wholerows);
|
||||||
if( esz * cols == step || rows == 1 )
|
std::swap(wholecols, b.wholecols);
|
||||||
flags |= Mat::CONTINUOUS_FLAG;
|
std::swap(acl_context, b.acl_context);
|
||||||
else
|
std::swap(totalSize, b.totalSize);
|
||||||
flags &= ~Mat::CONTINUOUS_FLAG;
|
}
|
||||||
|
|
||||||
data = static_cast<void *>((static_cast<uchar *>(datastart) + offset));
|
inline aclMat aclMat::operator()(Range rRange, Range cRange) const {
|
||||||
return *this;
|
return aclMat(*this, rRange, cRange);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void aclMat::swap(aclMat &b)
|
inline aclMat aclMat::operator()(const Rect &roi) const {
|
||||||
{
|
return aclMat(*this, roi);
|
||||||
std::swap( flags, b.flags );
|
}
|
||||||
std::swap( rows, b.rows );
|
|
||||||
std::swap( cols, b.cols );
|
|
||||||
std::swap( step, b.step );
|
|
||||||
std::swap( data, b.data );
|
|
||||||
std::swap( datastart, b.datastart );
|
|
||||||
std::swap( dataend, b.dataend );
|
|
||||||
std::swap( refcount, b.refcount );
|
|
||||||
std::swap( offset, b.offset );
|
|
||||||
std::swap( wholerows, b.wholerows );
|
|
||||||
std::swap( wholecols, b.wholecols );
|
|
||||||
std::swap( acl_context, b.acl_context);
|
|
||||||
std::swap( totalSize, b.totalSize);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline aclMat aclMat::operator()( Range rRange, Range cRange ) const
|
inline bool aclMat::isContinuous() const {
|
||||||
{
|
return (flags & Mat::CONTINUOUS_FLAG) != 0;
|
||||||
return aclMat(*this, rRange, cRange);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
inline aclMat aclMat::operator()( const Rect &roi ) const
|
inline size_t aclMat::elemSize() const {
|
||||||
{
|
return CV_ELEM_SIZE((CV_MAKE_TYPE(type(), channels())));
|
||||||
return aclMat(*this, roi);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
inline bool aclMat::isContinuous() const
|
inline size_t aclMat::elemSize1() const { return CV_ELEM_SIZE1(flags); }
|
||||||
{
|
|
||||||
return (flags & Mat::CONTINUOUS_FLAG) != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline size_t aclMat::elemSize() const
|
inline int aclMat::type() const { return CV_MAT_TYPE(flags); }
|
||||||
{
|
|
||||||
return CV_ELEM_SIZE((CV_MAKE_TYPE(type(), channels())));
|
|
||||||
}
|
|
||||||
|
|
||||||
inline size_t aclMat::elemSize1() const
|
inline int aclMat::acltype() const {
|
||||||
{
|
return CV_MAKE_TYPE(depth(), aclchannels());
|
||||||
return CV_ELEM_SIZE1(flags);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
inline int aclMat::type() const
|
inline int aclMat::depth() const { return CV_MAT_DEPTH(flags); }
|
||||||
{
|
|
||||||
return CV_MAT_TYPE(flags);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline int aclMat::acltype() const
|
inline int aclMat::channels() const { return CV_MAT_CN(flags); }
|
||||||
{
|
|
||||||
return CV_MAKE_TYPE(depth(), aclchannels());
|
|
||||||
}
|
|
||||||
|
|
||||||
inline int aclMat::depth() const
|
inline int aclMat::aclchannels() const {
|
||||||
{
|
return (CV_MAT_CN(flags)) == 3 ? 4 : (CV_MAT_CN(flags));
|
||||||
return CV_MAT_DEPTH(flags);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
inline int aclMat::channels() const
|
inline size_t aclMat::step1() const { return step / elemSize1(); }
|
||||||
{
|
|
||||||
return CV_MAT_CN(flags);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline int aclMat::aclchannels() const
|
inline Size aclMat::size() const { return Size(cols, rows); }
|
||||||
{
|
|
||||||
return (CV_MAT_CN(flags)) == 3 ? 4 : (CV_MAT_CN(flags));
|
|
||||||
}
|
|
||||||
|
|
||||||
inline size_t aclMat::step1() const
|
inline bool aclMat::empty() const { return data == 0; }
|
||||||
{
|
|
||||||
return step / elemSize1();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Size aclMat::size() const
|
inline void swap(aclMat &a, aclMat &b) { a.swap(b); }
|
||||||
{
|
|
||||||
return Size(cols, rows);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool aclMat::empty() const
|
inline void ensureSizeIsEnough(int rows, int cols, int type, aclMat &m,
|
||||||
{
|
ALIGNMENT config) {
|
||||||
return data == 0;
|
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 swap( aclMat &a, aclMat &b )
|
inline void ensureSizeIsEnough(Size size, int type, ALIGNMENT config,
|
||||||
{
|
aclMat &m) {
|
||||||
a.swap(b);
|
ensureSizeIsEnough(size.height, size.width, type, m, config);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void ensureSizeIsEnough(int rows, int cols, int type, aclMat &m, ALIGNMENT config)
|
} /* end of namespace acl */
|
||||||
{
|
|
||||||
if (m.type() == type && m.rows >= rows && m.cols >= cols)
|
|
||||||
m = m(Rect(0, 0, cols, rows));
|
|
||||||
else
|
|
||||||
m.create(rows, cols, type, config);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void ensureSizeIsEnough(Size size, int type, ALIGNMENT config, aclMat &m)
|
|
||||||
{
|
|
||||||
ensureSizeIsEnough(size.height, size.width, type, m, config);
|
|
||||||
}
|
|
||||||
|
|
||||||
} /* end of namespace acl */
|
|
||||||
|
|
||||||
} /* end of namespace cv */
|
} /* end of namespace cv */
|
||||||
|
|
||||||
|
@@ -7,20 +7,23 @@
|
|||||||
* mathfunctions;
|
* mathfunctions;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace cv
|
namespace cv {
|
||||||
{
|
namespace acl {
|
||||||
namespace acl
|
CV_EXPORTS aclMat abs(const aclMat &src, int stream_id = 0);
|
||||||
{
|
CV_EXPORTS void pow(const aclMat &src, double power, aclMat &dest,
|
||||||
CV_EXPORTS aclMat abs(const aclMat &src, int stream_id = 0);
|
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 sqrt(const aclMat &src, aclMat &dest, int stream_id = 0);
|
CV_EXPORTS void add(const aclMat &src, const aclMat &other_src, aclMat &dest,
|
||||||
CV_EXPORTS void add(const aclMat &src, const aclMat &other_src, aclMat &dest, int stream_id = 0);
|
int stream_id = 0);
|
||||||
CV_EXPORTS void divide(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,
|
||||||
CV_EXPORTS void exp(const aclMat &src, aclMat &dest, int stream_id = 0);
|
int stream_id = 0);
|
||||||
CV_EXPORTS void log(const aclMat &src, aclMat &dest, int stream_id = 0);
|
CV_EXPORTS void exp(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 log(const aclMat &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,
|
||||||
} /* end of namespace acl */
|
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 */
|
} /* end of namespace cv */
|
||||||
|
|
||||||
|
@@ -3,20 +3,17 @@
|
|||||||
|
|
||||||
#include "acl_mat.hpp"
|
#include "acl_mat.hpp"
|
||||||
|
|
||||||
namespace cv
|
namespace cv {
|
||||||
{
|
namespace acl {
|
||||||
namespace acl
|
// Multiple channel merge
|
||||||
{
|
CV_EXPORTS void merge(const std::vector<aclMat> &mv, aclMat &dst, int stream_id = 0);
|
||||||
// Matrix lookup table
|
// Split into channels
|
||||||
//CV_EXPORTS void lookUpTable(const aclMat& src, const aclMat& lut, aclMat& dst);
|
CV_EXPORTS void split(const aclMat &src, std::vector<aclMat> &mv, int stream_id = 0);
|
||||||
// Multiple channel merge
|
// Matrix transpose
|
||||||
CV_EXPORTS void merge(const vector<aclMat>& mv, aclMat& dst, int stream_id = 0);
|
CV_EXPORTS void transpose(const aclMat &src, aclMat &dest, int stream_id = 0);
|
||||||
// Split into channels
|
CV_EXPORTS void flip(const aclMat &src, aclMat &dest, int flipCode = 0,
|
||||||
CV_EXPORTS void split(const aclMat& src, vector<aclMat>& mv, int stream_id = 0);
|
int stream_id = 0);
|
||||||
// Matrix transpose
|
} /* end of namespace acl */
|
||||||
CV_EXPORTS void transpose(const aclMat& src, aclMat& dest, int stream_id = 0);
|
|
||||||
CV_EXPORTS void flip(const aclMat& src, aclMat& dest, int flipCode = 0, int stream_id = 0);
|
|
||||||
} /* end of namespace acl */
|
|
||||||
|
|
||||||
} /* end of namespace cv */
|
} /* end of namespace cv */
|
||||||
|
|
||||||
|
@@ -4,90 +4,96 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "acl_type.hpp"
|
#include "acl/acl.h"
|
||||||
#include "acl_init.hpp"
|
#include "acl_init.hpp"
|
||||||
#include "acl_mat.hpp"
|
#include "acl_mat.hpp"
|
||||||
#include "acl/acl.h"
|
#include "acl_type.hpp"
|
||||||
|
|
||||||
namespace cv
|
namespace cv {
|
||||||
{
|
namespace acl {
|
||||||
namespace acl
|
class CV_EXPORTS OperatorDesc {
|
||||||
{
|
public:
|
||||||
class CV_EXPORTS OperatorDesc
|
/**
|
||||||
{
|
* Constructor
|
||||||
public:
|
* @param [in] opType: op type
|
||||||
/**
|
*/
|
||||||
* Constructor
|
OperatorDesc(std::string opType);
|
||||||
* @param [in] opType: op type
|
|
||||||
*/
|
|
||||||
OperatorDesc(std::string opType);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Destructor
|
* Destructor
|
||||||
*/
|
*/
|
||||||
virtual ~OperatorDesc();
|
virtual ~OperatorDesc();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add an input tensor description
|
* Add an input tensor description
|
||||||
* @param [in] dataType: data type
|
* @param [in] dataType: data type
|
||||||
* @param [in] numDims: number of dims
|
* @param [in] numDims: number of dims
|
||||||
* @param [in] dims: dims
|
* @param [in] dims: dims
|
||||||
* @param [in] format: format
|
* @param [in] format: format
|
||||||
* @return OperatorDesc
|
* @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
|
* Add an output tensor description
|
||||||
* @param [in] dataType: data type
|
* @param [in] dataType: data type
|
||||||
* @param [in] numDims: number of dims
|
* @param [in] numDims: number of dims
|
||||||
* @param [in] dims: dims
|
* @param [in] dims: dims
|
||||||
* @param [in] format: format
|
* @param [in] format: format
|
||||||
* @return OperatorDesc
|
* @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>
|
template <typename T>
|
||||||
bool AddTensorAttr(const char *attrName, AttrType type, T vaule)
|
bool AddTensorAttr(const char *attrName, AttrType type, T vaule) {
|
||||||
{
|
if (opAttr == nullptr) return false;
|
||||||
if (opAttr == nullptr)
|
switch (type) {
|
||||||
return false;
|
case OP_BOOL:
|
||||||
switch (type)
|
aclopSetAttrBool(opAttr, attrName, vaule);
|
||||||
{
|
break;
|
||||||
case OP_BOOL:
|
case OP_INT:
|
||||||
aclopSetAttrBool(opAttr, attrName, vaule);
|
aclopSetAttrInt(opAttr, attrName, vaule);
|
||||||
break;
|
break;
|
||||||
case OP_INT:
|
case OP_FLOAT:
|
||||||
aclopSetAttrInt(opAttr, attrName, vaule);
|
aclopSetAttrFloat(opAttr, attrName, vaule);
|
||||||
break;
|
break;
|
||||||
case OP_FLOAT:
|
default:
|
||||||
aclopSetAttrFloat(opAttr, attrName, vaule);
|
break;
|
||||||
break;
|
}
|
||||||
default:
|
return true;
|
||||||
break;
|
}
|
||||||
}
|
std::string opType;
|
||||||
return true;
|
std::vector<aclTensorDesc *> inputDesc;
|
||||||
}
|
std::vector<aclTensorDesc *> outputDesc;
|
||||||
std::string opType;
|
aclopAttr *opAttr;
|
||||||
std::vector<aclTensorDesc *> inputDesc;
|
};
|
||||||
std::vector<aclTensorDesc *> outputDesc;
|
|
||||||
aclopAttr *opAttr;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
// Create operator description
|
||||||
|
CV_EXPORTS OperatorDesc CreateOpDesc(const std::string opType,
|
||||||
|
const std::vector<aclMat> &input_Mat,
|
||||||
|
std::vector<aclMat> &output_Mat,
|
||||||
|
aclFormat format = ACL_FORMAT_NHWC,
|
||||||
|
Opdims config = FOUR_DIMS);
|
||||||
|
// Compile and run the operator
|
||||||
|
CV_EXPORTS void compileAndRunop(OperatorDesc &opDesc,
|
||||||
|
std::vector<aclDataBuffer *> &inputBuffers_,
|
||||||
|
std::vector<aclDataBuffer *> &outputBuffers_,
|
||||||
|
aclCxt *acl_context, int stream_id);
|
||||||
|
// Suitable for one input and one output
|
||||||
|
CV_EXPORTS void OneInAndOneOut(const aclMat &input, aclMat &output,
|
||||||
|
const std::string opType, int stream_id = 0);
|
||||||
|
// Suitable for tow input and one output
|
||||||
|
CV_EXPORTS void TwoInAndOneOut(const aclMat &inputMat,
|
||||||
|
const aclMat &inputMatOther, aclMat &outputMat,
|
||||||
|
const std::string opType, int stream_id = 0);
|
||||||
|
// run the operator
|
||||||
|
CV_EXPORTS void Runop(std::vector<aclMat> &input, std::vector<aclMat> &output,
|
||||||
|
OperatorDesc &opDesc, int stream_id);
|
||||||
|
|
||||||
// Create operator description
|
} /* end of namespace acl */
|
||||||
CV_EXPORTS OperatorDesc CreateOpDesc(const string opType, const vector<aclMat> &input_Mat, vector<aclMat> &output_Mat, aclFormat format = ACL_FORMAT_NHWC, Opdims config = FOUR_DIMS);
|
|
||||||
// Compile and run the operator
|
|
||||||
CV_EXPORTS void compileAndRunop(OperatorDesc &opDesc, vector<aclDataBuffer *> &inputBuffers_, vector<aclDataBuffer *> &outputBuffers_, aclCxt *acl_context, int stream_id);
|
|
||||||
// Suitable for one input and one output
|
|
||||||
CV_EXPORTS void OneInAndOneOut(const aclMat &input, aclMat &output, const string opType, int stream_id = 0);
|
|
||||||
// Suitable for tow input and one output
|
|
||||||
CV_EXPORTS void TwoInAndOneOut(const aclMat &inputMat, const aclMat &inputMatOther, aclMat &outputMat, const string opType, int stream_id = 0);
|
|
||||||
// run the operator
|
|
||||||
CV_EXPORTS void Runop(vector<aclMat> &input, vector<aclMat> &output, OperatorDesc &opDesc, int stream_id);
|
|
||||||
|
|
||||||
} /* end of namespace acl */
|
|
||||||
|
|
||||||
} /* end of namespace cv */
|
} /* end of namespace cv */
|
||||||
|
|
||||||
#endif // OPERATOR_DESC_HPP
|
#endif // OPERATOR_DESC_HPP
|
||||||
|
@@ -1,8 +1,9 @@
|
|||||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
/* M///////////////////////////////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
// 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,
|
// If you do not agree to this license, do not download, install,
|
||||||
// copy or use the software.
|
// copy or use the software.
|
||||||
//
|
//
|
||||||
@@ -10,28 +11,35 @@
|
|||||||
// License Agreement
|
// License Agreement
|
||||||
// For Open Source Computer Vision Library
|
// 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, Advanced Micro Devices, Inc., all rights reserved.
|
||||||
// Copyright (C) 2010-2012, Multicoreware, Inc., all rights reserved.
|
// Copyright (C) 2010-2012, Multicoreware, Inc., all rights reserved.
|
||||||
// Third party copyrights are property of their respective owners.
|
// 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:
|
// are permitted provided that the following conditions are met:
|
||||||
//
|
//
|
||||||
// * Redistribution's of source code must retain the above copyright notice,
|
// * Redistribution's of source code must retain the above copyright notice,
|
||||||
// this list of conditions and the following disclaimer.
|
// 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
|
// this list of conditions and the following disclaimer in the documentation
|
||||||
// and/or other materials provided with the distribution.
|
// 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.
|
// 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
|
// any express or implied warranties, including, but not limited to, the implied
|
||||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
// warranties of merchantability and fitness for a particular purpose are
|
||||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
disclaimed.
|
||||||
|
// In no event shall the Intel Corporation or contributors be liable for any
|
||||||
|
direct,
|
||||||
// indirect, incidental, special, exemplary, or consequential damages
|
// indirect, incidental, special, exemplary, or consequential damages
|
||||||
// (including, but not limited to, procurement of substitute goods or services;
|
// (including, but not limited to, procurement of substitute goods or services;
|
||||||
// loss of use, data, or profits; or business interruption) however caused
|
// loss of use, data, or profits; or business interruption) however caused
|
||||||
@@ -39,85 +47,74 @@
|
|||||||
// or tort (including negligence or otherwise) arising in any way out of
|
// 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.
|
// the use of this software, even if advised of the possibility of such damage.
|
||||||
//
|
//
|
||||||
//M*/
|
//M */
|
||||||
#include "precomp.hpp"
|
#include "precomp.hpp"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
using namespace cv;
|
||||||
|
using namespace cv::acl;
|
||||||
|
namespace cv {
|
||||||
|
namespace acl {
|
||||||
|
///////////////////////////aclEnv//////////////////////////////////
|
||||||
|
static Mutex *__initmutex = NULL;
|
||||||
|
Mutex &getInitMutex() {
|
||||||
|
if (__initmutex == NULL) __initmutex = new Mutex();
|
||||||
|
return *__initmutex;
|
||||||
|
}
|
||||||
|
|
||||||
|
aclEnv *global_aclenv = nullptr;
|
||||||
|
aclEnv *aclEnv::get_acl_env(const char *config_path) {
|
||||||
|
if (nullptr == global_aclenv) {
|
||||||
|
AutoLock lock(getInitMutex());
|
||||||
|
if (nullptr == global_aclenv) global_aclenv = new aclEnv(config_path);
|
||||||
|
}
|
||||||
|
return global_aclenv;
|
||||||
|
}
|
||||||
|
|
||||||
namespace cv
|
void wait_stream(aclCxt *acl_context, const int stream_id) {
|
||||||
{
|
aclrtSynchronizeStream(acl_context->get_stream(stream_id));
|
||||||
namespace acl
|
}
|
||||||
{
|
|
||||||
///////////////////////////aclEnv//////////////////////////////////
|
|
||||||
static Mutex *__initmutex = NULL;
|
|
||||||
Mutex &getInitMutex()
|
|
||||||
{
|
|
||||||
if (__initmutex == NULL)
|
|
||||||
__initmutex = new Mutex();
|
|
||||||
return *__initmutex;
|
|
||||||
}
|
|
||||||
|
|
||||||
aclEnv *global_aclenv = nullptr;
|
/////////////////////////create acl context////////////////////////
|
||||||
aclEnv* aclEnv::get_acl_env(const char* config_path)
|
/**
|
||||||
{
|
* @brief: set device and stream
|
||||||
if (nullptr == global_aclenv)
|
* @param [in] config_path: ajson path
|
||||||
{
|
* @param [in] device_id: device id
|
||||||
AutoLock lock(getInitMutex());
|
* @param [in] stream_count: stream count
|
||||||
if (nullptr == global_aclenv)
|
*/
|
||||||
global_aclenv = new aclEnv(config_path);
|
aclCxt *set_device(const char *config_path, int device_id, int stream_count) {
|
||||||
}
|
aclEnv *acl_env = aclEnv::get_acl_env(config_path);
|
||||||
return global_aclenv;
|
if (global_aclenv->refcount) {
|
||||||
}
|
AutoLock lock(getInitMutex());
|
||||||
|
CV_XADD(global_aclenv->refcount, 1);
|
||||||
|
}
|
||||||
|
int device_count = acl_env->get_device_count();
|
||||||
|
CV_Assert(device_id < device_count);
|
||||||
|
|
||||||
void wait_stream(aclCxt * acl_context, const int stream_id)
|
aclCxt *acl_context = new aclCxt(device_id);
|
||||||
{
|
acl_context->set_current_context();
|
||||||
aclrtSynchronizeStream(acl_context->get_stream(stream_id));
|
acl_context->create_stream(stream_count);
|
||||||
}
|
|
||||||
|
|
||||||
/////////////////////////create acl context////////////////////////
|
clog << "set_device() is success" << endl;
|
||||||
/**
|
return acl_context;
|
||||||
* @brief: set device and stream
|
}
|
||||||
* @param [in] config_path: ajson path
|
|
||||||
* @param [in] device_id: device id
|
|
||||||
* @param [in] stream_count: stream count
|
|
||||||
*/
|
|
||||||
aclCxt *set_device(const char* config_path, int device_id, int stream_count)
|
|
||||||
{
|
|
||||||
aclEnv *acl_env = aclEnv::get_acl_env(config_path);
|
|
||||||
if (global_aclenv->refcount) {
|
|
||||||
AutoLock lock(getInitMutex());
|
|
||||||
CV_XADD(global_aclenv->refcount, 1);
|
|
||||||
}
|
|
||||||
int device_count = acl_env->get_device_count();
|
|
||||||
CV_Assert(device_id < device_count);
|
|
||||||
|
|
||||||
aclCxt *acl_context = new aclCxt(device_id);
|
void release_device(aclCxt *context) {
|
||||||
acl_context->set_current_context();
|
CV_Assert(context);
|
||||||
acl_context->create_stream(stream_count);
|
delete context;
|
||||||
|
context = nullptr;
|
||||||
|
if (global_aclenv->refcount) {
|
||||||
|
AutoLock lock(getInitMutex());
|
||||||
|
CV_XADD(global_aclenv->refcount, -1);
|
||||||
|
|
||||||
clog << "set_device() is success" << endl;
|
if (*(global_aclenv->refcount) == 0) {
|
||||||
return acl_context;
|
delete global_aclenv;
|
||||||
}
|
global_aclenv = nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
clog << "release_device() is success" << endl;
|
||||||
|
}
|
||||||
|
|
||||||
void release_device(aclCxt* context)
|
} /* end of namespace acl */
|
||||||
{
|
|
||||||
CV_Assert(context);
|
|
||||||
delete context;
|
|
||||||
context = nullptr;
|
|
||||||
if (global_aclenv->refcount)
|
|
||||||
{
|
|
||||||
AutoLock lock(getInitMutex());
|
|
||||||
CV_XADD(global_aclenv->refcount, -1);
|
|
||||||
|
|
||||||
if (*(global_aclenv->refcount) == 0)
|
|
||||||
{
|
|
||||||
delete global_aclenv;
|
|
||||||
global_aclenv = nullptr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
clog << "release_device() is success" << endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
} /* end of namespace acl */
|
|
||||||
|
|
||||||
} /* end of namespace cv */
|
} /* end of namespace cv */
|
||||||
|
@@ -1,216 +1,213 @@
|
|||||||
#include "precomp.hpp"
|
#include "precomp.hpp"
|
||||||
|
|
||||||
|
|
||||||
#define ALIGN 64
|
#define ALIGN 64
|
||||||
|
|
||||||
namespace cv
|
using namespace std;
|
||||||
{
|
using namespace cv;
|
||||||
namespace acl
|
using namespace cv::acl;
|
||||||
{
|
namespace cv {
|
||||||
/* Memory alignment */
|
namespace acl {
|
||||||
static inline size_t alignSize(size_t sz, int n = ALIGN);
|
/* Memory alignment */
|
||||||
|
static inline size_t alignSize(size_t sz, int n = ALIGN);
|
||||||
|
|
||||||
void aclMat::upload(const Mat &m, ALIGNMENT config)
|
void aclMat::upload(const Mat &m, ALIGNMENT config) {
|
||||||
{
|
CV_Assert((config == ALIGNMENT::MEMORY_ALIGN) ||
|
||||||
CV_Assert((config == ALIGNMENT::MEMORY_ALIGN) || (config == ALIGNMENT::MEMORY_UNALIGNED));
|
(config == ALIGNMENT::MEMORY_UNALIGNED));
|
||||||
if (config == ALIGNMENT::MEMORY_UNALIGNED)
|
if (config == ALIGNMENT::MEMORY_UNALIGNED) {
|
||||||
{
|
CV_Assert(m.data && (this->step == m.step) && (this->rows == m.rows) &&
|
||||||
CV_Assert(m.data && (this->step == m.step) && (this->rows == m.rows) && (this->cols == m.cols) && (this->type() == m.type()));
|
(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);
|
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)
|
} else if (config == ALIGNMENT::MEMORY_ALIGN) {
|
||||||
{
|
CV_Assert(m.data && (this->rows == m.rows) && (this->cols == m.cols) &&
|
||||||
CV_Assert(m.data && (this->rows == m.rows) && (this->cols == m.cols) && (this->type() == m.type()));
|
(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);
|
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)
|
void aclMat::upload(const Mat &m, aclStream stream, ALIGNMENT config) {
|
||||||
{
|
CV_Assert((config == ALIGNMENT::MEMORY_ALIGN) ||
|
||||||
CV_Assert((config == ALIGNMENT::MEMORY_ALIGN) || (config == ALIGNMENT::MEMORY_UNALIGNED));
|
(config == ALIGNMENT::MEMORY_UNALIGNED));
|
||||||
if (config == ALIGNMENT::MEMORY_UNALIGNED)
|
if (config == ALIGNMENT::MEMORY_UNALIGNED) {
|
||||||
{
|
CV_Assert(m.data && (this->step == m.step) && (this->rows == m.rows) &&
|
||||||
CV_Assert(m.data && (this->step == m.step) && (this->rows == m.rows) && (this->cols == m.cols) && (this->type() == m.type()));
|
(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);
|
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)
|
} else if (config == ALIGNMENT::MEMORY_ALIGN) {
|
||||||
{
|
CV_Assert(m.data && (this->rows == m.rows) && (this->cols == m.cols) &&
|
||||||
CV_Assert(m.data && (this->rows == m.rows) && (this->cols == m.cols) && (this->type() == m.type()));
|
(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);
|
aclrtMemcpy2dAsync((void *)this->data, this->step, (void *)m.data, m.step,
|
||||||
}
|
m.cols * m.elemSize(), m.rows, ACL_MEMCPY_HOST_TO_DEVICE,
|
||||||
AclSafeCall(aclrtSynchronizeStream(stream));
|
stream);
|
||||||
}
|
}
|
||||||
|
AclSafeCall(aclrtSynchronizeStream(stream));
|
||||||
|
}
|
||||||
|
|
||||||
|
void aclMat::download(Mat &m, ALIGNMENT config) const {
|
||||||
|
CV_Assert((config == ALIGNMENT::MEMORY_ALIGN) ||
|
||||||
|
(config == ALIGNMENT::MEMORY_UNALIGNED));
|
||||||
|
if (config == ALIGNMENT::MEMORY_UNALIGNED) {
|
||||||
|
CV_Assert(m.data && (this->step == m.step) && (this->rows == m.rows) &&
|
||||||
|
(this->cols == m.cols) && (this->type() == m.type()));
|
||||||
|
aclrtMemcpy((void *)m.data, (m.step * m.rows), (void *)(this->data),
|
||||||
|
(m.step * m.rows), ACL_MEMCPY_DEVICE_TO_HOST);
|
||||||
|
} else if (config == ALIGNMENT::MEMORY_ALIGN) {
|
||||||
|
CV_Assert(m.data && (this->rows == m.rows) && (this->cols == m.cols) &&
|
||||||
|
(this->type() == m.type()));
|
||||||
|
aclrtMemcpy2d((void *)m.data, m.step, (void *)(this->data), this->step,
|
||||||
|
this->cols * this->elemSize(), this->rows,
|
||||||
|
ACL_MEMCPY_DEVICE_TO_HOST);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
void aclMat::download(Mat &m, ALIGNMENT config) const
|
void aclMat::download(Mat &m, aclStream stream, ALIGNMENT config) const {
|
||||||
{
|
CV_Assert((config == ALIGNMENT::MEMORY_ALIGN) ||
|
||||||
CV_Assert((config == ALIGNMENT::MEMORY_ALIGN) || (config == ALIGNMENT::MEMORY_UNALIGNED));
|
(config == ALIGNMENT::MEMORY_UNALIGNED));
|
||||||
if (config == ALIGNMENT::MEMORY_UNALIGNED)
|
if (config == ALIGNMENT::MEMORY_UNALIGNED) {
|
||||||
{
|
CV_Assert(m.data && (this->step == m.step) && (this->rows == m.rows) &&
|
||||||
CV_Assert(m.data && (this->step == m.step) && (this->rows == m.rows) && (this->cols == m.cols) && (this->type() == m.type()));
|
(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);
|
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)
|
} else if (config == ALIGNMENT::MEMORY_ALIGN) {
|
||||||
{
|
CV_Assert(m.data && (this->rows == m.rows) && (this->cols == m.cols) &&
|
||||||
CV_Assert(m.data && (this->rows == m.rows) && (this->cols == m.cols) && (this->type() == m.type()));
|
(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);
|
aclrtMemcpy2dAsync((void *)m.data, m.step, (void *)(this->data), this->step,
|
||||||
}
|
this->cols * this->elemSize(), this->rows,
|
||||||
return;
|
ACL_MEMCPY_DEVICE_TO_HOST, stream);
|
||||||
}
|
}
|
||||||
|
AclSafeCall(aclrtSynchronizeStream(stream));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
void aclMat::download(Mat &m, aclStream stream, ALIGNMENT config) const
|
void aclMat::create(int _rows, int _cols, int _type, ALIGNMENT config,
|
||||||
{
|
MemMallocPolicy policy) {
|
||||||
CV_Assert((config == ALIGNMENT::MEMORY_ALIGN) || (config == ALIGNMENT::MEMORY_UNALIGNED));
|
createEx(_rows, _cols, _type, config, policy);
|
||||||
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(Size size, int type, ALIGNMENT config,
|
||||||
{
|
MemMallocPolicy policy) {
|
||||||
createEx(_rows, _cols, _type, config, policy);
|
createEx(size, type, config, policy);
|
||||||
}
|
}
|
||||||
|
|
||||||
void aclMat::create(Size size, int type, ALIGNMENT config, MemMallocPolicy policy)
|
inline size_t alignSize(size_t sz, int n) { return (((sz) + n - 1) / n) * n; }
|
||||||
{
|
|
||||||
createEx(size, type, config, policy);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline size_t alignSize(size_t sz, int n)
|
/* core logic */
|
||||||
{
|
void aclMat::createEx(int _rows, int _cols, int _type, ALIGNMENT config,
|
||||||
return (((sz) + n - 1) / n ) * n;
|
MemMallocPolicy policy) {
|
||||||
}
|
/* TO ENSURE */
|
||||||
|
//_type &= CV_MAT_TYPE_MASK;
|
||||||
|
_type &= TYPE_MASK;
|
||||||
|
if (rows == _rows && cols == _cols && type() == _type && data) return;
|
||||||
|
|
||||||
/* core logic */
|
if (data) release();
|
||||||
void aclMat::createEx(int _rows, int _cols, int _type, ALIGNMENT config, MemMallocPolicy policy)
|
|
||||||
{
|
|
||||||
/* TO ENSURE */
|
|
||||||
//_type &= CV_MAT_TYPE_MASK;
|
|
||||||
_type &= TYPE_MASK;
|
|
||||||
if (rows == _rows && cols == _cols && type() == _type && data)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (data)
|
CV_DbgAssert(_rows >= 0 && _cols >= 0);
|
||||||
release();
|
|
||||||
|
|
||||||
CV_DbgAssert(_rows >= 0 && _cols >= 0);
|
if (_rows > 0 && _cols > 0) {
|
||||||
|
/* TO ENSURE */
|
||||||
|
// flags = (_type & CV_MAT_TYPE_MASK) | MAGIC_VAL;
|
||||||
|
flags = Mat::MAGIC_VAL + _type;
|
||||||
|
rows = _rows;
|
||||||
|
cols = _cols;
|
||||||
|
wholerows = _rows;
|
||||||
|
wholecols = _cols;
|
||||||
|
size_t esz = elemSize();
|
||||||
|
void *dev_ptr;
|
||||||
|
if (config == ALIGNMENT::MEMORY_ALIGN) {
|
||||||
|
if (channels() == 3)
|
||||||
|
step = alignSize(cols * esz, ALIGN * channels());
|
||||||
|
else
|
||||||
|
step = alignSize(cols * esz);
|
||||||
|
} else
|
||||||
|
step = cols * esz;
|
||||||
|
totalSize = step * rows;
|
||||||
|
|
||||||
if (_rows > 0 && _cols > 0)
|
AclSafeCall(aclrtMalloc(&dev_ptr, totalSize, type_transition(policy)));
|
||||||
{
|
|
||||||
/* TO ENSURE */
|
|
||||||
//flags = (_type & CV_MAT_TYPE_MASK) | MAGIC_VAL;
|
|
||||||
flags = Mat::MAGIC_VAL + _type;
|
|
||||||
rows = _rows;
|
|
||||||
cols = _cols;
|
|
||||||
wholerows = _rows;
|
|
||||||
wholecols = _cols;
|
|
||||||
size_t esz = elemSize();
|
|
||||||
void *dev_ptr;
|
|
||||||
if (config == ALIGNMENT::MEMORY_ALIGN)
|
|
||||||
{
|
|
||||||
if (channels() == 3)
|
|
||||||
step = alignSize(cols * esz, ALIGN * channels());
|
|
||||||
else
|
|
||||||
step = alignSize(cols * esz);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
step = cols * esz;
|
|
||||||
totalSize = step * rows;
|
|
||||||
|
|
||||||
AclSafeCall(aclrtMalloc(&dev_ptr, totalSize, type_transition(policy)));
|
data = dev_ptr;
|
||||||
|
datastart = static_cast<uchar *>(data);
|
||||||
|
dataend = static_cast<uchar *>(data) + totalSize;
|
||||||
|
refcount = static_cast<int *>(fastMalloc(sizeof(*refcount)));
|
||||||
|
*refcount = 0;
|
||||||
|
CV_XADD(refcount, 1);
|
||||||
|
flags |= Mat::CONTINUOUS_FLAG;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
data = dev_ptr;
|
void aclMat::createEx(Size size, int type, ALIGNMENT config,
|
||||||
datastart = static_cast<uchar *>(data);
|
MemMallocPolicy policy) {
|
||||||
dataend = static_cast<uchar *>(data) + totalSize;
|
createEx(size.height, size.width, type, config, policy);
|
||||||
refcount = static_cast<int *>(fastMalloc(sizeof(*refcount)));
|
}
|
||||||
*refcount = 0;
|
|
||||||
CV_XADD(refcount, 1);
|
|
||||||
flags |= Mat::CONTINUOUS_FLAG;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void aclMat::createEx(Size size, int type, ALIGNMENT config, MemMallocPolicy policy)
|
void aclMat::release() {
|
||||||
{
|
CV_XADD(refcount, -1);
|
||||||
createEx(size.height, size.width, type, config, policy);
|
if (data && (*refcount == 0)) {
|
||||||
}
|
aclrtFree(data);
|
||||||
|
}
|
||||||
|
data = nullptr;
|
||||||
|
datastart = nullptr;
|
||||||
|
dataend = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
void aclMat::release()
|
aclMat &aclMat::operator+=(const aclMat &m) {
|
||||||
{
|
CV_Assert(this->rows == m.rows && this->cols == m.cols &&
|
||||||
CV_XADD(refcount, -1);
|
this->type() == m.type());
|
||||||
if (data && (*refcount == 0))
|
TwoInAndOneOut(*this, m, *this, "Add");
|
||||||
{
|
return *this;
|
||||||
aclrtFree(data);
|
}
|
||||||
}
|
|
||||||
data = nullptr;
|
|
||||||
datastart = nullptr;
|
|
||||||
dataend = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
aclMat &aclMat::operator+=(const aclMat &m)
|
aclMat &aclMat::operator-=(const aclMat &m) {
|
||||||
{
|
CV_Assert(this->rows == m.rows && this->cols == m.cols &&
|
||||||
CV_Assert(this->rows == m.rows && this->cols == m.cols && this->type() == m.type());
|
this->type() == m.type());
|
||||||
TwoInAndOneOut(*this, m, *this, "Add");
|
TwoInAndOneOut(*this, m, *this, "Sub");
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
aclMat &aclMat::operator-=(const aclMat &m)
|
aclMat &aclMat::operator/=(const aclMat &m) {
|
||||||
{
|
CV_Assert(this->rows == m.rows && this->cols == m.cols &&
|
||||||
CV_Assert(this->rows == m.rows && this->cols == m.cols && this->type() == m.type());
|
this->type() == m.type());
|
||||||
TwoInAndOneOut(*this, m, *this, "Sub");
|
TwoInAndOneOut(*this, m, *this, "Div");
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
aclMat &aclMat::operator/=(const aclMat &m)
|
aclMat &aclMat::operator*=(const aclMat &m) {
|
||||||
{
|
CV_Assert(this->cols == m.rows && this->type() == m.type());
|
||||||
CV_Assert(this->rows == m.rows && this->cols == m.cols && this->type() == m.type());
|
vector<aclMat> input_Mat;
|
||||||
TwoInAndOneOut(*this, m, *this, "Div");
|
vector<aclMat> output_Mat;
|
||||||
return *this;
|
vector<aclDataBuffer *> inputBuffers_;
|
||||||
}
|
vector<aclDataBuffer *> outputBuffers_;
|
||||||
|
aclMat newMat{this->rows, m.cols, this->type(), this->acl_context};
|
||||||
|
|
||||||
aclMat &aclMat::operator*=(const aclMat &m)
|
input_Mat.emplace_back(*this);
|
||||||
{
|
input_Mat.emplace_back(m);
|
||||||
CV_Assert(this->cols == m.rows && this->type() == m.type());
|
output_Mat.emplace_back(newMat);
|
||||||
vector<aclMat> input_Mat;
|
|
||||||
vector<aclMat> output_Mat;
|
|
||||||
vector<aclDataBuffer *> inputBuffers_;
|
|
||||||
vector<aclDataBuffer *> outputBuffers_;
|
|
||||||
aclMat newMat{this->rows, m.cols, this->type(), this->acl_context};
|
|
||||||
|
|
||||||
input_Mat.emplace_back(*this);
|
OperatorDesc opDesc =
|
||||||
input_Mat.emplace_back(m);
|
CreateOpDesc("MatMul", input_Mat, output_Mat, ACL_FORMAT_NHWC, TWO_DIMS);
|
||||||
output_Mat.emplace_back(newMat);
|
opDesc.AddInputTensorDesc(ACL_DT_UNDEFINED, 0, nullptr, ACL_FORMAT_UNDEFINED);
|
||||||
|
opDesc.AddTensorAttr("transpose_x1", OP_BOOL, false);
|
||||||
|
opDesc.AddTensorAttr("transpose_x2", OP_BOOL, false);
|
||||||
|
|
||||||
OperatorDesc opDesc = CreateOpDesc("MatMul", input_Mat, output_Mat, ACL_FORMAT_NHWC, TWO_DIMS);
|
inputBuffers_.emplace_back(aclCreateDataBuffer(this->data, this->totalSize));
|
||||||
opDesc.AddInputTensorDesc(ACL_DT_UNDEFINED, 0, nullptr, ACL_FORMAT_UNDEFINED);
|
inputBuffers_.emplace_back(aclCreateDataBuffer(m.data, m.totalSize));
|
||||||
opDesc.AddTensorAttr("transpose_x1", OP_BOOL, false);
|
inputBuffers_.emplace_back(aclCreateDataBuffer(nullptr, 0));
|
||||||
opDesc.AddTensorAttr("transpose_x2", OP_BOOL, false);
|
outputBuffers_.emplace_back(
|
||||||
|
aclCreateDataBuffer(newMat.data, newMat.totalSize));
|
||||||
|
|
||||||
inputBuffers_.emplace_back(aclCreateDataBuffer(this->data, this->totalSize));
|
compileAndRunop(opDesc, inputBuffers_, outputBuffers_, this->acl_context, 0);
|
||||||
inputBuffers_.emplace_back(aclCreateDataBuffer(m.data, m.totalSize));
|
|
||||||
inputBuffers_.emplace_back(aclCreateDataBuffer(nullptr, 0));
|
|
||||||
outputBuffers_.emplace_back(aclCreateDataBuffer(newMat.data, newMat.totalSize));
|
|
||||||
|
|
||||||
compileAndRunop(opDesc, inputBuffers_, outputBuffers_, this->acl_context, 0);
|
*this = newMat;
|
||||||
|
|
||||||
*this = newMat;
|
for (size_t i = 0; i < inputBuffers_.size(); i++)
|
||||||
|
AclSafeCall(aclDestroyDataBuffer(inputBuffers_[i]));
|
||||||
|
for (size_t i = 0; i < outputBuffers_.size(); i++)
|
||||||
|
AclSafeCall(aclDestroyDataBuffer(outputBuffers_[i]));
|
||||||
|
|
||||||
for (size_t i = 0; i < inputBuffers_.size(); i++)
|
return *this;
|
||||||
AclSafeCall(aclDestroyDataBuffer(inputBuffers_[i]));
|
}
|
||||||
for (size_t i = 0; i < outputBuffers_.size(); i++)
|
|
||||||
AclSafeCall(aclDestroyDataBuffer(outputBuffers_[i]));
|
|
||||||
|
|
||||||
return *this;
|
} /* end of namespace acl */
|
||||||
}
|
|
||||||
|
|
||||||
} /* end of namespace acl */
|
|
||||||
|
|
||||||
} /* end of namespace cv */
|
} /* end of namespace cv */
|
||||||
|
163
acl/src/gemm.cpp
163
acl/src/gemm.cpp
@@ -1,88 +1,103 @@
|
|||||||
#include "precomp.hpp"
|
#include "precomp.hpp"
|
||||||
|
|
||||||
namespace cv
|
using namespace std;
|
||||||
{
|
using namespace cv;
|
||||||
namespace acl
|
using namespace cv::acl;
|
||||||
{
|
namespace cv {
|
||||||
/**
|
namespace acl {
|
||||||
* @brief: matrix multiplication
|
/**
|
||||||
*
|
* @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,
|
||||||
CV_Assert(src1.cols == src2.rows && src1.type() == src2.type());
|
int stream_id) {
|
||||||
vector<aclMat> input_Mat;
|
CV_Assert(src1.cols == src2.rows && src1.type() == src2.type());
|
||||||
vector<aclMat> output_Mat;
|
vector<aclMat> input_Mat;
|
||||||
vector<aclDataBuffer *> inputBuffers_;
|
vector<aclMat> output_Mat;
|
||||||
vector<aclDataBuffer *> outputBuffers_;
|
vector<aclDataBuffer*> inputBuffers_;
|
||||||
|
vector<aclDataBuffer*> outputBuffers_;
|
||||||
|
|
||||||
input_Mat.emplace_back(src1);
|
input_Mat.emplace_back(src1);
|
||||||
input_Mat.emplace_back(src2);
|
input_Mat.emplace_back(src2);
|
||||||
output_Mat.emplace_back(dest);
|
output_Mat.emplace_back(dest);
|
||||||
|
|
||||||
inputBuffers_.emplace_back(aclCreateDataBuffer(src1.data, src1.totalSize));
|
inputBuffers_.emplace_back(aclCreateDataBuffer(src1.data, src1.totalSize));
|
||||||
inputBuffers_.emplace_back(aclCreateDataBuffer(src2.data, src2.totalSize));
|
inputBuffers_.emplace_back(aclCreateDataBuffer(src2.data, src2.totalSize));
|
||||||
inputBuffers_.emplace_back(aclCreateDataBuffer(nullptr, 0));
|
inputBuffers_.emplace_back(aclCreateDataBuffer(nullptr, 0));
|
||||||
outputBuffers_.emplace_back(aclCreateDataBuffer(dest.data, dest.totalSize));
|
outputBuffers_.emplace_back(aclCreateDataBuffer(dest.data, dest.totalSize));
|
||||||
|
|
||||||
OperatorDesc opDesc = CreateOpDesc("MatMul", input_Mat, output_Mat, ACL_FORMAT_NHWC, TWO_DIMS);
|
OperatorDesc opDesc =
|
||||||
opDesc.AddInputTensorDesc(ACL_DT_UNDEFINED, 0, nullptr, ACL_FORMAT_UNDEFINED);
|
CreateOpDesc("MatMul", input_Mat, output_Mat, ACL_FORMAT_NHWC, TWO_DIMS);
|
||||||
opDesc.AddTensorAttr("transpose_x1", OP_BOOL, false);
|
opDesc.AddInputTensorDesc(ACL_DT_UNDEFINED, 0, nullptr, ACL_FORMAT_UNDEFINED);
|
||||||
opDesc.AddTensorAttr("transpose_x2", OP_BOOL, false);
|
opDesc.AddTensorAttr("transpose_x1", OP_BOOL, false);
|
||||||
compileAndRunop(opDesc, inputBuffers_, outputBuffers_, dest.acl_context, stream_id);
|
opDesc.AddTensorAttr("transpose_x2", OP_BOOL, false);
|
||||||
|
compileAndRunop(opDesc, inputBuffers_, outputBuffers_, dest.acl_context,
|
||||||
|
stream_id);
|
||||||
|
|
||||||
for (size_t i = 0; i < inputBuffers_.size(); i++)
|
for (size_t i = 0; i < inputBuffers_.size(); i++)
|
||||||
AclSafeCall(aclDestroyDataBuffer(inputBuffers_[i]));
|
AclSafeCall(aclDestroyDataBuffer(inputBuffers_[i]));
|
||||||
for (size_t i = 0; i < outputBuffers_.size(); i++)
|
for (size_t i = 0; i < outputBuffers_.size(); i++)
|
||||||
AclSafeCall(aclDestroyDataBuffer(outputBuffers_[i]));
|
AclSafeCall(aclDestroyDataBuffer(outputBuffers_[i]));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief convolution
|
* @brief convolution
|
||||||
* @param [in] src: characteristic matrix
|
* @param [in] src: characteristic matrix
|
||||||
* @param [in] kernel: convolution kernel
|
* @param [in] kernel: convolution kernel
|
||||||
* @param [in] dest: destination matrix
|
* @param [in] dest: destination matrix
|
||||||
* @param [in] stridesList: strides, The N and C dimensions must be set to 1
|
* @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)
|
* @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,
|
||||||
vector<aclDataBuffer *> inputBuffers_;
|
const vector<int64_t>& padsList, int stream_id) {
|
||||||
vector<aclDataBuffer *> outputBuffers_;
|
vector<aclDataBuffer*> inputBuffers_;
|
||||||
vector<int64_t> dilationsList{1, 1, 1, 1};
|
vector<aclDataBuffer*> outputBuffers_;
|
||||||
string opType = "Conv2D";
|
vector<int64_t> dilationsList{1, 1, 1, 1};
|
||||||
int dest_rows = (src.rows + padsList[0] + padsList[1] - (1 * (kernel.rows - 1) + 1)) / stridesList[2] + 1;
|
string opType = "Conv2D";
|
||||||
int dest_cols = (src.cols + padsList[2] + padsList[3] - (1 * (kernel.cols - 1) + 1)) / stridesList[3] + 1;
|
int dest_rows =
|
||||||
aclMat acl_dest{dest_rows, dest_cols, src.type(), src.acl_context};
|
(src.rows + padsList[0] + padsList[1] - (1 * (kernel.rows - 1) + 1)) /
|
||||||
|
stridesList[2] +
|
||||||
|
1;
|
||||||
|
int dest_cols =
|
||||||
|
(src.cols + padsList[2] + padsList[3] - (1 * (kernel.cols - 1) + 1)) /
|
||||||
|
stridesList[3] +
|
||||||
|
1;
|
||||||
|
aclMat acl_dest{dest_rows, dest_cols, src.type(), src.acl_context};
|
||||||
|
|
||||||
vector<int64_t> shape{1, 1, src.rows, src.cols};
|
vector<int64_t> shape{1, 1, src.rows, src.cols};
|
||||||
vector<int64_t> shape1{1, 1, kernel.rows, kernel.cols};
|
vector<int64_t> shape1{1, 1, kernel.rows, kernel.cols};
|
||||||
vector<int64_t> shape2{1, 1, acl_dest.rows, acl_dest.cols};
|
vector<int64_t> shape2{1, 1, acl_dest.rows, acl_dest.cols};
|
||||||
|
|
||||||
aclDataType dataType = type_transition(src.depth());
|
aclDataType dataType = type_transition(src.depth());
|
||||||
aclFormat format = ACL_FORMAT_NCHW;
|
aclFormat format = ACL_FORMAT_NCHW;
|
||||||
OperatorDesc opDesc(opType);
|
OperatorDesc opDesc(opType);
|
||||||
opDesc.AddInputTensorDesc(dataType, shape.size(), shape.data(), format);
|
opDesc.AddInputTensorDesc(dataType, shape.size(), shape.data(), format);
|
||||||
opDesc.AddInputTensorDesc(dataType, shape1.size(), shape1.data(), format);
|
opDesc.AddInputTensorDesc(dataType, shape1.size(), shape1.data(), format);
|
||||||
opDesc.AddOutputTensorDesc(dataType, shape2.size(), shape2.data(), format);
|
opDesc.AddOutputTensorDesc(dataType, shape2.size(), shape2.data(), format);
|
||||||
|
|
||||||
auto opAttr = opDesc.opAttr;
|
auto opAttr = opDesc.opAttr;
|
||||||
aclopSetAttrListInt(opAttr, "strides", stridesList.size(), stridesList.data());
|
aclopSetAttrListInt(opAttr, "strides", stridesList.size(),
|
||||||
aclopSetAttrListInt(opAttr, "pads", padsList.size(), padsList.data());
|
stridesList.data());
|
||||||
aclopSetAttrListInt(opAttr, "dilations", dilationsList.size(), dilationsList.data());
|
aclopSetAttrListInt(opAttr, "pads", padsList.size(), padsList.data());
|
||||||
|
aclopSetAttrListInt(opAttr, "dilations", dilationsList.size(),
|
||||||
|
dilationsList.data());
|
||||||
|
|
||||||
inputBuffers_.emplace_back(aclCreateDataBuffer(src.data, src.totalSize));
|
inputBuffers_.emplace_back(aclCreateDataBuffer(src.data, src.totalSize));
|
||||||
inputBuffers_.emplace_back(aclCreateDataBuffer(kernel.data, kernel.totalSize));
|
inputBuffers_.emplace_back(
|
||||||
outputBuffers_.emplace_back(aclCreateDataBuffer(acl_dest.data, acl_dest.totalSize));
|
aclCreateDataBuffer(kernel.data, kernel.totalSize));
|
||||||
compileAndRunop(opDesc, inputBuffers_, outputBuffers_, src.acl_context, stream_id);
|
outputBuffers_.emplace_back(
|
||||||
acl_dest.data = aclGetDataBufferAddr(outputBuffers_[0]);
|
aclCreateDataBuffer(acl_dest.data, acl_dest.totalSize));
|
||||||
dest = acl_dest;
|
compileAndRunop(opDesc, inputBuffers_, outputBuffers_, src.acl_context,
|
||||||
|
stream_id);
|
||||||
|
acl_dest.data = aclGetDataBufferAddr(outputBuffers_[0]);
|
||||||
|
dest = acl_dest;
|
||||||
|
|
||||||
for (size_t i = 0; i < inputBuffers_.size(); i++)
|
for (size_t i = 0; i < inputBuffers_.size(); i++)
|
||||||
AclSafeCall(aclDestroyDataBuffer(inputBuffers_[i]));
|
AclSafeCall(aclDestroyDataBuffer(inputBuffers_[i]));
|
||||||
for (size_t i = 0; i < outputBuffers_.size(); i++)
|
for (size_t i = 0; i < outputBuffers_.size(); i++)
|
||||||
AclSafeCall(aclDestroyDataBuffer(outputBuffers_[i]));
|
AclSafeCall(aclDestroyDataBuffer(outputBuffers_[i]));
|
||||||
}
|
}
|
||||||
} /* end of namespace acl */
|
} /* end of namespace acl */
|
||||||
|
|
||||||
} /* end of namespace cv */
|
} /* end of namespace cv */
|
@@ -1,224 +1,224 @@
|
|||||||
#include "precomp.hpp"
|
#include "precomp.hpp"
|
||||||
|
|
||||||
namespace cv
|
using namespace std;
|
||||||
{
|
using namespace cv;
|
||||||
namespace acl
|
using namespace cv::acl;
|
||||||
{
|
namespace cv {
|
||||||
aclMat abs(const aclMat& a, int stream_id)
|
namespace acl {
|
||||||
{
|
aclMat abs(const aclMat &a, int stream_id) {
|
||||||
aclMat dest(a.rows, a.cols, a.type(), a.acl_context);
|
aclMat dest(a.rows, a.cols, a.type(), a.acl_context);
|
||||||
OneInAndOneOut(a, dest, "Abs", stream_id);
|
OneInAndOneOut(a, dest, "Abs", stream_id);
|
||||||
return dest;
|
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;
|
||||||
void *dev_ptr;
|
|
||||||
|
|
||||||
switch(type)
|
switch (type) {
|
||||||
{
|
case ACL_UINT8: {
|
||||||
case ACL_UINT8:
|
aclrtMalloc(&dev_ptr, powersize, ACL_MEM_MALLOC_NORMAL_ONLY);
|
||||||
{
|
uchar power_8u = uchar(power);
|
||||||
aclrtMalloc(&dev_ptr, powersize, ACL_MEM_MALLOC_NORMAL_ONLY);
|
aclrtMemcpy(dev_ptr, powersize, static_cast<void *>(&power_8u), powersize,
|
||||||
uchar power_8u = uchar(power);
|
ACL_MEMCPY_HOST_TO_DEVICE);
|
||||||
aclrtMemcpy(dev_ptr, powersize, static_cast<void *>(&power_8u), powersize, ACL_MEMCPY_HOST_TO_DEVICE);
|
return dev_ptr;
|
||||||
return dev_ptr;
|
}
|
||||||
}
|
case ACL_INT8: {
|
||||||
case ACL_INT8:
|
aclrtMalloc(&dev_ptr, powersize, ACL_MEM_MALLOC_NORMAL_ONLY);
|
||||||
{
|
char power_8s = char(power);
|
||||||
aclrtMalloc(&dev_ptr, powersize, ACL_MEM_MALLOC_NORMAL_ONLY);
|
aclrtMemcpy(dev_ptr, powersize, static_cast<void *>(&power_8s), powersize,
|
||||||
char power_8s = char(power);
|
ACL_MEMCPY_HOST_TO_DEVICE);
|
||||||
aclrtMemcpy(dev_ptr, powersize, static_cast<void *>(&power_8s), powersize, ACL_MEMCPY_HOST_TO_DEVICE);
|
return dev_ptr;
|
||||||
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);
|
||||||
aclrtMalloc(&dev_ptr, powersize, ACL_MEM_MALLOC_NORMAL_ONLY);
|
aclrtMemcpy(dev_ptr, powersize, static_cast<void *>(&power_16f),
|
||||||
float16_t power_16f = float16_t(power);
|
powersize, ACL_MEMCPY_HOST_TO_DEVICE);
|
||||||
aclrtMemcpy(dev_ptr, powersize, static_cast<void *>(&power_16f), powersize, ACL_MEMCPY_HOST_TO_DEVICE);
|
return dev_ptr;
|
||||||
return dev_ptr;
|
}
|
||||||
}
|
case ACL_INT32: {
|
||||||
case ACL_INT32:
|
aclrtMalloc(&dev_ptr, powersize, ACL_MEM_MALLOC_NORMAL_ONLY);
|
||||||
{
|
int power_32s = int(power);
|
||||||
aclrtMalloc(&dev_ptr, powersize, ACL_MEM_MALLOC_NORMAL_ONLY);
|
aclrtMemcpy(dev_ptr, powersize, static_cast<void *>(&power_32s),
|
||||||
int power_32s = int(power);
|
powersize, ACL_MEMCPY_HOST_TO_DEVICE);
|
||||||
aclrtMemcpy(dev_ptr, powersize, static_cast<void *>(&power_32s), powersize, ACL_MEMCPY_HOST_TO_DEVICE);
|
return dev_ptr;
|
||||||
return dev_ptr;
|
}
|
||||||
}
|
case ACL_FLOAT: {
|
||||||
case ACL_FLOAT:
|
aclrtMalloc(&dev_ptr, powersize, ACL_MEM_MALLOC_NORMAL_ONLY);
|
||||||
{
|
float power_32f = float(power);
|
||||||
aclrtMalloc(&dev_ptr, powersize, ACL_MEM_MALLOC_NORMAL_ONLY);
|
aclrtMemcpy(dev_ptr, powersize, static_cast<void *>(&power_32f),
|
||||||
float power_32f = float(power);
|
powersize, ACL_MEMCPY_HOST_TO_DEVICE);
|
||||||
aclrtMemcpy(dev_ptr, powersize, static_cast<void *>(&power_32f), powersize, ACL_MEMCPY_HOST_TO_DEVICE);
|
return dev_ptr;
|
||||||
return dev_ptr;
|
}
|
||||||
}
|
case ACL_DOUBLE: {
|
||||||
case ACL_DOUBLE:
|
aclrtMalloc(&dev_ptr, powersize, ACL_MEM_MALLOC_NORMAL_ONLY);
|
||||||
{
|
double power_64f = double(power);
|
||||||
aclrtMalloc(&dev_ptr, powersize, ACL_MEM_MALLOC_NORMAL_ONLY);
|
aclrtMemcpy(dev_ptr, powersize, static_cast<void *>(&power_64f),
|
||||||
double power_64f = double(power);
|
powersize, ACL_MEMCPY_HOST_TO_DEVICE);
|
||||||
aclrtMemcpy(dev_ptr, powersize, static_cast<void *>(&power_64f), powersize, ACL_MEMCPY_HOST_TO_DEVICE);
|
return dev_ptr;
|
||||||
return dev_ptr;
|
}
|
||||||
}
|
default:
|
||||||
default:
|
return nullptr;
|
||||||
return nullptr;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
void pow(const aclMat &src, double power, aclMat &dest, int stream_id) {
|
||||||
|
vector<aclMat> input_Mat;
|
||||||
|
vector<aclMat> output_Mat;
|
||||||
|
vector<aclDataBuffer *> inputBuffers_;
|
||||||
|
vector<aclDataBuffer *> outputBuffers_;
|
||||||
|
|
||||||
void pow(const aclMat& src, double power, aclMat& dest, int stream_id)
|
aclDataType dataType = type_transition(src.depth());
|
||||||
{
|
|
||||||
vector<aclMat> input_Mat;
|
|
||||||
vector<aclMat> output_Mat;
|
|
||||||
vector<aclDataBuffer *> inputBuffers_;
|
|
||||||
vector<aclDataBuffer *> outputBuffers_;
|
|
||||||
|
|
||||||
aclDataType dataType = type_transition(src.depth());
|
input_Mat.emplace_back(src);
|
||||||
|
output_Mat.emplace_back(dest);
|
||||||
|
|
||||||
input_Mat.emplace_back(src);
|
OperatorDesc opDesc = CreateOpDesc("Pow", input_Mat, output_Mat);
|
||||||
output_Mat.emplace_back(dest);
|
vector<int64_t> shape2{1};
|
||||||
|
opDesc.AddInputTensorDesc(dataType, shape2.size(), shape2.data(),
|
||||||
|
ACL_FORMAT_NHWC);
|
||||||
|
|
||||||
OperatorDesc opDesc = CreateOpDesc("Pow", input_Mat, output_Mat);
|
size_t size = aclGetTensorDescSize(opDesc.inputDesc[1]);
|
||||||
vector<int64_t> shape2{1};
|
void *power_dev = power_data(power, dataType, size);
|
||||||
opDesc.AddInputTensorDesc(dataType, shape2.size(), shape2.data(), ACL_FORMAT_NHWC);
|
|
||||||
|
|
||||||
size_t size = aclGetTensorDescSize(opDesc.inputDesc[1]);
|
inputBuffers_.emplace_back(aclCreateDataBuffer(src.data, src.totalSize));
|
||||||
void *power_dev = power_data(power, dataType, size);
|
inputBuffers_.emplace_back(aclCreateDataBuffer(power_dev, size));
|
||||||
|
|
||||||
inputBuffers_.emplace_back(aclCreateDataBuffer(src.data, src.totalSize));
|
outputBuffers_.emplace_back(aclCreateDataBuffer(dest.data, dest.totalSize));
|
||||||
inputBuffers_.emplace_back(aclCreateDataBuffer(power_dev, size));
|
|
||||||
|
|
||||||
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++)
|
||||||
|
AclSafeCall(aclDestroyDataBuffer(inputBuffers_[i]));
|
||||||
|
for (size_t i = 0; i < outputBuffers_.size(); i++)
|
||||||
|
AclSafeCall(aclDestroyDataBuffer(outputBuffers_[i]));
|
||||||
|
}
|
||||||
|
|
||||||
aclrtFree(power_dev);
|
void add(const aclMat &src, const aclMat &other_src, aclMat &dest,
|
||||||
for (size_t i = 0; i < inputBuffers_.size(); i++)
|
int stream_id) {
|
||||||
AclSafeCall(aclDestroyDataBuffer(inputBuffers_[i]));
|
bool is_correct;
|
||||||
for (size_t i = 0; i < outputBuffers_.size(); i++)
|
|
||||||
AclSafeCall(aclDestroyDataBuffer(outputBuffers_[i]));
|
|
||||||
}
|
|
||||||
|
|
||||||
void add(const aclMat& src, const aclMat& other_src, aclMat& dest, int stream_id)
|
is_correct = (src.rows == other_src.rows);
|
||||||
{
|
is_correct &= (src.rows == dest.rows);
|
||||||
bool is_correct;
|
is_correct &= (src.cols == other_src.cols);
|
||||||
|
is_correct &= (src.cols == dest.cols);
|
||||||
|
is_correct &= (src.type() == other_src.type());
|
||||||
|
is_correct &= (src.type() == dest.type());
|
||||||
|
CV_Assert(is_correct);
|
||||||
|
|
||||||
is_correct = (src.rows == other_src.rows);
|
TwoInAndOneOut(src, other_src, dest, "Add", stream_id);
|
||||||
is_correct &= (src.rows == dest.rows);
|
}
|
||||||
is_correct &= (src.cols == other_src.cols);
|
|
||||||
is_correct &= (src.cols == dest.cols);
|
|
||||||
is_correct &= (src.type() == other_src.type());
|
|
||||||
is_correct &= (src.type() == dest.type());
|
|
||||||
CV_Assert(is_correct);
|
|
||||||
|
|
||||||
TwoInAndOneOut(src, other_src, dest, "Add", stream_id);
|
void divide(const aclMat &src, const aclMat &other_src, aclMat &dest,
|
||||||
}
|
int stream_id) {
|
||||||
|
bool is_correct;
|
||||||
|
|
||||||
void divide(const aclMat& src, const aclMat& other_src, aclMat& dest, int stream_id)
|
is_correct = (src.rows == other_src.rows);
|
||||||
{
|
is_correct &= (src.rows == dest.rows);
|
||||||
bool is_correct;
|
is_correct &= (src.cols == other_src.cols);
|
||||||
|
is_correct &= (src.cols == dest.cols);
|
||||||
|
is_correct &= (src.type() == other_src.type());
|
||||||
|
is_correct &= (src.type() == dest.type());
|
||||||
|
CV_Assert(is_correct);
|
||||||
|
|
||||||
is_correct = (src.rows == other_src.rows);
|
TwoInAndOneOut(src, other_src, dest, "Div", stream_id);
|
||||||
is_correct &= (src.rows == dest.rows);
|
}
|
||||||
is_correct &= (src.cols == other_src.cols);
|
|
||||||
is_correct &= (src.cols == dest.cols);
|
|
||||||
is_correct &= (src.type() == other_src.type());
|
|
||||||
is_correct &= (src.type() == dest.type());
|
|
||||||
CV_Assert(is_correct);
|
|
||||||
|
|
||||||
TwoInAndOneOut(src, other_src, dest, "Div", stream_id);
|
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)
|
vector<aclMat> input_Mat;
|
||||||
{
|
vector<aclMat> output_Mat;
|
||||||
CV_Assert(src.rows == dest.rows && src.cols == dest.cols && src.type() == dest.type());
|
|
||||||
|
|
||||||
vector<aclMat> input_Mat;
|
vector<aclDataBuffer *> inputBuffers_;
|
||||||
vector<aclMat> output_Mat;
|
vector<aclDataBuffer *> outputBuffers_;
|
||||||
|
|
||||||
vector<aclDataBuffer *> inputBuffers_;
|
input_Mat.emplace_back(src);
|
||||||
vector<aclDataBuffer *> outputBuffers_;
|
output_Mat.emplace_back(dest);
|
||||||
|
|
||||||
input_Mat.emplace_back(src);
|
inputBuffers_.emplace_back(aclCreateDataBuffer(src.data, src.totalSize));
|
||||||
output_Mat.emplace_back(dest);
|
outputBuffers_.emplace_back(aclCreateDataBuffer(dest.data, dest.totalSize));
|
||||||
|
|
||||||
inputBuffers_.emplace_back(aclCreateDataBuffer(src.data, src.totalSize));
|
OperatorDesc opDesc = CreateOpDesc("Exp", input_Mat, output_Mat);
|
||||||
outputBuffers_.emplace_back(aclCreateDataBuffer(dest.data, dest.totalSize));
|
opDesc.AddTensorAttr("base", OP_FLOAT, -1.0);
|
||||||
|
opDesc.AddTensorAttr("scale", OP_FLOAT, 1.0);
|
||||||
|
opDesc.AddTensorAttr("shift", OP_FLOAT, 0.0);
|
||||||
|
|
||||||
OperatorDesc opDesc = CreateOpDesc("Exp", input_Mat, output_Mat);
|
compileAndRunop(opDesc, inputBuffers_, outputBuffers_, dest.acl_context,
|
||||||
opDesc.AddTensorAttr("base", OP_FLOAT, -1.0);
|
stream_id);
|
||||||
opDesc.AddTensorAttr("scale", OP_FLOAT, 1.0);
|
|
||||||
opDesc.AddTensorAttr("shift", OP_FLOAT, 0.0);
|
|
||||||
|
|
||||||
compileAndRunop(opDesc, inputBuffers_, outputBuffers_, dest.acl_context, stream_id);
|
AclSafeCall(aclDestroyDataBuffer(inputBuffers_[0]));
|
||||||
|
AclSafeCall(aclDestroyDataBuffer(outputBuffers_[0]));
|
||||||
|
}
|
||||||
|
|
||||||
AclSafeCall(aclDestroyDataBuffer(inputBuffers_[0]));
|
void log(const aclMat &src, aclMat &dest, int stream_id) {
|
||||||
AclSafeCall(aclDestroyDataBuffer(outputBuffers_[0]));
|
CV_Assert(src.rows == dest.rows && src.cols == dest.cols &&
|
||||||
}
|
src.type() == dest.type());
|
||||||
|
|
||||||
void log(const aclMat &src, aclMat &dest, int stream_id)
|
vector<aclMat> input_Mat;
|
||||||
{
|
vector<aclMat> output_Mat;
|
||||||
CV_Assert(src.rows == dest.rows && src.cols == dest.cols && src.type() == dest.type());
|
|
||||||
|
|
||||||
vector<aclMat> input_Mat;
|
vector<aclDataBuffer *> inputBuffers_;
|
||||||
vector<aclMat> output_Mat;
|
vector<aclDataBuffer *> outputBuffers_;
|
||||||
|
|
||||||
vector<aclDataBuffer *> inputBuffers_;
|
input_Mat.emplace_back(src);
|
||||||
vector<aclDataBuffer *> outputBuffers_;
|
output_Mat.emplace_back(dest);
|
||||||
|
|
||||||
input_Mat.emplace_back(src);
|
inputBuffers_.emplace_back(aclCreateDataBuffer(src.data, src.totalSize));
|
||||||
output_Mat.emplace_back(dest);
|
outputBuffers_.emplace_back(aclCreateDataBuffer(dest.data, dest.totalSize));
|
||||||
|
|
||||||
inputBuffers_.emplace_back(aclCreateDataBuffer(src.data, src.totalSize));
|
OperatorDesc opDesc = CreateOpDesc("Log", input_Mat, output_Mat);
|
||||||
outputBuffers_.emplace_back(aclCreateDataBuffer(dest.data, dest.totalSize));
|
opDesc.AddTensorAttr("base", OP_FLOAT, -1.0);
|
||||||
|
opDesc.AddTensorAttr("scale", OP_FLOAT, 1.0);
|
||||||
|
opDesc.AddTensorAttr("shift", OP_FLOAT, 0.0);
|
||||||
|
|
||||||
OperatorDesc opDesc = CreateOpDesc("Log", input_Mat, output_Mat);
|
compileAndRunop(opDesc, inputBuffers_, outputBuffers_, dest.acl_context,
|
||||||
opDesc.AddTensorAttr("base", OP_FLOAT, -1.0);
|
stream_id);
|
||||||
opDesc.AddTensorAttr("scale", OP_FLOAT, 1.0);
|
|
||||||
opDesc.AddTensorAttr("shift", OP_FLOAT, 0.0);
|
|
||||||
|
|
||||||
compileAndRunop(opDesc, inputBuffers_, outputBuffers_, dest.acl_context, stream_id);
|
AclSafeCall(aclDestroyDataBuffer(inputBuffers_[0]));
|
||||||
|
AclSafeCall(aclDestroyDataBuffer(outputBuffers_[0]));
|
||||||
|
}
|
||||||
|
|
||||||
AclSafeCall(aclDestroyDataBuffer(inputBuffers_[0]));
|
void max(const aclMat &src, const aclMat &other_src, aclMat &dest,
|
||||||
AclSafeCall(aclDestroyDataBuffer(outputBuffers_[0]));
|
int stream_id) {
|
||||||
}
|
bool is_correct;
|
||||||
|
|
||||||
void max(const aclMat &src, const aclMat &other_src, aclMat &dest, int stream_id)
|
is_correct = (src.rows == other_src.rows);
|
||||||
{
|
is_correct &= (src.rows == dest.rows);
|
||||||
bool is_correct;
|
is_correct &= (src.cols == other_src.cols);
|
||||||
|
is_correct &= (src.cols == dest.cols);
|
||||||
|
is_correct &= (src.type() == other_src.type());
|
||||||
|
is_correct &= (src.type() == dest.type());
|
||||||
|
CV_Assert(is_correct);
|
||||||
|
|
||||||
is_correct = (src.rows == other_src.rows);
|
TwoInAndOneOut(src, other_src, dest, "Maximum", stream_id);
|
||||||
is_correct &= (src.rows == dest.rows);
|
}
|
||||||
is_correct &= (src.cols == other_src.cols);
|
|
||||||
is_correct &= (src.cols == dest.cols);
|
|
||||||
is_correct &= (src.type() == other_src.type());
|
|
||||||
is_correct &= (src.type() == dest.type());
|
|
||||||
CV_Assert(is_correct);
|
|
||||||
|
|
||||||
TwoInAndOneOut(src, other_src, dest, "Maximum", stream_id);
|
void min(const aclMat &src, const aclMat &other_src, aclMat &dest,
|
||||||
}
|
int stream_id) {
|
||||||
|
bool is_correct;
|
||||||
|
|
||||||
void min(const aclMat &src, const aclMat &other_src, aclMat &dest, int stream_id)
|
is_correct = (src.rows == other_src.rows);
|
||||||
{
|
is_correct &= (src.rows == dest.rows);
|
||||||
bool is_correct;
|
is_correct &= (src.cols == other_src.cols);
|
||||||
|
is_correct &= (src.cols == dest.cols);
|
||||||
|
is_correct &= (src.type() == other_src.type());
|
||||||
|
is_correct &= (src.type() == dest.type());
|
||||||
|
CV_Assert(is_correct);
|
||||||
|
|
||||||
is_correct = (src.rows == other_src.rows);
|
TwoInAndOneOut(src, other_src, dest, "Minimum", stream_id);
|
||||||
is_correct &= (src.rows == dest.rows);
|
}
|
||||||
is_correct &= (src.cols == other_src.cols);
|
|
||||||
is_correct &= (src.cols == dest.cols);
|
|
||||||
is_correct &= (src.type() == other_src.type());
|
|
||||||
is_correct &= (src.type() == dest.type());
|
|
||||||
CV_Assert(is_correct);
|
|
||||||
|
|
||||||
TwoInAndOneOut(src, other_src, dest, "Minimum", stream_id);
|
void sqrt(const aclMat &src, aclMat &dest, int stream_id) {
|
||||||
}
|
CV_Assert(src.rows == dest.rows && src.cols == dest.cols &&
|
||||||
|
src.type() == dest.type());
|
||||||
|
|
||||||
void sqrt(const aclMat &src, aclMat &dest, int stream_id)
|
OneInAndOneOut(src, dest, "Sqrt", stream_id);
|
||||||
{
|
}
|
||||||
CV_Assert(src.rows == dest.rows && src.cols == dest.cols && src.type() == dest.type());
|
|
||||||
|
|
||||||
OneInAndOneOut(src, dest, "Sqrt", stream_id);
|
} /* end of namespace acl */
|
||||||
}
|
|
||||||
|
|
||||||
} /* end of namespace acl */
|
|
||||||
|
|
||||||
} /* end of namespace cv */
|
} /* end of namespace cv */
|
@@ -1,60 +1,11 @@
|
|||||||
#include "precomp.hpp"
|
#include "precomp.hpp"
|
||||||
|
|
||||||
namespace cv
|
using namespace std;
|
||||||
{
|
using namespace cv;
|
||||||
namespace acl
|
using namespace cv::acl;
|
||||||
{
|
namespace cv {
|
||||||
/*
|
namespace acl {
|
||||||
//disable
|
#if 0
|
||||||
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]));
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
void merge(const vector<aclMat>& mv, aclMat& dest)
|
void merge(const vector<aclMat>& mv, aclMat& dest)
|
||||||
{
|
{
|
||||||
vector<aclDataBuffer *> inputBuffers_;
|
vector<aclDataBuffer *> inputBuffers_;
|
||||||
@@ -66,191 +17,190 @@ namespace cv
|
|||||||
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();
|
int cols = mv[i].step/mv[i].elemSize();
|
||||||
vector<int64_t> inputShape{1, mv[i].rows, cols, mv[i].channels()};
|
vector<int64_t> inputShape{1, mv[i].rows, cols,
|
||||||
opDesc.AddInputTensorDesc(dataType, inputShape.size(), inputShape.data(), ACL_FORMAT_ND);
|
mv[i].channels()}; opDesc.AddInputTensorDesc(dataType, inputShape.size(),
|
||||||
|
inputShape.data(), ACL_FORMAT_ND);
|
||||||
}
|
}
|
||||||
int cols = dest.step/dest.elemSize();
|
int cols = dest.step/dest.elemSize();
|
||||||
vector<int64_t> outputShape{1, dest.rows, cols, dest.channels()};
|
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)
|
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, "N", mv.size());
|
||||||
aclopSetAttrInt(opDesc.opAttr, "concat_dim", 3);
|
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++)
|
for (size_t i = 0; i < inputBuffers_.size(); i++)
|
||||||
AclSafeCall(aclDestroyDataBuffer(inputBuffers_[i]));
|
AclSafeCall(aclDestroyDataBuffer(inputBuffers_[i]));
|
||||||
for (size_t i = 0; i < outputBuffers_.size(); i++)
|
for (size_t i = 0; i < outputBuffers_.size(); i++)
|
||||||
AclSafeCall(aclDestroyDataBuffer(outputBuffers_[i]));
|
AclSafeCall(aclDestroyDataBuffer(outputBuffers_[i]));
|
||||||
}
|
}
|
||||||
*/
|
#endif
|
||||||
static int merge_type(int depth, int channels)
|
|
||||||
{
|
|
||||||
switch (depth)
|
|
||||||
{
|
|
||||||
case CV_8U:
|
|
||||||
return CV_8UC(channels);
|
|
||||||
case CV_8S:
|
|
||||||
return CV_8SC(channels);
|
|
||||||
case CV_32F:
|
|
||||||
return CV_32FC(channels);
|
|
||||||
case CV_32S:
|
|
||||||
return CV_32SC(channels);
|
|
||||||
case CV_64F:
|
|
||||||
return CV_64FC(channels);
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
void merge(const vector<aclMat>& mv, aclMat& dest, int stream_id)
|
static int merge_type(int depth, int channels) {
|
||||||
{
|
switch (depth) {
|
||||||
vector<aclDataBuffer *> inputBuffers_;
|
case CV_8U:
|
||||||
vector<aclDataBuffer *> outputBuffers_;
|
return CV_8UC(channels);
|
||||||
|
case CV_8S:
|
||||||
|
return CV_8SC(channels);
|
||||||
|
case CV_32F:
|
||||||
|
return CV_32FC(channels);
|
||||||
|
case CV_32S:
|
||||||
|
return CV_32SC(channels);
|
||||||
|
case CV_64F:
|
||||||
|
return CV_64FC(channels);
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
OperatorDesc opDesc("Concat");
|
void merge(const vector<aclMat> &mv, aclMat &dest, int stream_id) {
|
||||||
aclDataType dataType = type_transition(mv[0].depth());
|
vector<aclDataBuffer *> inputBuffers_;
|
||||||
|
vector<aclDataBuffer *> outputBuffers_;
|
||||||
|
|
||||||
vector<int64_t> inputShape{};
|
OperatorDesc opDesc("Concat");
|
||||||
opDesc.AddInputTensorDesc(ACL_INT32, inputShape.size(), inputShape.data(), ACL_FORMAT_ND);
|
aclDataType dataType = type_transition(mv[0].depth());
|
||||||
|
|
||||||
for (size_t i = 0; i < mv.size(); ++i)
|
vector<int64_t> inputShape{};
|
||||||
{
|
opDesc.AddInputTensorDesc(ACL_INT32, inputShape.size(), inputShape.data(),
|
||||||
int cols = mv[i].step/mv[i].elemSize();
|
ACL_FORMAT_ND);
|
||||||
vector<int64_t> inputShape{1, mv[i].rows, cols, mv[i].channels()};
|
|
||||||
opDesc.AddInputTensorDesc(dataType, inputShape.size(), inputShape.data(), ACL_FORMAT_NHWC);
|
|
||||||
}
|
|
||||||
|
|
||||||
int cols = mv[0].step/mv[0].elemSize();
|
for (size_t i = 0; i < mv.size(); ++i) {
|
||||||
int channels = mv.size();
|
int cols = mv[i].step / mv[i].elemSize();
|
||||||
vector<int64_t> outputShape{1, mv[0].rows, cols, channels};
|
vector<int64_t> inputShape{1, mv[i].rows, cols, mv[i].channels()};
|
||||||
opDesc.AddOutputTensorDesc(dataType, outputShape.size(), outputShape.data(), ACL_FORMAT_NHWC);
|
opDesc.AddInputTensorDesc(dataType, inputShape.size(), inputShape.data(),
|
||||||
|
ACL_FORMAT_NHWC);
|
||||||
|
}
|
||||||
|
|
||||||
ino64_t N = mv.size();
|
int cols = mv[0].step / mv[0].elemSize();
|
||||||
aclopSetAttrInt(opDesc.opAttr, "N", N);
|
int channels = mv.size();
|
||||||
|
vector<int64_t> outputShape{1, mv[0].rows, cols, channels};
|
||||||
|
opDesc.AddOutputTensorDesc(dataType, outputShape.size(), outputShape.data(),
|
||||||
|
ACL_FORMAT_NHWC);
|
||||||
|
|
||||||
aclSetTensorDescName(opDesc.inputDesc[0], "concat_dim");
|
ino64_t N = mv.size();
|
||||||
|
aclopSetAttrInt(opDesc.opAttr, "N", N);
|
||||||
|
|
||||||
aclSetTensorDescName(opDesc.inputDesc[1], "x0");
|
aclSetTensorDescName(opDesc.inputDesc[0], "concat_dim");
|
||||||
aclSetTensorDescName(opDesc.inputDesc[2], "x1");
|
|
||||||
if (mv.size() == 3)
|
|
||||||
aclSetTensorDescName(opDesc.inputDesc[3], "x2");
|
|
||||||
else if(mv.size() == 4)
|
|
||||||
aclSetTensorDescName(opDesc.inputDesc[4], "x3");
|
|
||||||
aclSetTensorDescName(opDesc.outputDesc[0], "y");
|
|
||||||
|
|
||||||
void *dev;
|
aclSetTensorDescName(opDesc.inputDesc[1], "x0");
|
||||||
int64_t concat_dim = 3;
|
aclSetTensorDescName(opDesc.inputDesc[2], "x1");
|
||||||
size_t size = aclGetTensorDescSize(opDesc.inputDesc[0]);
|
if (mv.size() == 3)
|
||||||
aclrtMalloc(&dev, size, ACL_MEM_MALLOC_NORMAL_ONLY);
|
aclSetTensorDescName(opDesc.inputDesc[3], "x2");
|
||||||
aclrtMemcpy(dev, size, &concat_dim, size, ACL_MEMCPY_HOST_TO_DEVICE);
|
else if (mv.size() == 4)
|
||||||
inputBuffers_.emplace_back(aclCreateDataBuffer(dev, size));
|
aclSetTensorDescName(opDesc.inputDesc[4], "x3");
|
||||||
|
aclSetTensorDescName(opDesc.outputDesc[0], "y");
|
||||||
|
|
||||||
for (size_t i = 0; i < mv.size(); ++i)
|
void *dev;
|
||||||
inputBuffers_.emplace_back(aclCreateDataBuffer(mv[i].data, mv[i].totalSize));
|
int64_t concat_dim = 3;
|
||||||
|
size_t size = aclGetTensorDescSize(opDesc.inputDesc[0]);
|
||||||
|
aclrtMalloc(&dev, size, ACL_MEM_MALLOC_NORMAL_ONLY);
|
||||||
|
aclrtMemcpy(dev, size, &concat_dim, size, ACL_MEMCPY_HOST_TO_DEVICE);
|
||||||
|
inputBuffers_.emplace_back(aclCreateDataBuffer(dev, size));
|
||||||
|
|
||||||
int type = merge_type(mv[0].depth(), channels);
|
for (size_t i = 0; i < mv.size(); ++i)
|
||||||
aclMat temp(mv[0].rows, mv[0].cols, type, mv[0].acl_context);
|
inputBuffers_.emplace_back(
|
||||||
dest = temp;
|
aclCreateDataBuffer(mv[i].data, mv[i].totalSize));
|
||||||
outputBuffers_.emplace_back(aclCreateDataBuffer(dest.data, dest.totalSize));
|
|
||||||
|
|
||||||
compileAndRunop(opDesc, inputBuffers_, outputBuffers_, dest.acl_context, stream_id);
|
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));
|
||||||
|
|
||||||
for (size_t i = 0; i < inputBuffers_.size(); i++)
|
compileAndRunop(opDesc, inputBuffers_, outputBuffers_, dest.acl_context,
|
||||||
AclSafeCall(aclDestroyDataBuffer(inputBuffers_[i]));
|
stream_id);
|
||||||
for (size_t i = 0; i < outputBuffers_.size(); i++)
|
|
||||||
AclSafeCall(aclDestroyDataBuffer(outputBuffers_[i]));
|
|
||||||
|
|
||||||
aclrtFree(dev);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
for (size_t i = 0; i < inputBuffers_.size(); i++)
|
||||||
|
AclSafeCall(aclDestroyDataBuffer(inputBuffers_[i]));
|
||||||
|
for (size_t i = 0; i < outputBuffers_.size(); i++)
|
||||||
|
AclSafeCall(aclDestroyDataBuffer(outputBuffers_[i]));
|
||||||
|
|
||||||
|
aclrtFree(dev);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief : Dynamic shape reasoning
|
* @brief : Dynamic shape reasoning
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
void transpose(const aclMat &src, aclMat &dest, int stream_id) {
|
||||||
|
vector<aclDataBuffer *> inputBuffers_;
|
||||||
|
vector<aclDataBuffer *> outputBuffers_;
|
||||||
|
vector<aclDataBuffer *> inputBuffers_host;
|
||||||
|
|
||||||
void transpose(const aclMat& src, aclMat& dest, int stream_id)
|
OperatorDesc opDesc("Transpose");
|
||||||
{
|
aclDataType dataType = type_transition(src.depth());
|
||||||
vector<aclDataBuffer *> inputBuffers_;
|
|
||||||
vector<aclDataBuffer *> outputBuffers_;
|
|
||||||
vector<aclDataBuffer *> inputBuffers_host;
|
|
||||||
|
|
||||||
OperatorDesc opDesc("Transpose");
|
vector<int64_t> inputShape1{1, src.rows, src.cols, src.channels()};
|
||||||
aclDataType dataType = type_transition(src.depth());
|
opDesc.AddInputTensorDesc(dataType, inputShape1.size(), inputShape1.data(),
|
||||||
|
ACL_FORMAT_ND);
|
||||||
|
|
||||||
vector<int64_t> inputShape1{1, src.rows, src.cols, src.channels()};
|
vector<int64_t> inputShape2{4};
|
||||||
opDesc.AddInputTensorDesc(dataType, inputShape1.size(), inputShape1.data(), ACL_FORMAT_ND);
|
opDesc.AddInputTensorDesc(ACL_INT32, inputShape2.size(), inputShape2.data(),
|
||||||
|
ACL_FORMAT_ND);
|
||||||
|
|
||||||
vector<int64_t> inputShape2{4};
|
vector<int64_t> outputShape{-1, -1, -1, -1};
|
||||||
opDesc.AddInputTensorDesc(ACL_INT32, inputShape2.size(), inputShape2.data(), ACL_FORMAT_ND);
|
opDesc.AddOutputTensorDesc(dataType, outputShape.size(), outputShape.data(),
|
||||||
|
ACL_FORMAT_ND);
|
||||||
|
|
||||||
vector<int64_t> outputShape{-1, -1, -1, -1};
|
inputBuffers_.emplace_back(aclCreateDataBuffer(src.data, src.totalSize));
|
||||||
opDesc.AddOutputTensorDesc(dataType, outputShape.size(), outputShape.data(), ACL_FORMAT_ND);
|
|
||||||
|
|
||||||
inputBuffers_.emplace_back(aclCreateDataBuffer(src.data, src.totalSize));
|
void *dev;
|
||||||
|
void *perm;
|
||||||
|
|
||||||
void *dev;
|
size_t size = aclGetTensorDescSize(opDesc.inputDesc[1]);
|
||||||
void *perm;
|
aclrtMalloc(&dev, size, ACL_MEM_MALLOC_NORMAL_ONLY);
|
||||||
|
aclrtMallocHost(&perm, aclGetTensorDescSize(opDesc.inputDesc.data()[1]));
|
||||||
|
((int *)perm)[0] = 0;
|
||||||
|
((int *)perm)[1] = 2;
|
||||||
|
((int *)perm)[2] = 1;
|
||||||
|
((int *)perm)[3] = 3;
|
||||||
|
aclrtMemcpy(dev, size, perm, size, ACL_MEMCPY_HOST_TO_DEVICE);
|
||||||
|
inputBuffers_.emplace_back(aclCreateDataBuffer(dev, size));
|
||||||
|
|
||||||
size_t size = aclGetTensorDescSize(opDesc.inputDesc[1]);
|
AclSafeCall(aclopCompile(opDesc.opType.c_str(), opDesc.inputDesc.size(),
|
||||||
aclrtMalloc(&dev, size, ACL_MEM_MALLOC_NORMAL_ONLY);
|
opDesc.inputDesc.data(), opDesc.outputDesc.size(),
|
||||||
aclrtMallocHost(&perm, aclGetTensorDescSize(opDesc.inputDesc.data()[1]));
|
opDesc.outputDesc.data(), opDesc.opAttr,
|
||||||
((int *)perm)[0] = 0;
|
ACL_ENGINE_SYS, ACL_COMPILE_SYS, nullptr));
|
||||||
((int *)perm)[1] = 2;
|
|
||||||
((int *)perm)[2] = 1;
|
|
||||||
((int *)perm)[3] = 3;
|
|
||||||
aclrtMemcpy(dev, size, perm, size, ACL_MEMCPY_HOST_TO_DEVICE);
|
|
||||||
inputBuffers_.emplace_back(aclCreateDataBuffer(dev, size));
|
|
||||||
|
|
||||||
AclSafeCall(aclopCompile(opDesc.opType.c_str(),
|
void *host_data;
|
||||||
opDesc.inputDesc.size(),
|
size_t host_size = src.totalSize;
|
||||||
opDesc.inputDesc.data(),
|
aclrtMallocHost(&host_data, host_size);
|
||||||
opDesc.outputDesc.size(),
|
aclrtMemcpy(host_data, host_size, src.data, host_size,
|
||||||
opDesc.outputDesc.data(),
|
ACL_MEMCPY_DEVICE_TO_HOST);
|
||||||
opDesc.opAttr,
|
inputBuffers_host.emplace_back(aclCreateDataBuffer(host_data, host_size));
|
||||||
ACL_ENGINE_SYS,
|
inputBuffers_host.emplace_back(aclCreateDataBuffer(perm, size));
|
||||||
ACL_COMPILE_SYS,
|
|
||||||
nullptr));
|
|
||||||
|
|
||||||
void *host_data;
|
AclSafeCall(aclopInferShape("Transpose", opDesc.inputDesc.size(),
|
||||||
size_t host_size = src.totalSize;
|
opDesc.inputDesc.data(), inputBuffers_host.data(),
|
||||||
aclrtMallocHost(&host_data, host_size);
|
opDesc.outputDesc.size(),
|
||||||
aclrtMemcpy(host_data, host_size, src.data, host_size, ACL_MEMCPY_DEVICE_TO_HOST);
|
opDesc.outputDesc.data(), opDesc.opAttr));
|
||||||
inputBuffers_host.emplace_back(aclCreateDataBuffer(host_data, host_size));
|
outputBuffers_.emplace_back(aclCreateDataBuffer(dest.data, dest.totalSize));
|
||||||
inputBuffers_host.emplace_back(aclCreateDataBuffer(perm, size));
|
|
||||||
|
|
||||||
AclSafeCall(aclopInferShape("Transpose", opDesc.inputDesc.size(), opDesc.inputDesc.data(), \
|
AclSafeCall(aclopExecuteV2(opDesc.opType.c_str(), inputBuffers_.size(),
|
||||||
inputBuffers_host.data(), opDesc.outputDesc.size(), opDesc.outputDesc.data(), opDesc.opAttr));
|
opDesc.inputDesc.data(), inputBuffers_.data(),
|
||||||
outputBuffers_.emplace_back(aclCreateDataBuffer(dest.data, dest.totalSize));
|
outputBuffers_.size(), opDesc.outputDesc.data(),
|
||||||
|
outputBuffers_.data(), opDesc.opAttr,
|
||||||
AclSafeCall(aclopExecuteV2(opDesc.opType.c_str(),
|
dest.acl_context->get_stream(stream_id)));
|
||||||
inputBuffers_.size(),
|
|
||||||
opDesc.inputDesc.data(),
|
|
||||||
inputBuffers_.data(),
|
|
||||||
outputBuffers_.size(),
|
|
||||||
opDesc.outputDesc.data(),
|
|
||||||
outputBuffers_.data(),
|
|
||||||
opDesc.opAttr,
|
|
||||||
dest.acl_context->get_stream(stream_id)));
|
|
||||||
|
|
||||||
AclSafeCall(aclDestroyDataBuffer(inputBuffers_[0]));
|
|
||||||
AclSafeCall(aclDestroyDataBuffer(inputBuffers_[1]));
|
|
||||||
AclSafeCall(aclDestroyDataBuffer(inputBuffers_host[0]));
|
|
||||||
AclSafeCall(aclDestroyDataBuffer(inputBuffers_host[1]));
|
|
||||||
AclSafeCall(aclDestroyDataBuffer(outputBuffers_[0]));
|
|
||||||
AclSafeCall(aclrtFree(dev));
|
|
||||||
AclSafeCall(aclrtFreeHost(perm));
|
|
||||||
AclSafeCall(aclrtFreeHost(host_data));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
AclSafeCall(aclDestroyDataBuffer(inputBuffers_[0]));
|
||||||
|
AclSafeCall(aclDestroyDataBuffer(inputBuffers_[1]));
|
||||||
|
AclSafeCall(aclDestroyDataBuffer(inputBuffers_host[0]));
|
||||||
|
AclSafeCall(aclDestroyDataBuffer(inputBuffers_host[1]));
|
||||||
|
AclSafeCall(aclDestroyDataBuffer(outputBuffers_[0]));
|
||||||
|
AclSafeCall(aclrtFree(dev));
|
||||||
|
AclSafeCall(aclrtFreeHost(perm));
|
||||||
|
AclSafeCall(aclrtFreeHost(host_data));
|
||||||
|
}
|
||||||
|
|
||||||
/* transposeD */
|
/* transposeD */
|
||||||
#if 0
|
#if 0
|
||||||
@@ -281,65 +231,63 @@ namespace cv
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static int split_type(int depth)
|
static int split_type(int depth) {
|
||||||
{
|
switch (depth) {
|
||||||
switch (depth)
|
case CV_8U:
|
||||||
{
|
return CV_8UC1;
|
||||||
case CV_8U:
|
case CV_8S:
|
||||||
return CV_8UC1;
|
return CV_8SC1;
|
||||||
case CV_8S:
|
case CV_32F:
|
||||||
return CV_8SC1;
|
return CV_32FC1;
|
||||||
case CV_32F:
|
case CV_32S:
|
||||||
return CV_32FC1;
|
return CV_32SC1;
|
||||||
case CV_32S:
|
case CV_64F:
|
||||||
return CV_32SC1;
|
return CV_64FC1;
|
||||||
case CV_64F:
|
}
|
||||||
return CV_64FC1;
|
return -1;
|
||||||
}
|
}
|
||||||
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 *> inputBuffers_;
|
vector<aclDataBuffer *> outputBuffers_;
|
||||||
vector<aclDataBuffer *> outputBuffers_;
|
int split_dim = 3;
|
||||||
int split_dim = 3;
|
int num_split = src.channels();
|
||||||
int num_split = src.channels();
|
|
||||||
|
|
||||||
OperatorDesc opDesc("SplitD");
|
OperatorDesc opDesc("SplitD");
|
||||||
aclDataType dataType = type_transition(src.depth());
|
aclDataType dataType = type_transition(src.depth());
|
||||||
|
|
||||||
int cols = src.step/src.elemSize();
|
int cols = src.step / src.elemSize();
|
||||||
vector<int64_t> inputShape1{1, src.rows, cols, src.channels()};
|
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};
|
||||||
vector<int64_t> outputShape{1, src.rows, cols, 1};
|
opDesc.AddOutputTensorDesc(dataType, outputShape.size(), outputShape.data(),
|
||||||
opDesc.AddOutputTensorDesc(dataType, outputShape.size(), outputShape.data(), ACL_FORMAT_ND);
|
ACL_FORMAT_ND);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto opAttr = opDesc.opAttr;
|
auto opAttr = opDesc.opAttr;
|
||||||
aclopSetAttrInt(opAttr, "split_dim", split_dim);
|
aclopSetAttrInt(opAttr, "split_dim", split_dim);
|
||||||
aclopSetAttrInt(opAttr, "num_split", num_split);
|
aclopSetAttrInt(opAttr, "num_split", num_split);
|
||||||
|
|
||||||
inputBuffers_.emplace_back(aclCreateDataBuffer(src.data, src.totalSize));
|
inputBuffers_.emplace_back(aclCreateDataBuffer(src.data, src.totalSize));
|
||||||
|
|
||||||
int type = split_type(src.depth());
|
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);
|
||||||
aclMat tmp(src.rows, src.cols, type, src.acl_context);
|
mv[i] = tmp;
|
||||||
mv[i] = tmp;
|
outputBuffers_.emplace_back(
|
||||||
outputBuffers_.emplace_back(aclCreateDataBuffer(mv[i].data, mv[i].totalSize));
|
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]));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
AclSafeCall(aclDestroyDataBuffer(inputBuffers_[0]));
|
||||||
|
for (int i = 0; i < num_split; ++i)
|
||||||
|
AclSafeCall(aclDestroyDataBuffer(outputBuffers_[i]));
|
||||||
|
}
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
//disable
|
//disable
|
||||||
@@ -429,56 +377,57 @@ namespace cv
|
|||||||
}
|
}
|
||||||
#endif
|
#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 *> inputBuffers_;
|
vector<aclDataBuffer *> outputBuffers_;
|
||||||
vector<aclDataBuffer *> outputBuffers_;
|
|
||||||
|
|
||||||
OperatorDesc opDesc("ReverseV2");
|
OperatorDesc opDesc("ReverseV2");
|
||||||
aclDataType dataType = type_transition(src.depth());
|
aclDataType dataType = type_transition(src.depth());
|
||||||
|
|
||||||
vector<int64_t> inputShape1{1, src.rows, src.cols, src.channels()};
|
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};
|
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()};
|
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));
|
inputBuffers_.emplace_back(aclCreateDataBuffer(src.data, src.totalSize));
|
||||||
|
|
||||||
void *dev;
|
void *dev;
|
||||||
size_t size = aclGetTensorDescSize(opDesc.inputDesc[1]);
|
size_t size = aclGetTensorDescSize(opDesc.inputDesc[1]);
|
||||||
aclrtMalloc(&dev, size, ACL_MEM_MALLOC_NORMAL_ONLY);
|
aclrtMalloc(&dev, size, ACL_MEM_MALLOC_NORMAL_ONLY);
|
||||||
aclrtMemcpy(dev, size, &axis, size, ACL_MEMCPY_HOST_TO_DEVICE);
|
aclrtMemcpy(dev, size, &axis, size, ACL_MEMCPY_HOST_TO_DEVICE);
|
||||||
inputBuffers_.emplace_back(aclCreateDataBuffer(dev, size));
|
inputBuffers_.emplace_back(aclCreateDataBuffer(dev, size));
|
||||||
|
|
||||||
outputBuffers_.emplace_back(aclCreateDataBuffer(dest.data, dest.totalSize));
|
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_[0]));
|
||||||
AclSafeCall(aclDestroyDataBuffer(inputBuffers_[1]));
|
AclSafeCall(aclDestroyDataBuffer(inputBuffers_[1]));
|
||||||
AclSafeCall(aclDestroyDataBuffer(outputBuffers_[0]));
|
AclSafeCall(aclDestroyDataBuffer(outputBuffers_[0]));
|
||||||
AclSafeCall(aclrtFree(dev));
|
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) {
|
||||||
if (filpCode == 0) {
|
flip_(src, dest, 1, stream_id);
|
||||||
flip_(src, dest, 1, stream_id);
|
} else if (filpCode > 0) {
|
||||||
}
|
flip_(src, dest, 2, stream_id);
|
||||||
else if (filpCode > 0) {
|
} else {
|
||||||
flip_(src, dest, 2, stream_id);
|
flip_(src, dest, 2, stream_id);
|
||||||
}
|
aclMat tmp(dest.rows, dest.cols, dest.type(), dest.acl_context);
|
||||||
else {
|
aclrtMemcpy(tmp.data, dest.totalSize, dest.data, dest.totalSize,
|
||||||
flip_(src, dest, 2, stream_id);
|
ACL_MEMCPY_DEVICE_TO_DEVICE);
|
||||||
aclMat tmp(dest.rows, dest.cols, dest.type(), dest.acl_context);
|
flip_(tmp, dest, 1, stream_id);
|
||||||
aclrtMemcpy(tmp.data, dest.totalSize, dest.data, dest.totalSize, ACL_MEMCPY_DEVICE_TO_DEVICE);
|
}
|
||||||
flip_(tmp, dest, 1, stream_id);
|
}
|
||||||
}
|
} /* end of namespace acl */
|
||||||
}
|
|
||||||
} /* end of namespace acl */
|
|
||||||
|
|
||||||
} /* end of namespace cv */
|
} /* end of namespace cv */
|
@@ -1,181 +1,166 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @file operator_desc.cpp
|
* @file operator_desc.cpp
|
||||||
*
|
*
|
||||||
* Copyright (C) 2020. Huawei Technologies Co., Ltd. All rights reserved.
|
* Copyright (C) 2020. Huawei Technologies Co., Ltd. All rights reserved.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful,
|
* This program is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "precomp.hpp"
|
#include "precomp.hpp"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
using namespace cv;
|
||||||
|
using namespace cv::acl;
|
||||||
|
namespace cv {
|
||||||
|
namespace acl {
|
||||||
|
OperatorDesc::OperatorDesc(std::string opType) : opType(std::move(opType)) {
|
||||||
|
opAttr = aclopCreateAttr();
|
||||||
|
}
|
||||||
|
|
||||||
namespace cv
|
OperatorDesc::~OperatorDesc() {
|
||||||
{
|
for (auto* desc : inputDesc) {
|
||||||
namespace acl
|
aclDestroyTensorDesc(desc);
|
||||||
{
|
}
|
||||||
OperatorDesc::OperatorDesc(std::string opType) : opType(std::move(opType))
|
|
||||||
{
|
|
||||||
opAttr = aclopCreateAttr();
|
|
||||||
}
|
|
||||||
|
|
||||||
OperatorDesc::~OperatorDesc()
|
for (auto* desc : outputDesc) {
|
||||||
{
|
aclDestroyTensorDesc(desc);
|
||||||
for (auto *desc : inputDesc)
|
}
|
||||||
{
|
|
||||||
aclDestroyTensorDesc(desc);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (auto *desc : outputDesc)
|
aclopDestroyAttr(opAttr);
|
||||||
{
|
}
|
||||||
aclDestroyTensorDesc(desc);
|
|
||||||
}
|
|
||||||
|
|
||||||
aclopDestroyAttr(opAttr);
|
OperatorDesc& OperatorDesc::AddInputTensorDesc(aclDataType dataType,
|
||||||
}
|
int numDims, const int64_t* dims,
|
||||||
|
aclFormat format) {
|
||||||
|
aclTensorDesc* desc = aclCreateTensorDesc(dataType, numDims, dims, format);
|
||||||
|
CV_Assert(desc);
|
||||||
|
inputDesc.emplace_back(desc);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
OperatorDesc &OperatorDesc::AddInputTensorDesc(aclDataType dataType,
|
OperatorDesc& OperatorDesc::AddOutputTensorDesc(aclDataType dataType,
|
||||||
int numDims,
|
int numDims,
|
||||||
const int64_t *dims,
|
const int64_t* dims,
|
||||||
aclFormat format)
|
aclFormat format) {
|
||||||
{
|
aclTensorDesc* desc = aclCreateTensorDesc(dataType, numDims, dims, format);
|
||||||
aclTensorDesc *desc = aclCreateTensorDesc(dataType, numDims, dims, format);
|
CV_Assert(desc);
|
||||||
CV_Assert(desc);
|
outputDesc.emplace_back(desc);
|
||||||
inputDesc.emplace_back(desc);
|
return *this;
|
||||||
return *this;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
OperatorDesc &OperatorDesc::AddOutputTensorDesc(aclDataType dataType,
|
/**
|
||||||
int numDims,
|
* @brief create operator describe
|
||||||
const int64_t *dims,
|
*
|
||||||
aclFormat format)
|
*/
|
||||||
{
|
OperatorDesc CreateOpDesc(const string opType, const vector<aclMat>& input_Mat,
|
||||||
aclTensorDesc *desc = aclCreateTensorDesc(dataType, numDims, dims, format);
|
vector<aclMat>& output_Mat, aclFormat format,
|
||||||
CV_Assert(desc);
|
Opdims config) {
|
||||||
outputDesc.emplace_back(desc);
|
CV_Assert(config == TWO_DIMS || config == FOUR_DIMS);
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
size_t i;
|
||||||
* @brief create operator describe
|
aclDataType dataType = type_transition(input_Mat[0].depth());
|
||||||
*
|
|
||||||
*/
|
|
||||||
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;
|
OperatorDesc opDesc(opType);
|
||||||
aclDataType dataType = type_transition(input_Mat[0].depth());
|
for (i = 0; i < input_Mat.size(); ++i) {
|
||||||
|
if (config == TWO_DIMS) {
|
||||||
|
int cols = input_Mat[i].step / input_Mat[i].elemSize();
|
||||||
|
vector<int64_t> shape{input_Mat[i].rows, cols};
|
||||||
|
opDesc.AddInputTensorDesc(dataType, shape.size(), shape.data(), format);
|
||||||
|
} else if (config == FOUR_DIMS) {
|
||||||
|
int cols = input_Mat[i].step / input_Mat[i].elemSize();
|
||||||
|
vector<int64_t> shape{1, input_Mat[i].rows, cols,
|
||||||
|
input_Mat[i].channels()};
|
||||||
|
opDesc.AddInputTensorDesc(dataType, shape.size(), shape.data(), format);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
OperatorDesc opDesc(opType);
|
for (i = 0; i < output_Mat.size(); ++i) {
|
||||||
for (i = 0; i < input_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};
|
||||||
int cols = input_Mat[i].step / input_Mat[i].elemSize();
|
opDesc.AddOutputTensorDesc(dataType, shape.size(), shape.data(), format);
|
||||||
vector<int64_t> shape{input_Mat[i].rows, cols};
|
} else if (config == FOUR_DIMS) {
|
||||||
opDesc.AddInputTensorDesc(dataType, shape.size(), shape.data(), format);
|
int cols = output_Mat[i].step / output_Mat[i].elemSize();
|
||||||
}
|
vector<int64_t> shape{1, output_Mat[i].rows, cols,
|
||||||
else if(config == FOUR_DIMS)
|
output_Mat[i].channels()};
|
||||||
{
|
opDesc.AddOutputTensorDesc(dataType, shape.size(), shape.data(), format);
|
||||||
int cols = input_Mat[i].step / input_Mat[i].elemSize();
|
}
|
||||||
vector<int64_t> shape{1, input_Mat[i].rows, cols, input_Mat[i].channels()};
|
}
|
||||||
opDesc.AddInputTensorDesc(dataType, shape.size(), shape.data(), format);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < output_Mat.size(); ++i) {
|
return opDesc;
|
||||||
if (config == TWO_DIMS)
|
}
|
||||||
{
|
|
||||||
int cols = output_Mat[i].step / output_Mat[i].elemSize();
|
|
||||||
vector<int64_t> shape{output_Mat[i].rows, cols};
|
|
||||||
opDesc.AddOutputTensorDesc(dataType, shape.size(), shape.data(), format);
|
|
||||||
}
|
|
||||||
else if(config == FOUR_DIMS)
|
|
||||||
{
|
|
||||||
int cols = output_Mat[i].step / output_Mat[i].elemSize();
|
|
||||||
vector<int64_t> shape{1, output_Mat[i].rows, cols, output_Mat[i].channels()};
|
|
||||||
opDesc.AddOutputTensorDesc(dataType, shape.size(), shape.data(), format);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return opDesc;
|
/**
|
||||||
}
|
* @brief compile and run operator
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void compileAndRunop(OperatorDesc& opDesc,
|
||||||
|
vector<aclDataBuffer*>& inputBuffers_,
|
||||||
|
vector<aclDataBuffer*>& outputBuffers_,
|
||||||
|
aclCxt* acl_context, int stream_id) {
|
||||||
|
AclSafeCall(aclopCompile(opDesc.opType.c_str(), opDesc.inputDesc.size(),
|
||||||
|
opDesc.inputDesc.data(), opDesc.outputDesc.size(),
|
||||||
|
opDesc.outputDesc.data(), opDesc.opAttr,
|
||||||
|
ACL_ENGINE_SYS, ACL_COMPILE_SYS, nullptr));
|
||||||
|
|
||||||
/**
|
AclSafeCall(aclopExecuteV2(opDesc.opType.c_str(), inputBuffers_.size(),
|
||||||
* @brief compile and run operator
|
opDesc.inputDesc.data(), inputBuffers_.data(),
|
||||||
*
|
outputBuffers_.size(), opDesc.outputDesc.data(),
|
||||||
*/
|
outputBuffers_.data(), opDesc.opAttr,
|
||||||
void compileAndRunop(OperatorDesc& opDesc, vector<aclDataBuffer *>& inputBuffers_, vector<aclDataBuffer *>& outputBuffers_, aclCxt *acl_context, int stream_id)
|
acl_context->get_stream(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(),
|
void Runop(vector<aclMat>& input, vector<aclMat>& output, OperatorDesc& opDesc,
|
||||||
inputBuffers_.size(),
|
int stream_id) {
|
||||||
opDesc.inputDesc.data(),
|
size_t i;
|
||||||
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)
|
vector<aclDataBuffer*> inputBuffers_;
|
||||||
{
|
vector<aclDataBuffer*> outputBuffers_;
|
||||||
size_t i;
|
|
||||||
|
|
||||||
vector<aclDataBuffer *> inputBuffers_;
|
for (i = 0; i < input.size(); ++i)
|
||||||
vector<aclDataBuffer *> outputBuffers_;
|
inputBuffers_.emplace_back(
|
||||||
|
aclCreateDataBuffer(input[i].data, input[i].totalSize));
|
||||||
|
for (i = 0; i < output.size(); ++i)
|
||||||
|
outputBuffers_.emplace_back(
|
||||||
|
aclCreateDataBuffer(output[i].data, output[i].totalSize));
|
||||||
|
|
||||||
for (i = 0; i < input.size(); ++i)
|
compileAndRunop(opDesc, inputBuffers_, outputBuffers_, output[0].acl_context,
|
||||||
inputBuffers_.emplace_back(aclCreateDataBuffer(input[i].data, input[i].totalSize));
|
stream_id);
|
||||||
for (i = 0; i < output.size(); ++i)
|
|
||||||
outputBuffers_.emplace_back(aclCreateDataBuffer(output[i].data, output[i].totalSize));
|
|
||||||
|
|
||||||
compileAndRunop(opDesc, inputBuffers_, outputBuffers_, output[0].acl_context, stream_id);
|
for (i = 0; i < input.size(); ++i)
|
||||||
|
AclSafeCall(aclDestroyDataBuffer(inputBuffers_[i]));
|
||||||
|
for (i = 0; i < output.size(); ++i)
|
||||||
|
AclSafeCall(aclDestroyDataBuffer(outputBuffers_[i]));
|
||||||
|
}
|
||||||
|
|
||||||
for (i = 0; i < input.size(); ++i)
|
void OneInAndOneOut(const aclMat& inputMat, aclMat& outputMat,
|
||||||
AclSafeCall(aclDestroyDataBuffer(inputBuffers_[i]));
|
const string opType, int stream_id) {
|
||||||
for (i = 0; i < output.size(); ++i)
|
vector<aclMat> input_Mat;
|
||||||
AclSafeCall(aclDestroyDataBuffer(outputBuffers_[i]));
|
vector<aclMat> output_Mat;
|
||||||
}
|
|
||||||
|
|
||||||
void OneInAndOneOut(const aclMat& inputMat, aclMat& outputMat, const string opType, int stream_id)
|
input_Mat.emplace_back(inputMat);
|
||||||
{
|
output_Mat.emplace_back(outputMat);
|
||||||
vector<aclMat> input_Mat;
|
|
||||||
vector<aclMat> output_Mat;
|
|
||||||
|
|
||||||
input_Mat.emplace_back(inputMat);
|
OperatorDesc opDesc = CreateOpDesc(opType, input_Mat, output_Mat);
|
||||||
output_Mat.emplace_back(outputMat);
|
Runop(input_Mat, output_Mat, opDesc, stream_id);
|
||||||
|
}
|
||||||
|
|
||||||
OperatorDesc opDesc = CreateOpDesc(opType, input_Mat, output_Mat);
|
void TwoInAndOneOut(const aclMat& inputMat, const aclMat& inputMatOther,
|
||||||
Runop(input_Mat, output_Mat, opDesc, stream_id);
|
aclMat& outputMat, const string opType, int stream_id) {
|
||||||
}
|
vector<aclMat> input_Mat;
|
||||||
|
vector<aclMat> output_Mat;
|
||||||
|
|
||||||
void TwoInAndOneOut(const aclMat& inputMat, const aclMat& inputMatOther, aclMat& outputMat, const string opType, int stream_id)
|
input_Mat.emplace_back(inputMat);
|
||||||
{
|
input_Mat.emplace_back(inputMatOther);
|
||||||
vector<aclMat> input_Mat;
|
output_Mat.emplace_back(outputMat);
|
||||||
vector<aclMat> output_Mat;
|
|
||||||
|
|
||||||
input_Mat.emplace_back(inputMat);
|
OperatorDesc opDesc = CreateOpDesc(opType, input_Mat, output_Mat);
|
||||||
input_Mat.emplace_back(inputMatOther);
|
Runop(input_Mat, output_Mat, opDesc, stream_id);
|
||||||
output_Mat.emplace_back(outputMat);
|
}
|
||||||
|
|
||||||
OperatorDesc opDesc = CreateOpDesc(opType, input_Mat, output_Mat);
|
} /* end of namespace acl */
|
||||||
Runop(input_Mat, output_Mat, opDesc, stream_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
} /* end of namespace acl */
|
|
||||||
|
|
||||||
} /* end of namespace cv */
|
} /* end of namespace cv */
|
||||||
|
@@ -1,8 +1,9 @@
|
|||||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
/* M///////////////////////////////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
// 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,
|
// If you do not agree to this license, do not download, install,
|
||||||
// copy or use the software.
|
// copy or use the software.
|
||||||
//
|
//
|
||||||
@@ -14,23 +15,29 @@
|
|||||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||||
// Third party copyrights are property of their respective owners.
|
// 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:
|
// are permitted provided that the following conditions are met:
|
||||||
//
|
//
|
||||||
// * Redistribution's of source code must retain the above copyright notice,
|
// * Redistribution's of source code must retain the above copyright notice,
|
||||||
// this list of conditions and the following disclaimer.
|
// 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
|
// this list of conditions and the following disclaimer in the documentation
|
||||||
// and/or other materials provided with the distribution.
|
// 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.
|
// 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
|
// any express or implied warranties, including, but not limited to, the implied
|
||||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
// warranties of merchantability and fitness for a particular purpose are
|
||||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
disclaimed.
|
||||||
|
// In no event shall the Intel Corporation or contributors be liable for any
|
||||||
|
direct,
|
||||||
// indirect, incidental, special, exemplary, or consequential damages
|
// indirect, incidental, special, exemplary, or consequential damages
|
||||||
// (including, but not limited to, procurement of substitute goods or services;
|
// (including, but not limited to, procurement of substitute goods or services;
|
||||||
// loss of use, data, or profits; or business interruption) however caused
|
// loss of use, data, or profits; or business interruption) however caused
|
||||||
@@ -38,12 +45,11 @@
|
|||||||
// or tort (including negligence or otherwise) arising in any way out of
|
// 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.
|
// the use of this software, even if advised of the possibility of such damage.
|
||||||
//
|
//
|
||||||
//M*/
|
//M */
|
||||||
|
|
||||||
#ifndef OPENCV_ACL_PRECOMP_HPP__
|
#ifndef OPENCV_ACL_PRECOMP_HPP__
|
||||||
#define OPENCV_ACL_PRECOMP_HPP__
|
#define OPENCV_ACL_PRECOMP_HPP__
|
||||||
|
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <float.h>
|
#include <float.h>
|
||||||
@@ -52,19 +58,16 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#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.h"
|
||||||
#include "acl/acl_op_compiler.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
|
#endif
|
||||||
|
532
acl/test/acl.cpp
532
acl/test/acl.cpp
@@ -1,299 +1,277 @@
|
|||||||
|
#include "test_common.hpp"
|
||||||
#include "test_correctness.hpp"
|
#include "test_correctness.hpp"
|
||||||
#include "test_perf.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 opencv_test {
|
||||||
{
|
namespace {
|
||||||
namespace
|
aclCxt *acl_context_0 = set_device("../../modules/acl/test/acl.json", 2, 3);
|
||||||
{
|
////////////////////////////////////////////////////Correctness_test////////////////////////////////////////////////////////
|
||||||
aclCxt *acl_context_0 = set_device("../../modules/acl/test/acl.json", 2, 3);
|
/* range: rows: 1 ~ 64, cols: 1 ~ 64, type: 0 ~ 7
|
||||||
////////////////////////////////////////////////////Correctness_test////////////////////////////////////////////////////////
|
* test function:
|
||||||
/* range: rows: 1 ~ 64, cols: 1 ~ 64, type: 0 ~ 7
|
* config: MEMORY_ALIGN
|
||||||
* test function:
|
* aclMat(int rows, int cols, int type, aclCxt *acl_context, ALIGNMENT config =
|
||||||
* config: MEMORY_ALIGN
|
* 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 =
|
||||||
* aclMat(Size size, int type, aclCxt *acl_context, ALIGNMENT config = MEMORY_UNALIGNED, aclrtMemMallocPolicy policy = ACL_MEM_MALLOC_HUGE_FIRST);
|
* MEMORY_UNALIGNED, aclrtMemMallocPolicy policy = ACL_MEM_MALLOC_HUGE_FIRST);
|
||||||
* aclMat(const aclMat &m);
|
* aclMat(const aclMat &m);
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
TEST(ACLMAT_CONSTRUCTOR, MEMORY_ALIGN)
|
TEST(ACLMAT_CONSTRUCTOR, MEMORY_ALIGN) {
|
||||||
{
|
AclMat_Test test;
|
||||||
AclMat_Test test;
|
test.Test_constructor_ALIGN(acl_context_0);
|
||||||
test.Test_constructor_ALIGN(acl_context_0);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/* range: rows: 1 ~ 64, cols: 1 ~ 64, type: 0 ~ 7
|
/* range: rows: 1 ~ 64, cols: 1 ~ 64, type: 0 ~ 7
|
||||||
* test function:
|
* test function:
|
||||||
* config: MEMORY_UNALIGNED
|
* 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(int rows, int cols, int type, aclCxt *acl_context, ALIGNMENT config =
|
||||||
* aclMat(Size size, int type, aclCxt *acl_context, ALIGNMENT config = MEMORY_UNALIGNED, aclrtMemMallocPolicy policy = ACL_MEM_MALLOC_HUGE_FIRST);
|
* MEMORY_UNALIGNED, aclrtMemMallocPolicy policy = ACL_MEM_MALLOC_HUGE_FIRST);
|
||||||
*
|
* aclMat(Size size, int type, aclCxt *acl_context, ALIGNMENT config =
|
||||||
*/
|
* MEMORY_UNALIGNED, aclrtMemMallocPolicy policy = ACL_MEM_MALLOC_HUGE_FIRST);
|
||||||
TEST(ACLMAT_CONSTRUCTOR, MEMORY_UNALIGNED)
|
*
|
||||||
{
|
*/
|
||||||
AclMat_Test test;
|
TEST(ACLMAT_CONSTRUCTOR, MEMORY_UNALIGNED) {
|
||||||
test.Test_constructor_UNALIGNED(acl_context_0);
|
AclMat_Test test;
|
||||||
}
|
test.Test_constructor_UNALIGNED(acl_context_0);
|
||||||
|
}
|
||||||
|
|
||||||
/* range: rows: 1 ~ 64, cols: 1 ~ 64, type: 0 ~ 7
|
/* range: rows: 1 ~ 64, cols: 1 ~ 64, type: 0 ~ 7
|
||||||
* test function:
|
* test function:
|
||||||
* aclMat(const aclMat &m);
|
* aclMat(const aclMat &m);
|
||||||
*/
|
*/
|
||||||
TEST(ACLMAT_CONSTRUCTOR, COPY_CONSTRUCTOR)
|
TEST(ACLMAT_CONSTRUCTOR, COPY_CONSTRUCTOR) {
|
||||||
{
|
AclMat_Test test;
|
||||||
AclMat_Test test;
|
test.Test_constructor(acl_context_0);
|
||||||
test.Test_constructor(acl_context_0);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/* range: rows: 1 ~ 64, cols: 1 ~ 64, type: 0 ~ 7
|
/* range: rows: 1 ~ 64, cols: 1 ~ 64, type: 0 ~ 7
|
||||||
* test function:
|
* 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(int rows, int cols, int type, void *data, aclCxt* acl_context,
|
||||||
* aclMat(Size size, int type, void *data, aclCxt* acl_context, ALIGNMENT config = MEMORY_UNALIGNED, size_t step = Mat::AUTO_STEP);
|
* ALIGNMENT config = MEMORY_UNALIGNED, size_t step = Mat::AUTO_STEP);
|
||||||
*/
|
* aclMat(Size size, int type, void *data, aclCxt* acl_context, ALIGNMENT config
|
||||||
TEST(ACLMAT_CONSTRUCTOR, DATA)
|
* = MEMORY_UNALIGNED, size_t step = Mat::AUTO_STEP);
|
||||||
{
|
*/
|
||||||
AclMat_Test test;
|
TEST(ACLMAT_CONSTRUCTOR, DATA) {
|
||||||
test.Test_constructor_DATA(acl_context_0);
|
AclMat_Test test;
|
||||||
}
|
test.Test_constructor_DATA(acl_context_0);
|
||||||
|
}
|
||||||
|
|
||||||
/* range: rows: 1 ~ 64, cols: 1 ~ 64, type: 0 ~ 7
|
/* range: rows: 1 ~ 64, cols: 1 ~ 64, type: 0 ~ 7
|
||||||
* test function:
|
* 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;
|
AclMat_Test test;
|
||||||
test.Test_constructor_RANGE(acl_context_0);
|
test.Test_constructor_RANGE(acl_context_0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* test function:
|
* test function:
|
||||||
* aclMat(const aclMat &m, const Rect &roi);
|
* aclMat(const aclMat &m, const Rect &roi);
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
TEST(ACLMAT_CONSTRUCTOR, ROI)
|
TEST(ACLMAT_CONSTRUCTOR, ROI) {
|
||||||
{
|
AclMat_Test test;
|
||||||
AclMat_Test test;
|
test.Test_constructor_ROI(acl_context_0);
|
||||||
test.Test_constructor_ROI(acl_context_0);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* test function:
|
* 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;
|
AclMat_Test test;
|
||||||
test.Test_constructor_MAT(acl_context_0);
|
test.Test_constructor_MAT(acl_context_0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* range: rows: 1 ~ 64, cols: 1 ~ 64, type: 0 ~ 7
|
/* range: rows: 1 ~ 64, cols: 1 ~ 64, type: 0 ~ 7
|
||||||
* test function:
|
* test function:
|
||||||
* CV_EXPORTS void upload(const Mat &m, ALIGNMENT config = MEMORY_UNALIGNED);
|
* 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;
|
AclMat_Test test;
|
||||||
test.Test_DATA_TRANSFER(acl_context_0);
|
test.Test_DATA_TRANSFER(acl_context_0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* range: rows: 1 ~ 64, cols: 1 ~ 64, type: 0 ~ 7
|
/* range: rows: 1 ~ 64, cols: 1 ~ 64, type: 0 ~ 7
|
||||||
* test function:
|
* test function:
|
||||||
* CV_EXPORTS void download(Mat &m, ALIGNMENT config = MEMORY_UNALIGNED) const;
|
* 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;
|
AclMat_Test test;
|
||||||
test.Test_DATA_TRANSFERASYNC(acl_context_0);
|
test.Test_DATA_TRANSFERASYNC(acl_context_0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* test function:
|
* test function:
|
||||||
* void locateROI(Size &wholeSize, Point &ofs) const;
|
* void locateROI(Size &wholeSize, Point &ofs) const;
|
||||||
*/
|
*/
|
||||||
TEST(ACLMAT_FUNCTION, LOCATEROI)
|
TEST(ACLMAT_FUNCTION, LOCATEROI) {
|
||||||
{
|
AclMat_Test test;
|
||||||
AclMat_Test test;
|
test.Test_locateROI(acl_context_0);
|
||||||
test.Test_locateROI(acl_context_0);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* test function:
|
* test function:
|
||||||
* void swap(aclMat &mat);
|
* void swap(aclMat &mat);
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
TEST(ACLMAT_FUNCTION, SWAP)
|
TEST(ACLMAT_FUNCTION, SWAP) {
|
||||||
{
|
AclMat_Test test;
|
||||||
AclMat_Test test;
|
test.Test_swap(acl_context_0);
|
||||||
test.Test_swap(acl_context_0);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* test function:
|
* test function:
|
||||||
* operator+=()
|
* operator+=()
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
TEST(ACLMAT_FUNCTION, OPERATOR_ADD)
|
TEST(ACLMAT_FUNCTION, OPERATOR_ADD) {
|
||||||
{
|
AclMat_Test test;
|
||||||
AclMat_Test test;
|
test.Test_operator_add(acl_context_0);
|
||||||
test.Test_operator_add(acl_context_0);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* test function:
|
* test function:
|
||||||
* operator-=()
|
* operator-=()
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
TEST(ACLMAT_FUNCTION, OPERATOR_SUB)
|
TEST(ACLMAT_FUNCTION, OPERATOR_SUB) {
|
||||||
{
|
AclMat_Test test;
|
||||||
AclMat_Test test;
|
test.Test_operator_sub(acl_context_0);
|
||||||
test.Test_operator_sub(acl_context_0);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* test function:
|
* test function:
|
||||||
* operator*=()
|
* operator*=()
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
TEST(ACLMAT_FUNCTION, OPERATOR_MUL)
|
TEST(ACLMAT_FUNCTION, OPERATOR_MUL) {
|
||||||
{
|
AclMat_Test test;
|
||||||
AclMat_Test test;
|
test.Test_operator_mul(acl_context_0);
|
||||||
test.Test_operator_mul(acl_context_0);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* test function:
|
* test function:
|
||||||
* operator/=()
|
* operator/=()
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
TEST(ACLMAT_FUNCTION, OPERATOR_DIV)
|
TEST(ACLMAT_FUNCTION, OPERATOR_DIV) {
|
||||||
{
|
AclMat_Test test;
|
||||||
AclMat_Test test;
|
test.Test_operator_div(acl_context_0);
|
||||||
test.Test_operator_div(acl_context_0);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////Perf_test////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////Perf_test////////////////////////////////////////////////////////
|
||||||
|
|
||||||
TEST(Operator, add)
|
TEST(Operator, add) {
|
||||||
{
|
PERF_TEST test;
|
||||||
PERF_TEST test;
|
test.Test_operator_add_perf(acl_context_0);
|
||||||
test.Test_operator_add_perf(acl_context_0);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(Operator, sub)
|
|
||||||
{
|
|
||||||
PERF_TEST test;
|
|
||||||
test.Test_operator_sub_perf(acl_context_0);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(Operator, div)
|
|
||||||
{
|
|
||||||
PERF_TEST test;
|
|
||||||
test.Test_operator_div_perf(acl_context_0);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(Operator, mul)
|
|
||||||
{
|
|
||||||
PERF_TEST test;
|
|
||||||
test.Test_operator_mul_perf(acl_context_0);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(Mathfunction, abs)
|
|
||||||
{
|
|
||||||
PERF_TEST test;
|
|
||||||
test.Test_Abs(acl_context_0);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(Mathfunction, pow)
|
|
||||||
{
|
|
||||||
PERF_TEST test;
|
|
||||||
test.Test_Pow(acl_context_0);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(Mathfunction, sqrt)
|
|
||||||
{
|
|
||||||
PERF_TEST test;
|
|
||||||
test.Test_Sqrt(acl_context_0);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(Mathfunction, add)
|
|
||||||
{
|
|
||||||
PERF_TEST test;
|
|
||||||
test.Test_Add(acl_context_0);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(Mathfunction, divide)
|
|
||||||
{
|
|
||||||
PERF_TEST test;
|
|
||||||
test.Test_Divide(acl_context_0);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(Mathfunction, exp)
|
|
||||||
{
|
|
||||||
PERF_TEST test;
|
|
||||||
test.Test_Exp(acl_context_0);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(Mathfunction, log)
|
|
||||||
{
|
|
||||||
PERF_TEST test;
|
|
||||||
test.Test_Log(acl_context_0);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(Mathfunction, max)
|
|
||||||
{
|
|
||||||
PERF_TEST test;
|
|
||||||
test.Test_Max(acl_context_0);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(Mathfunction, min)
|
|
||||||
{
|
|
||||||
PERF_TEST test;
|
|
||||||
test.Test_Min(acl_context_0);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(Gemm, MatMul)
|
|
||||||
{
|
|
||||||
PERF_TEST test;
|
|
||||||
test.Test_MatMul(acl_context_0);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(Gemm, Convolution)
|
|
||||||
{
|
|
||||||
PERF_TEST test;
|
|
||||||
test.Test_Convolution(acl_context_0);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(Matrices, merge)
|
|
||||||
{
|
|
||||||
PERF_TEST test;
|
|
||||||
test.Test_Merge(acl_context_0);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(Matrices, split)
|
|
||||||
{
|
|
||||||
PERF_TEST test;
|
|
||||||
test.Test_Split(acl_context_0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
TEST(Matrices, transpose)
|
|
||||||
{
|
|
||||||
PERF_TEST test;
|
|
||||||
test.Test_Transpose(acl_context_0);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(Matrices, flip)
|
|
||||||
{
|
|
||||||
PERF_TEST test;
|
|
||||||
test.Test_Flip(acl_context_0);
|
|
||||||
release_device(acl_context_0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(Operator, sub) {
|
||||||
|
PERF_TEST test;
|
||||||
|
test.Test_operator_sub_perf(acl_context_0);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(Operator, div) {
|
||||||
|
PERF_TEST test;
|
||||||
|
test.Test_operator_div_perf(acl_context_0);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(Operator, mul) {
|
||||||
|
PERF_TEST test;
|
||||||
|
test.Test_operator_mul_perf(acl_context_0);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(Mathfunction, abs) {
|
||||||
|
PERF_TEST test;
|
||||||
|
test.Test_Abs(acl_context_0);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(Mathfunction, pow) {
|
||||||
|
PERF_TEST test;
|
||||||
|
test.Test_Pow(acl_context_0);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(Mathfunction, sqrt) {
|
||||||
|
PERF_TEST test;
|
||||||
|
test.Test_Sqrt(acl_context_0);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(Mathfunction, add) {
|
||||||
|
PERF_TEST test;
|
||||||
|
test.Test_Add(acl_context_0);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(Mathfunction, divide) {
|
||||||
|
PERF_TEST test;
|
||||||
|
test.Test_Divide(acl_context_0);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(Mathfunction, exp) {
|
||||||
|
PERF_TEST test;
|
||||||
|
test.Test_Exp(acl_context_0);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(Mathfunction, log) {
|
||||||
|
PERF_TEST test;
|
||||||
|
test.Test_Log(acl_context_0);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(Mathfunction, max) {
|
||||||
|
PERF_TEST test;
|
||||||
|
test.Test_Max(acl_context_0);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(Mathfunction, min) {
|
||||||
|
PERF_TEST test;
|
||||||
|
test.Test_Min(acl_context_0);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(Gemm, MatMul) {
|
||||||
|
PERF_TEST test;
|
||||||
|
test.Test_MatMul(acl_context_0);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(Gemm, Convolution) {
|
||||||
|
PERF_TEST test;
|
||||||
|
test.Test_Convolution(acl_context_0);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(Matrices, merge) {
|
||||||
|
PERF_TEST test;
|
||||||
|
test.Test_Merge(acl_context_0);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(Matrices, split) {
|
||||||
|
PERF_TEST test;
|
||||||
|
test.Test_Split(acl_context_0);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(Matrices, transpose) {
|
||||||
|
PERF_TEST test;
|
||||||
|
test.Test_Transpose(acl_context_0);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(Matrices, flip) {
|
||||||
|
PERF_TEST test;
|
||||||
|
test.Test_Flip(acl_context_0);
|
||||||
|
release_device(acl_context_0);
|
||||||
|
}
|
||||||
|
} // namespace
|
||||||
|
} // namespace opencv_test
|
@@ -1,2 +1 @@
|
|||||||
{
|
{}
|
||||||
}
|
|
@@ -1,216 +1,202 @@
|
|||||||
#include "test_common.hpp"
|
#include "test_common.hpp"
|
||||||
#include "test_perf.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 val, n;
|
int valmax = 8192;
|
||||||
int valmax = 8192;
|
int cycle_index = 10;
|
||||||
int cycle_index = 10;
|
double begin, end, time, acltime;
|
||||||
double begin, end, time, acltime;
|
Common_Test test;
|
||||||
Common_Test test;
|
|
||||||
|
|
||||||
vector<int> type{CV_8UC1, CV_32FC1, CV_32SC1, CV_64FC1};
|
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]);
|
||||||
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]);
|
||||||
n = cycle_index;
|
Mat mat_dest(val, val, type[i]);
|
||||||
Mat mat_src(val, val, type[i]);
|
Mat mat_dest1(val, val, type[i]);
|
||||||
Mat mat_dest(val, val, type[i]);
|
|
||||||
Mat mat_dest1(val, val, type[i]);
|
|
||||||
|
|
||||||
test.SetDataRange(mat_src, 1);
|
test.SetDataRange(mat_src, 1);
|
||||||
test.SetDataRange(mat_dest, 1);
|
test.SetDataRange(mat_dest, 1);
|
||||||
|
|
||||||
aclMat aclmat_src(val, val, type[i], mat_src.data, acl_context);
|
aclMat aclmat_src(val, val, type[i], mat_src.data, acl_context);
|
||||||
aclMat aclmat_dest(val, val, type[i], mat_dest.data, acl_context);
|
aclMat aclmat_dest(val, val, type[i], mat_dest.data, acl_context);
|
||||||
|
|
||||||
begin = static_cast<double>(getTickCount());
|
begin = static_cast<double>(getTickCount());
|
||||||
while (n--)
|
while (n--) mat_dest += mat_src;
|
||||||
mat_dest += mat_src;
|
end = static_cast<double>(getTickCount());
|
||||||
end = static_cast<double>(getTickCount());
|
time = (end - begin) / getTickFrequency() / cycle_index;
|
||||||
time = (end - begin) / getTickFrequency() / cycle_index;
|
|
||||||
|
|
||||||
n = (cycle_index - 1);
|
n = (cycle_index - 1);
|
||||||
aclmat_dest += aclmat_src;
|
aclmat_dest += aclmat_src;
|
||||||
wait_stream(acl_context);
|
wait_stream(acl_context);
|
||||||
begin = static_cast<double>(getTickCount());
|
begin = static_cast<double>(getTickCount());
|
||||||
while (n--)
|
while (n--) aclmat_dest += aclmat_src;
|
||||||
aclmat_dest += aclmat_src;
|
wait_stream(acl_context);
|
||||||
wait_stream(acl_context);
|
end = static_cast<double>(getTickCount());
|
||||||
end = static_cast<double>(getTickCount());
|
acltime = (end - begin) / getTickFrequency() / (cycle_index - 1);
|
||||||
acltime = (end - begin) / getTickFrequency() / (cycle_index - 1);
|
|
||||||
|
|
||||||
aclmat_dest.download(mat_dest1);
|
aclmat_dest.download(mat_dest1);
|
||||||
bool ret = test.Test_Diff(mat_dest, mat_dest1);
|
bool ret = test.Test_Diff(mat_dest, mat_dest1);
|
||||||
ASSERT_TRUE(ret);
|
ASSERT_TRUE(ret);
|
||||||
if (val < 128)
|
if (val < 128)
|
||||||
cout << "Shape: " << val << " x " << val << "\t\t";
|
cout << "Shape: " << val << " x " << val << "\t\t";
|
||||||
else
|
else
|
||||||
cout << "Shape: " << val << " x " << val << "\t";
|
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 val, n;
|
int valmax = 8192;
|
||||||
int valmax = 8192;
|
int cycle_index = 10;
|
||||||
int cycle_index = 10;
|
double begin, end, time, acltime;
|
||||||
double begin, end, time, acltime;
|
Common_Test test;
|
||||||
Common_Test test;
|
|
||||||
|
|
||||||
vector<int> type{CV_8UC1, CV_32FC1, CV_32SC1,CV_64FC1};
|
vector<int> type{CV_8UC1, CV_32FC1, CV_32SC1, CV_64FC1};
|
||||||
//vector<int> type{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]);
|
||||||
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]);
|
||||||
n = cycle_index;
|
Mat mat_dest(val, val, type[i]);
|
||||||
Mat mat_src(val, val, type[i]);
|
Mat mat_dest1(val, val, type[i]);
|
||||||
Mat mat_dest(val, val, type[i]);
|
|
||||||
Mat mat_dest1(val, val, type[i]);
|
|
||||||
|
|
||||||
test.SetDataRange(mat_src, 4);
|
test.SetDataRange(mat_src, 4);
|
||||||
test.SetDataRange(mat_dest, 32);
|
test.SetDataRange(mat_dest, 32);
|
||||||
|
|
||||||
aclMat aclmat_src(val, val, type[i], mat_src.data, acl_context);
|
aclMat aclmat_src(val, val, type[i], mat_src.data, acl_context);
|
||||||
aclMat aclmat_dest(val, val, type[i], mat_dest.data, acl_context);
|
aclMat aclmat_dest(val, val, type[i], mat_dest.data, acl_context);
|
||||||
|
|
||||||
begin = static_cast<double>(getTickCount());
|
begin = static_cast<double>(getTickCount());
|
||||||
while (n--)
|
while (n--) mat_dest -= mat_src;
|
||||||
mat_dest -= mat_src;
|
end = static_cast<double>(getTickCount());
|
||||||
end = static_cast<double>(getTickCount());
|
time = (end - begin) / getTickFrequency() / cycle_index;
|
||||||
time = (end - begin) / getTickFrequency() / cycle_index;
|
|
||||||
|
|
||||||
n = (cycle_index - 1);
|
n = (cycle_index - 1);
|
||||||
aclmat_dest -= aclmat_src;
|
aclmat_dest -= aclmat_src;
|
||||||
wait_stream(acl_context);
|
wait_stream(acl_context);
|
||||||
begin = static_cast<double>(getTickCount());
|
begin = static_cast<double>(getTickCount());
|
||||||
while (n--)
|
while (n--) aclmat_dest -= aclmat_src;
|
||||||
aclmat_dest -= aclmat_src;
|
wait_stream(acl_context);
|
||||||
wait_stream(acl_context);
|
end = static_cast<double>(getTickCount());
|
||||||
end = static_cast<double>(getTickCount());
|
acltime = (end - begin) / getTickFrequency() / (cycle_index - 1);
|
||||||
acltime = (end - begin) / getTickFrequency() / (cycle_index - 1);
|
|
||||||
|
|
||||||
aclmat_dest.download(mat_dest1);
|
aclmat_dest.download(mat_dest1);
|
||||||
//bool ret = test.Test_Diff(mat_dest, mat_dest1);
|
// bool ret = test.Test_Diff(mat_dest, mat_dest1);
|
||||||
//ASSERT_TRUE(ret);
|
// ASSERT_TRUE(ret);
|
||||||
if (val < 128)
|
if (val < 128)
|
||||||
cout << "Shape: " << val << " x " << val << "\t\t";
|
cout << "Shape: " << val << " x " << val << "\t\t";
|
||||||
else
|
else
|
||||||
cout << "Shape: " << val << " x " << val << "\t";
|
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 val, n;
|
int valmax = 8192;
|
||||||
int valmax = 8192;
|
int cycle_index = 10;
|
||||||
int cycle_index = 10;
|
double begin, end, time, acltime;
|
||||||
double begin, end, time, acltime;
|
Common_Test test;
|
||||||
Common_Test test;
|
|
||||||
|
|
||||||
//vector<int> type{CV_32FC1};
|
// vector<int> type{CV_32FC1};
|
||||||
vector<int> type{CV_8UC1,CV_32FC1, CV_32SC1, CV_64FC1};
|
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]);
|
||||||
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));
|
||||||
n = cycle_index;
|
Mat mat_dest(val, val, type[i], Scalar(2, 4, 8));
|
||||||
Mat mat_src(val, val, type[i], Scalar(1, 2, 4));
|
Mat mat_dest1(val, val, type[i]);
|
||||||
Mat mat_dest(val, val, type[i], Scalar(2, 4, 8));
|
|
||||||
Mat mat_dest1(val, val, type[i]);
|
|
||||||
|
|
||||||
aclMat aclmat_src(val, val, type[i], mat_src.data, acl_context);
|
aclMat aclmat_src(val, val, type[i], mat_src.data, acl_context);
|
||||||
aclMat aclmat_dest(val, val, type[i], mat_dest.data, acl_context);
|
aclMat aclmat_dest(val, val, type[i], mat_dest.data, acl_context);
|
||||||
|
|
||||||
begin = static_cast<double>(getTickCount());
|
begin = static_cast<double>(getTickCount());
|
||||||
while (n--)
|
while (n--) mat_dest /= mat_src;
|
||||||
mat_dest /= mat_src;
|
end = static_cast<double>(getTickCount());
|
||||||
end = static_cast<double>(getTickCount());
|
time = (end - begin) / getTickFrequency() / cycle_index;
|
||||||
time = (end - begin) / getTickFrequency() / cycle_index;
|
|
||||||
|
|
||||||
n = (cycle_index - 1);
|
n = (cycle_index - 1);
|
||||||
aclmat_dest /= aclmat_src;
|
aclmat_dest /= aclmat_src;
|
||||||
wait_stream(acl_context);
|
wait_stream(acl_context);
|
||||||
begin = static_cast<double>(getTickCount());
|
begin = static_cast<double>(getTickCount());
|
||||||
while (n--)
|
while (n--) aclmat_dest /= aclmat_src;
|
||||||
aclmat_dest /= aclmat_src;
|
wait_stream(acl_context);
|
||||||
wait_stream(acl_context);
|
end = static_cast<double>(getTickCount());
|
||||||
end = static_cast<double>(getTickCount());
|
acltime = (end - begin) / getTickFrequency() / (cycle_index - 1);
|
||||||
acltime = (end - begin) / getTickFrequency() / (cycle_index - 1);
|
|
||||||
|
|
||||||
aclmat_dest.download(mat_dest1);
|
aclmat_dest.download(mat_dest1);
|
||||||
//bool ret = test.Test_Diff(mat_dest, mat_dest1);
|
// bool ret = test.Test_Diff(mat_dest, mat_dest1);
|
||||||
//ASSERT_TRUE(ret);
|
// ASSERT_TRUE(ret);
|
||||||
if (val < 128)
|
if (val < 128)
|
||||||
cout << "Shape: " << val << " x " << val << "\t\t";
|
cout << "Shape: " << val << " x " << val << "\t\t";
|
||||||
else
|
else
|
||||||
cout << "Shape: " << val << " x " << val << "\t";
|
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 val, n;
|
int valmax = 4096;
|
||||||
int valmax = 4096;
|
int cycle_index = 10;
|
||||||
int cycle_index = 10;
|
double begin, end, time, acltime;
|
||||||
double begin, end, time, acltime;
|
Common_Test test;
|
||||||
Common_Test test;
|
vector<int> type{CV_32FC1};
|
||||||
vector<int> type{CV_32FC1};
|
|
||||||
|
|
||||||
for (size_t i = 0; i < type.size(); ++i)
|
for (size_t i = 0; i < type.size(); ++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]);
|
||||||
n = cycle_index;
|
Mat mat_dest(val, val, type[i]);
|
||||||
Mat mat_src(val, val, type[i]);
|
Mat mat_dest1(val, val, type[i]);
|
||||||
Mat mat_dest(val, val, type[i]);
|
|
||||||
Mat mat_dest1(val, val, type[i]);
|
|
||||||
|
|
||||||
test.SetDataRange(mat_src, 1);
|
test.SetDataRange(mat_src, 1);
|
||||||
test.SetDataRange(mat_dest, 1);
|
test.SetDataRange(mat_dest, 1);
|
||||||
|
|
||||||
aclMat aclmat_src(val, val, type[i], mat_src.data, acl_context);
|
aclMat aclmat_src(val, val, type[i], mat_src.data, acl_context);
|
||||||
aclMat aclmat_dest(val, val, type[i], mat_dest.data, acl_context);
|
aclMat aclmat_dest(val, val, type[i], mat_dest.data, acl_context);
|
||||||
|
|
||||||
begin = static_cast<double>(getTickCount());
|
begin = static_cast<double>(getTickCount());
|
||||||
while (n--)
|
while (n--) mat_dest *= mat_src;
|
||||||
mat_dest *= mat_src;
|
end = static_cast<double>(getTickCount());
|
||||||
end = static_cast<double>(getTickCount());
|
time = (end - begin) / getTickFrequency() / cycle_index;
|
||||||
time = (end - begin) / getTickFrequency() / cycle_index;
|
|
||||||
|
|
||||||
n = (cycle_index - 1);
|
n = (cycle_index - 1);
|
||||||
aclmat_dest *= aclmat_src;
|
aclmat_dest *= aclmat_src;
|
||||||
wait_stream(acl_context);
|
wait_stream(acl_context);
|
||||||
begin = static_cast<double>(getTickCount());
|
begin = static_cast<double>(getTickCount());
|
||||||
while (n--)
|
while (n--) aclmat_dest *= aclmat_src;
|
||||||
aclmat_dest *= aclmat_src;
|
wait_stream(acl_context);
|
||||||
wait_stream(acl_context);
|
end = static_cast<double>(getTickCount());
|
||||||
end = static_cast<double>(getTickCount());
|
acltime = (end - begin) / getTickFrequency() / (cycle_index - 1);
|
||||||
acltime = (end - begin) / getTickFrequency() / (cycle_index - 1);
|
|
||||||
|
|
||||||
aclmat_dest.download(mat_dest1);
|
aclmat_dest.download(mat_dest1);
|
||||||
bool ret = test.Test_Diff(mat_dest, mat_dest1);
|
bool ret = test.Test_Diff(mat_dest, mat_dest1);
|
||||||
ASSERT_TRUE(ret);
|
ASSERT_TRUE(ret);
|
||||||
if (val < 128)
|
if (val < 128)
|
||||||
cout << "Shape: " << val << " x " << val << "\t\t";
|
cout << "Shape: " << val << " x " << val << "\t\t";
|
||||||
else
|
else
|
||||||
cout << "Shape: " << val << " x " << val << "\t";
|
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,306 +1,319 @@
|
|||||||
#include "test_common.hpp"
|
#include "test_common.hpp"
|
||||||
|
|
||||||
Common_Test::Common_Test() {
|
using namespace cv;
|
||||||
srand((unsigned)time(NULL));
|
using namespace cv::acl;
|
||||||
|
using namespace cvtest;
|
||||||
|
using namespace testing;
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
Common_Test::Common_Test() { srand((unsigned)time(NULL)); }
|
||||||
|
|
||||||
|
Common_Test::~Common_Test() {}
|
||||||
|
|
||||||
|
bool Common_Test::Test_Diff(const aclMat &aclmat, const Mat &mat,
|
||||||
|
ALIGNMENT config) {
|
||||||
|
bool is_correct;
|
||||||
|
|
||||||
|
if (config == ALIGNMENT::MEMORY_UNALIGNED) {
|
||||||
|
is_correct = (aclmat.rows == mat.rows);
|
||||||
|
is_correct &= (aclmat.cols == mat.cols);
|
||||||
|
is_correct &= (aclmat.channels() == mat.channels());
|
||||||
|
is_correct &= (aclmat.type() == mat.type());
|
||||||
|
is_correct &= (aclmat.step == mat.step);
|
||||||
|
is_correct &= (aclmat.elemSize() == mat.elemSize());
|
||||||
|
is_correct &= (aclmat.totalSize == mat.total() * mat.elemSize());
|
||||||
|
is_correct &=
|
||||||
|
((aclmat.dataend - aclmat.datastart) == (mat.dataend - mat.datastart));
|
||||||
|
|
||||||
|
Mat mat_dest(mat.rows, mat.cols, mat.type());
|
||||||
|
aclmat.download(mat_dest);
|
||||||
|
is_correct &= Test_Diff(mat, mat_dest);
|
||||||
|
} else {
|
||||||
|
is_correct = (aclmat.rows == mat.rows);
|
||||||
|
is_correct &= (aclmat.cols == mat.cols);
|
||||||
|
is_correct &= (aclmat.channels() == mat.channels());
|
||||||
|
is_correct &= (aclmat.type() == mat.type());
|
||||||
|
is_correct &= (aclmat.elemSize() == mat.elemSize());
|
||||||
|
|
||||||
|
Mat mat_dest(mat.rows, mat.cols, mat.type());
|
||||||
|
aclmat.download(mat_dest, MEMORY_ALIGN);
|
||||||
|
is_correct &= Test_Diff(mat, mat_dest);
|
||||||
|
}
|
||||||
|
|
||||||
|
return is_correct;
|
||||||
}
|
}
|
||||||
|
|
||||||
Common_Test::~Common_Test() {
|
bool Common_Test::Test_Diff(const aclMat &aclmat, const aclMat &aclmat_other) {
|
||||||
|
bool is_correct;
|
||||||
|
|
||||||
|
is_correct = (aclmat.flags == aclmat_other.flags);
|
||||||
|
is_correct &= (aclmat.rows == aclmat_other.rows);
|
||||||
|
is_correct &= (aclmat.cols == aclmat_other.cols);
|
||||||
|
is_correct &= (aclmat.type() == aclmat_other.type());
|
||||||
|
is_correct &= (aclmat.step == aclmat_other.step);
|
||||||
|
is_correct &= (aclmat.data == aclmat_other.data);
|
||||||
|
is_correct &= (aclmat.refcount == aclmat_other.refcount);
|
||||||
|
is_correct &= (aclmat.datastart == aclmat_other.datastart);
|
||||||
|
is_correct &= (aclmat.dataend == aclmat_other.dataend);
|
||||||
|
is_correct &= (aclmat.offset == aclmat_other.offset);
|
||||||
|
is_correct &= (aclmat.wholerows == aclmat_other.wholerows);
|
||||||
|
is_correct &= (aclmat.wholecols == aclmat_other.wholecols);
|
||||||
|
is_correct &= (aclmat.acl_context == aclmat_other.acl_context);
|
||||||
|
is_correct &= (aclmat.totalSize == aclmat_other.totalSize);
|
||||||
|
|
||||||
|
return is_correct;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Common_Test::Test_Diff(const aclMat& aclmat, const Mat& mat, ALIGNMENT config) {
|
bool Common_Test::Test_Diff(const Mat &mat, const Mat &mat_other) {
|
||||||
bool is_correct;
|
bool is_correct;
|
||||||
|
|
||||||
if (config == ALIGNMENT::MEMORY_UNALIGNED)
|
is_correct = (mat.rows == mat_other.rows);
|
||||||
{
|
is_correct &= (mat.cols == mat_other.cols);
|
||||||
is_correct = (aclmat.rows == mat.rows);
|
is_correct &= (mat.type() == mat_other.type());
|
||||||
is_correct &= (aclmat.cols == mat.cols);
|
is_correct &= (mat.channels() == mat.channels());
|
||||||
is_correct &= (aclmat.channels() == mat.channels());
|
is_correct &= (mat.step == mat_other.step);
|
||||||
is_correct &= (aclmat.type() == mat.type());
|
is_correct &= (mat.elemSize() == mat_other.elemSize());
|
||||||
is_correct &= (aclmat.step == mat.step);
|
is_correct &= (mat.total() == mat_other.total());
|
||||||
is_correct &= (aclmat.elemSize() == mat.elemSize());
|
|
||||||
is_correct &= (aclmat.totalSize == mat.total() * mat.elemSize());
|
|
||||||
is_correct &= ((aclmat.dataend - aclmat.datastart) == (mat.dataend - mat.datastart));
|
|
||||||
|
|
||||||
Mat mat_dest(mat.rows, mat.cols, mat.type());
|
switch (mat.depth()) {
|
||||||
aclmat.download(mat_dest);
|
|
||||||
is_correct &= Test_Diff(mat, mat_dest);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
is_correct = (aclmat.rows == mat.rows);
|
|
||||||
is_correct &= (aclmat.cols == mat.cols);
|
|
||||||
is_correct &= (aclmat.channels() == mat.channels());
|
|
||||||
is_correct &= (aclmat.type() == mat.type());
|
|
||||||
is_correct &= (aclmat.elemSize() == mat.elemSize());
|
|
||||||
|
|
||||||
Mat mat_dest(mat.rows, mat.cols, mat.type());
|
|
||||||
aclmat.download(mat_dest, MEMORY_ALIGN);
|
|
||||||
is_correct &= Test_Diff(mat, mat_dest);
|
|
||||||
}
|
|
||||||
|
|
||||||
return is_correct;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Common_Test::Test_Diff(const aclMat& aclmat, const aclMat& aclmat_other) {
|
|
||||||
bool is_correct;
|
|
||||||
|
|
||||||
is_correct = (aclmat.flags == aclmat_other.flags);
|
|
||||||
is_correct &= (aclmat.rows == aclmat_other.rows);
|
|
||||||
is_correct &= (aclmat.cols == aclmat_other.cols);
|
|
||||||
is_correct &= (aclmat.type() == aclmat_other.type());
|
|
||||||
is_correct &= (aclmat.step == aclmat_other.step);
|
|
||||||
is_correct &= (aclmat.data == aclmat_other.data);
|
|
||||||
is_correct &= (aclmat.refcount == aclmat_other.refcount);
|
|
||||||
is_correct &= (aclmat.datastart == aclmat_other.datastart);
|
|
||||||
is_correct &= (aclmat.dataend == aclmat_other.dataend);
|
|
||||||
is_correct &= (aclmat.offset == aclmat_other.offset);
|
|
||||||
is_correct &= (aclmat.wholerows == aclmat_other.wholerows);
|
|
||||||
is_correct &= (aclmat.wholecols == aclmat_other.wholecols);
|
|
||||||
is_correct &= (aclmat.acl_context == aclmat_other.acl_context);
|
|
||||||
is_correct &= (aclmat.totalSize == aclmat_other.totalSize);
|
|
||||||
|
|
||||||
return is_correct;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Common_Test::Test_Diff(const Mat &mat, const Mat &mat_other)
|
|
||||||
{
|
|
||||||
bool is_correct;
|
|
||||||
|
|
||||||
is_correct = (mat.rows == mat_other.rows);
|
|
||||||
is_correct &= (mat.cols == mat_other.cols);
|
|
||||||
is_correct &= (mat.type() == mat_other.type());
|
|
||||||
is_correct &= (mat.channels() == mat.channels());
|
|
||||||
is_correct &= (mat.step == mat_other.step);
|
|
||||||
is_correct &= (mat.elemSize() == mat_other.elemSize());
|
|
||||||
is_correct &= (mat.total() == mat_other.total());
|
|
||||||
|
|
||||||
switch (mat.depth())
|
|
||||||
{
|
|
||||||
case CV_8U:
|
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());
|
||||||
for (int j = 0; j < mat.channels(); ++j)
|
i += mat.channels()) {
|
||||||
is_correct &= ((mat.data)[i+j] == (mat_other.data)[i+j]);
|
for (int j = 0; j < mat.channels(); ++j)
|
||||||
}
|
is_correct &= ((mat.data)[i + j] == (mat_other.data)[i + j]);
|
||||||
return is_correct;
|
}
|
||||||
|
return is_correct;
|
||||||
case CV_16U:
|
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());
|
||||||
for (int j = 0; j < mat.channels(); ++j)
|
i += mat.channels()) {
|
||||||
is_correct &= (((unsigned short *)mat.data)[i+j] == ((unsigned short *)mat_other.data)[i+j]);
|
for (int j = 0; j < mat.channels(); ++j)
|
||||||
}
|
is_correct &= (((unsigned short *)mat.data)[i + j] ==
|
||||||
return is_correct;
|
((unsigned short *)mat_other.data)[i + j]);
|
||||||
|
}
|
||||||
|
return is_correct;
|
||||||
case CV_32S:
|
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());
|
||||||
for (int j = 0; j < mat.channels(); ++j)
|
i += mat.channels()) {
|
||||||
is_correct &= (((int *)(mat.data))[i+j] == (((int *)mat_other.data))[i+j]);
|
for (int j = 0; j < mat.channels(); ++j)
|
||||||
}
|
is_correct &=
|
||||||
return is_correct;
|
(((int *)(mat.data))[i + j] == (((int *)mat_other.data))[i + j]);
|
||||||
|
}
|
||||||
|
return is_correct;
|
||||||
case CV_32F:
|
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());
|
||||||
for (int j = 0; j < mat.channels(); ++j)
|
i += mat.channels()) {
|
||||||
is_correct &= ((((float *)(mat.data))[i+j] - (((float *)mat_other.data))[i+j] >= -0.00001) || \
|
for (int j = 0; j < mat.channels(); ++j)
|
||||||
(((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] >=
|
||||||
return is_correct;
|
-0.00001) ||
|
||||||
|
(((float *)(mat.data))[i + j] -
|
||||||
|
(((float *)mat_other.data))[i + j] <=
|
||||||
|
0.00001));
|
||||||
|
}
|
||||||
|
return is_correct;
|
||||||
case CV_64F:
|
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());
|
||||||
for (int j = 0; j < mat.channels(); ++j)
|
i += mat.channels()) {
|
||||||
is_correct &= ((((double *)(mat.data))[i+j] - (((double *)mat_other.data))[i+j] >= -0.00001) || \
|
for (int j = 0; j < mat.channels(); ++j)
|
||||||
(((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] >=
|
||||||
return is_correct;
|
-0.00001) ||
|
||||||
}
|
(((double *)(mat.data))[i + j] -
|
||||||
return is_correct;
|
(((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 << str.c_str() << endl;
|
cout << m;
|
||||||
cout << m;
|
cout << endl << endl << endl;
|
||||||
cout << endl
|
|
||||||
<< endl
|
|
||||||
<< endl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Common_Test::StatShow(cv::Mat &mat_src, aclMat &aclmat_dst)
|
void Common_Test::StatShow(cv::Mat &mat_src, aclMat &aclmat_dst) {
|
||||||
{
|
cout << "//////////////////////////////// MatStat "
|
||||||
cout << "//////////////////////////////// MatStat ////////////////////////////////" << endl;
|
"////////////////////////////////"
|
||||||
cout << "type: " << mat_src.type() << endl;
|
<< endl;
|
||||||
cout << "elemSize: " << mat_src.elemSize() << endl;
|
cout << "type: " << mat_src.type() << endl;
|
||||||
cout << "channels: " << mat_src.channels() << endl;
|
cout << "elemSize: " << mat_src.elemSize() << endl;
|
||||||
cout << "step: " << mat_src.step << endl;
|
cout << "channels: " << mat_src.channels() << endl;
|
||||||
cout << "totalSize: " << mat_src.rows * mat_src.cols * mat_src.elemSize() << endl;
|
cout << "step: " << mat_src.step << endl;
|
||||||
cout << "totalSize: " << mat_src.total() * mat_src.elemSize() << endl;
|
cout << "totalSize: " << mat_src.rows * mat_src.cols * mat_src.elemSize()
|
||||||
cout << "dataend - datastart: " << mat_src.dataend - mat_src.datastart << endl;
|
<< endl;
|
||||||
|
cout << "totalSize: " << mat_src.total() * mat_src.elemSize() << endl;
|
||||||
|
cout << "dataend - datastart: " << mat_src.dataend - mat_src.datastart
|
||||||
|
<< endl;
|
||||||
|
|
||||||
cout << "//////////////////////////////// aclMatStat ////////////////////////////////" << endl;
|
cout << "//////////////////////////////// aclMatStat "
|
||||||
cout << "type: " << aclmat_dst.type() << endl;
|
"////////////////////////////////"
|
||||||
cout << "elemSize: " << aclmat_dst.elemSize() << endl;
|
<< endl;
|
||||||
cout << "channels: " << aclmat_dst.channels() << endl;
|
cout << "type: " << aclmat_dst.type() << endl;
|
||||||
cout << "step: " << aclmat_dst.step << endl;
|
cout << "elemSize: " << aclmat_dst.elemSize() << endl;
|
||||||
cout << "totalSize: " << aclmat_dst.rows * aclmat_dst.step << endl;
|
cout << "channels: " << aclmat_dst.channels() << endl;
|
||||||
cout << "totalSize: " << aclmat_dst.totalSize << endl;
|
cout << "step: " << aclmat_dst.step << endl;
|
||||||
cout << "dataend - datastart: " << aclmat_dst.dataend - aclmat_dst.datastart << endl;
|
cout << "totalSize: " << aclmat_dst.rows * aclmat_dst.step << endl;
|
||||||
cout << "wholerows: " << aclmat_dst.wholerows << endl;
|
cout << "totalSize: " << aclmat_dst.totalSize << endl;
|
||||||
cout << "wholecols: " << aclmat_dst.wholecols << endl;
|
cout << "dataend - datastart: " << aclmat_dst.dataend - aclmat_dst.datastart
|
||||||
cout << "offset : " << aclmat_dst.offset << endl;
|
<< 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)
|
void Common_Test::PrintLog(const string &funcname, int type) {
|
||||||
{
|
switch (type) {
|
||||||
switch (type)
|
|
||||||
{
|
|
||||||
case CV_8UC1:
|
case CV_8UC1:
|
||||||
cout << funcname << "\t"
|
cout << funcname << "\t"
|
||||||
<< "Type: CV_8UC1" << endl;
|
<< "Type: CV_8UC1" << endl;
|
||||||
break;
|
break;
|
||||||
case CV_8UC2:
|
case CV_8UC2:
|
||||||
cout << funcname << "\t"
|
cout << funcname << "\t"
|
||||||
<< "Type: CV_8UC2" << endl;
|
<< "Type: CV_8UC2" << endl;
|
||||||
break;
|
break;
|
||||||
case CV_8UC3:
|
case CV_8UC3:
|
||||||
cout << funcname << "\t"
|
cout << funcname << "\t"
|
||||||
<< "Type: CV_8UC3" << endl;
|
<< "Type: CV_8UC3" << endl;
|
||||||
break;
|
break;
|
||||||
case CV_8UC4:
|
case CV_8UC4:
|
||||||
cout << funcname << "\t"
|
cout << funcname << "\t"
|
||||||
<< "Type: CV_8UC4" << endl;
|
<< "Type: CV_8UC4" << endl;
|
||||||
break;
|
break;
|
||||||
case CV_8SC1:
|
case CV_8SC1:
|
||||||
cout << funcname << "\t"
|
cout << funcname << "\t"
|
||||||
<< "Type: CV_8SC1" << endl;
|
<< "Type: CV_8SC1" << endl;
|
||||||
break;
|
break;
|
||||||
case CV_8SC2:
|
case CV_8SC2:
|
||||||
cout << funcname << "\t"
|
cout << funcname << "\t"
|
||||||
<< "Type: CV_8SC2" << endl;
|
<< "Type: CV_8SC2" << endl;
|
||||||
break;
|
break;
|
||||||
case CV_8SC3:
|
case CV_8SC3:
|
||||||
cout << funcname << "\t"
|
cout << funcname << "\t"
|
||||||
<< "Type: CV_8SC3" << endl;
|
<< "Type: CV_8SC3" << endl;
|
||||||
break;
|
break;
|
||||||
case CV_8SC4:
|
case CV_8SC4:
|
||||||
cout << funcname << "\t"
|
cout << funcname << "\t"
|
||||||
<< "Type: CV_8SC4" << endl;
|
<< "Type: CV_8SC4" << endl;
|
||||||
break;
|
break;
|
||||||
case CV_16FC1:
|
case CV_16FC1:
|
||||||
cout << funcname << "\t"
|
cout << funcname << "\t"
|
||||||
<< "Type: CV_16FC1" << endl;
|
<< "Type: CV_16FC1" << endl;
|
||||||
break;
|
break;
|
||||||
case CV_16FC2:
|
case CV_16FC2:
|
||||||
cout << funcname << "\t"
|
cout << funcname << "\t"
|
||||||
<< "Type: CV_16FC2" << endl;
|
<< "Type: CV_16FC2" << endl;
|
||||||
break;
|
break;
|
||||||
case CV_16FC3:
|
case CV_16FC3:
|
||||||
cout << funcname << "\t"
|
cout << funcname << "\t"
|
||||||
<< "Type: CV_16FC3" << endl;
|
<< "Type: CV_16FC3" << endl;
|
||||||
break;
|
break;
|
||||||
case CV_16FC4:
|
case CV_16FC4:
|
||||||
cout << funcname << "\t"
|
cout << funcname << "\t"
|
||||||
<< "Type: CV_16FC4" << endl;
|
<< "Type: CV_16FC4" << endl;
|
||||||
break;
|
break;
|
||||||
case CV_32FC1:
|
case CV_32FC1:
|
||||||
cout << funcname << "\t"
|
cout << funcname << "\t"
|
||||||
<< "Type: CV_32FC1" << endl;
|
<< "Type: CV_32FC1" << endl;
|
||||||
break;
|
break;
|
||||||
case CV_32FC2:
|
case CV_32FC2:
|
||||||
cout << funcname << "\t"
|
cout << funcname << "\t"
|
||||||
<< "Type: CV_32FC2" << endl;
|
<< "Type: CV_32FC2" << endl;
|
||||||
break;
|
break;
|
||||||
case CV_32FC3:
|
case CV_32FC3:
|
||||||
cout << funcname << "\t"
|
cout << funcname << "\t"
|
||||||
<< "Type: CV_32FC3" << endl;
|
<< "Type: CV_32FC3" << endl;
|
||||||
break;
|
break;
|
||||||
case CV_32FC4:
|
case CV_32FC4:
|
||||||
cout << funcname << "\t"
|
cout << funcname << "\t"
|
||||||
<< "Type: CV_32FC4" << endl;
|
<< "Type: CV_32FC4" << endl;
|
||||||
break;
|
break;
|
||||||
case CV_32SC1:
|
case CV_32SC1:
|
||||||
cout << funcname << "\t"
|
cout << funcname << "\t"
|
||||||
<< "Type: CV_32SC1" << endl;
|
<< "Type: CV_32SC1" << endl;
|
||||||
break;
|
break;
|
||||||
case CV_32SC2:
|
case CV_32SC2:
|
||||||
cout << funcname << "\t"
|
cout << funcname << "\t"
|
||||||
<< "Type: CV_32SC2" << endl;
|
<< "Type: CV_32SC2" << endl;
|
||||||
break;
|
break;
|
||||||
case CV_32SC3:
|
case CV_32SC3:
|
||||||
cout << funcname << "\t"
|
cout << funcname << "\t"
|
||||||
<< "Type: CV_32SC3" << endl;
|
<< "Type: CV_32SC3" << endl;
|
||||||
break;
|
break;
|
||||||
case CV_32SC4:
|
case CV_32SC4:
|
||||||
cout << funcname << "\t"
|
cout << funcname << "\t"
|
||||||
<< "Type: CV_32SC4" << endl;
|
<< "Type: CV_32SC4" << endl;
|
||||||
break;
|
break;
|
||||||
case CV_64FC1:
|
case CV_64FC1:
|
||||||
cout << funcname << "\t"
|
cout << funcname << "\t"
|
||||||
<< "Type: CV_64FC1" << endl;
|
<< "Type: CV_64FC1" << endl;
|
||||||
break;
|
break;
|
||||||
case CV_64FC2:
|
case CV_64FC2:
|
||||||
cout << funcname << "\t"
|
cout << funcname << "\t"
|
||||||
<< "Type: CV_64FC2" << endl;
|
<< "Type: CV_64FC2" << endl;
|
||||||
break;
|
break;
|
||||||
case CV_64FC3:
|
case CV_64FC3:
|
||||||
cout << funcname << "\t"
|
cout << funcname << "\t"
|
||||||
<< "Type: CV_64FC3" << endl;
|
<< "Type: CV_64FC3" << endl;
|
||||||
break;
|
break;
|
||||||
case CV_64FC4:
|
case CV_64FC4:
|
||||||
cout << funcname << "\t"
|
cout << funcname << "\t"
|
||||||
<< "Type: CV_64FC4" << endl;
|
<< "Type: CV_64FC4" << endl;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* srand((unsigned)time(NULL)) in constructor */
|
/* srand((unsigned)time(NULL)) in constructor */
|
||||||
size_t Common_Test::RandDom_(int config) {
|
size_t Common_Test::RandDom_(int config) {
|
||||||
return static_cast<size_t>(rand() % config);
|
return static_cast<size_t>(rand() % config);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Common_Test::SetDataRange(Mat &src, int dataRange)
|
bool Common_Test::SetDataRange(Mat &src, int dataRange) {
|
||||||
{
|
switch (src.depth()) {
|
||||||
switch (src.depth())
|
|
||||||
{
|
|
||||||
case CV_8U:
|
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)
|
for (int j = 0; j < src.channels(); ++j)
|
||||||
(src.data)[i+j] = RandDom_(dataRange) + 1;
|
(src.data)[i + j] = RandDom_(dataRange) + 1;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
case CV_16U:
|
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)
|
for (int j = 0; j < src.channels(); ++j)
|
||||||
((unsigned short *)src.data)[i+j] = RandDom_(dataRange) + 1;
|
((unsigned short *)src.data)[i + j] = RandDom_(dataRange) + 1;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
case CV_32S:
|
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)
|
for (int j = 0; j < src.channels(); ++j)
|
||||||
((int *)src.data)[i+j] = RandDom_(dataRange) + 1;
|
((int *)src.data)[i + j] = RandDom_(dataRange) + 1;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
case CV_32F:
|
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)
|
for (int j = 0; j < src.channels(); ++j)
|
||||||
((float *)src.data)[i+j] = RandDom_(dataRange) / 1.0 + 1;
|
((float *)src.data)[i + j] = RandDom_(dataRange) / 1.0 + 1;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
case CV_64F:
|
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)
|
for (int j = 0; j < src.channels(); ++j)
|
||||||
((double *)src.data)[i+j] = RandDom_(dataRange) / 1.0 + 1;
|
((double *)src.data)[i + j] = RandDom_(dataRange) / 1.0 + 1;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -3,25 +3,24 @@
|
|||||||
|
|
||||||
#include "test_precomp.hpp"
|
#include "test_precomp.hpp"
|
||||||
|
|
||||||
typedef enum TestDatatype {
|
typedef enum TestDatatype { INT = 1, FLOAT } TestDatatype;
|
||||||
INT = 1,
|
|
||||||
FLOAT
|
|
||||||
} TestDatatype;
|
|
||||||
|
|
||||||
class CV_EXPORTS Common_Test {
|
class CV_EXPORTS Common_Test {
|
||||||
public:
|
public:
|
||||||
Common_Test();
|
Common_Test();
|
||||||
~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(
|
||||||
CV_EXPORTS bool Test_Diff(const aclMat& aclmat, const aclMat& aclmat_other);
|
const cv::acl::aclMat& aclmat, const cv::Mat& mat,
|
||||||
CV_EXPORTS bool Test_Diff(const Mat& mat, const Mat& mat_other);
|
cv::acl::ALIGNMENT config = cv::acl::ALIGNMENT::MEMORY_UNALIGNED);
|
||||||
CV_EXPORTS void MatShow(Mat &m, string str);
|
CV_EXPORTS bool Test_Diff(const cv::acl::aclMat& aclmat,
|
||||||
CV_EXPORTS void StatShow(Mat &mat_src, aclMat &aclmat_dst);
|
const cv::acl::aclMat& aclmat_other);
|
||||||
CV_EXPORTS void PrintLog(const string& funcname, int type);
|
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 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
|
#endif
|
File diff suppressed because it is too large
Load Diff
@@ -2,39 +2,50 @@
|
|||||||
#define __OPENCV_CORRECTNESS_HPP__
|
#define __OPENCV_CORRECTNESS_HPP__
|
||||||
|
|
||||||
#include "test_precomp.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 {
|
class CV_EXPORTS AclMat_Test {
|
||||||
public:
|
public:
|
||||||
AclMat_Test();
|
AclMat_Test();
|
||||||
~AclMat_Test();
|
~AclMat_Test();
|
||||||
/* test set_device() */
|
/* test set_device() */
|
||||||
CV_EXPORTS void 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,
|
||||||
CV_EXPORTS void Test_constructor_UNALIGNED(aclCxt *acl_context);
|
* aclrtMemMallocPolicy policy = ACL_MEM_MALLOC_HUGE_FIRST) */
|
||||||
CV_EXPORTS void Test_constructor_ALIGN(aclCxt *acl_context);
|
CV_EXPORTS void Test_constructor_UNALIGNED(aclCxt *acl_context);
|
||||||
|
CV_EXPORTS void Test_constructor_ALIGN(aclCxt *acl_context);
|
||||||
|
|
||||||
/* test aclMat(const aclMat &m) */
|
/* test aclMat(const aclMat &m) */
|
||||||
CV_EXPORTS void Test_constructor(aclCxt *acl_context);
|
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,
|
||||||
CV_EXPORTS void Test_constructor_DATA(aclCxt *acl_context);
|
* size_t step = Mat::AUTO_STEP) */
|
||||||
/* test aclMat(const aclMat &m, const Range &rowRange, const Range &colRange = Range::all()) */
|
CV_EXPORTS void Test_constructor_DATA(aclCxt *acl_context);
|
||||||
CV_EXPORTS void Test_constructor_RANGE(aclCxt *acl_context);
|
/* test aclMat(const aclMat &m, const Range &rowRange, const Range &colRange =
|
||||||
/* test aclMat(const aclMat &m, const Rect &roi) */
|
* Range::all()) */
|
||||||
CV_EXPORTS void Test_constructor_ROI(aclCxt *acl_context);
|
CV_EXPORTS void Test_constructor_RANGE(aclCxt *acl_context);
|
||||||
/* test aclMat (const Mat &m, aclCxt* acl_context, aclrtMemMallocPolicy policy = ACL_MEM_MALLOC_HUGE_FIRST) */
|
/* test aclMat(const aclMat &m, const Rect &roi) */
|
||||||
CV_EXPORTS void Test_constructor_MAT(aclCxt *acl_context);
|
CV_EXPORTS void Test_constructor_ROI(aclCxt *acl_context);
|
||||||
/* test upload download*/
|
/* test aclMat (const Mat &m, aclCxt* acl_context, aclrtMemMallocPolicy policy
|
||||||
CV_EXPORTS void Test_DATA_TRANSFER(aclCxt *acl_context);
|
* = ACL_MEM_MALLOC_HUGE_FIRST) */
|
||||||
/* test upload_2d download_2d */
|
CV_EXPORTS void Test_constructor_MAT(aclCxt *acl_context);
|
||||||
CV_EXPORTS void Test_DATA_TRANSFERASYNC(aclCxt *acl_context);
|
/* test upload download*/
|
||||||
/* test locateROI adjustROI */
|
CV_EXPORTS void Test_DATA_TRANSFER(aclCxt *acl_context);
|
||||||
CV_EXPORTS void Test_locateROI(aclCxt *acl_context);
|
/* test upload_2d download_2d */
|
||||||
/* test swap */
|
CV_EXPORTS void Test_DATA_TRANSFERASYNC(aclCxt *acl_context);
|
||||||
CV_EXPORTS void Test_swap(aclCxt *acl_context);
|
/* test locateROI adjustROI */
|
||||||
|
CV_EXPORTS void Test_locateROI(aclCxt *acl_context);
|
||||||
|
/* test swap */
|
||||||
|
CV_EXPORTS void Test_swap(aclCxt *acl_context);
|
||||||
|
|
||||||
CV_EXPORTS void Test_operator_add(aclCxt *acl_context);
|
CV_EXPORTS void Test_operator_add(aclCxt *acl_context);
|
||||||
CV_EXPORTS void Test_operator_sub(aclCxt *acl_context);
|
CV_EXPORTS void Test_operator_sub(aclCxt *acl_context);
|
||||||
CV_EXPORTS void Test_operator_mul(aclCxt *acl_context);
|
CV_EXPORTS void Test_operator_mul(aclCxt *acl_context);
|
||||||
CV_EXPORTS void Test_operator_div(aclCxt *acl_context);
|
CV_EXPORTS void Test_operator_div(aclCxt *acl_context);
|
||||||
};
|
};
|
||||||
|
|
||||||
void thread_handler(void);
|
void thread_handler(void);
|
||||||
|
@@ -1,113 +1,111 @@
|
|||||||
#include "test_common.hpp"
|
#include "test_common.hpp"
|
||||||
#include "test_perf.hpp"
|
#include "test_perf.hpp"
|
||||||
|
|
||||||
void PERF_TEST::Test_MatMul(aclCxt *acl_context)
|
using namespace cv;
|
||||||
{
|
using namespace cv::acl;
|
||||||
int val, n;
|
using namespace cvtest;
|
||||||
int valmax = 4096;
|
using namespace testing;
|
||||||
int cycle_index = 10;//100;
|
using namespace std;
|
||||||
double begin, end, time, acltime;
|
|
||||||
Common_Test test;
|
|
||||||
vector<int> type{CV_32FC1};
|
|
||||||
|
|
||||||
for (size_t i = 0; i < type.size(); ++i)
|
void PERF_TEST::Test_MatMul(aclCxt *acl_context) {
|
||||||
{
|
int val, n;
|
||||||
for (val = 8; val <= valmax; val *= 2)
|
int valmax = 4096;
|
||||||
{
|
int cycle_index = 10; // 100;
|
||||||
Mat mat_src(val, val, type[i]);
|
double begin, end, time, acltime;
|
||||||
Mat mat_src1(val, val, type[i]);
|
Common_Test test;
|
||||||
Mat mat_dest(val, val, type[i]);
|
vector<int> type{CV_32FC1};
|
||||||
Mat mat_dest1(val, val, type[i]);
|
|
||||||
|
|
||||||
test.SetDataRange(mat_src, 32);
|
for (size_t i = 0; i < type.size(); ++i) {
|
||||||
test.SetDataRange(mat_src1, 32);
|
for (val = 8; val <= valmax; val *= 2) {
|
||||||
test.SetDataRange(mat_dest, 32);
|
Mat mat_src(val, val, type[i]);
|
||||||
|
Mat mat_src1(val, val, type[i]);
|
||||||
|
Mat mat_dest(val, val, type[i]);
|
||||||
|
Mat mat_dest1(val, val, type[i]);
|
||||||
|
|
||||||
aclMat aclmat_src(val, val, type[i], mat_src.data, acl_context);
|
test.SetDataRange(mat_src, 32);
|
||||||
aclMat aclmat_src1(val, val, type[i], mat_src1.data, acl_context);
|
test.SetDataRange(mat_src1, 32);
|
||||||
aclMat aclmat_dest(val, val, type[i], mat_dest.data, acl_context);
|
test.SetDataRange(mat_dest, 32);
|
||||||
|
|
||||||
n = cycle_index;
|
aclMat aclmat_src(val, val, type[i], mat_src.data, acl_context);
|
||||||
begin = static_cast<double>(getTickCount());
|
aclMat aclmat_src1(val, val, type[i], mat_src1.data, acl_context);
|
||||||
while (n--)
|
aclMat aclmat_dest(val, val, type[i], mat_dest.data, acl_context);
|
||||||
mat_dest = mat_src * mat_src1;
|
|
||||||
end = static_cast<double>(getTickCount());
|
|
||||||
time = (end - begin) / getTickFrequency() / cycle_index;
|
|
||||||
|
|
||||||
n = (cycle_index - 1);
|
n = cycle_index;
|
||||||
MatMul(aclmat_src1, aclmat_src, aclmat_dest, 0);
|
begin = static_cast<double>(getTickCount());
|
||||||
wait_stream(acl_context, 0);
|
while (n--) mat_dest = mat_src * mat_src1;
|
||||||
begin = static_cast<double>(getTickCount());
|
end = static_cast<double>(getTickCount());
|
||||||
while (n--)
|
time = (end - begin) / getTickFrequency() / cycle_index;
|
||||||
MatMul(aclmat_src1, aclmat_src, aclmat_dest, 1);
|
|
||||||
wait_stream(acl_context, 1);
|
|
||||||
end = static_cast<double>(getTickCount());
|
|
||||||
acltime = (end - begin) / getTickFrequency() / (cycle_index - 1);
|
|
||||||
|
|
||||||
aclmat_dest.download(mat_dest1);
|
n = (cycle_index - 1);
|
||||||
bool ret = test.Test_Diff(mat_dest, mat_dest1);
|
MatMul(aclmat_src1, aclmat_src, aclmat_dest, 0);
|
||||||
ASSERT_TRUE(ret);
|
wait_stream(acl_context, 0);
|
||||||
if (val < 128)
|
begin = static_cast<double>(getTickCount());
|
||||||
cout << "Shape: " << val << " x " << val << "\t\t";
|
while (n--) MatMul(aclmat_src1, aclmat_src, aclmat_dest, 1);
|
||||||
else
|
wait_stream(acl_context, 1);
|
||||||
cout << "Shape: " << val << " x " << val << "\t";
|
end = static_cast<double>(getTickCount());
|
||||||
cout << "CpuTimes: " << time << "\tAclTimes: " << acltime << "\tRate: " << time / acltime << endl;
|
acltime = (end - begin) / getTickFrequency() / (cycle_index - 1);
|
||||||
}
|
|
||||||
|
aclmat_dest.download(mat_dest1);
|
||||||
|
bool ret = test.Test_Diff(mat_dest, mat_dest1);
|
||||||
|
ASSERT_TRUE(ret);
|
||||||
|
if (val < 128)
|
||||||
|
cout << "Shape: " << val << " x " << val << "\t\t";
|
||||||
|
else
|
||||||
|
cout << "Shape: " << val << " x " << val << "\t";
|
||||||
|
cout << "CpuTimes: " << time << "\tAclTimes: " << acltime
|
||||||
|
<< "\tRate: " << time / acltime << endl;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PERF_TEST::Test_Convolution(aclCxt *acl_context)
|
void PERF_TEST::Test_Convolution(aclCxt *acl_context) {
|
||||||
{
|
int val, n;
|
||||||
int val, n;
|
int valmax = 4096;
|
||||||
int valmax = 4096;
|
int cycle_index = 10;
|
||||||
int cycle_index = 10;
|
double begin, end, time, acltime;
|
||||||
double begin, end, time, acltime;
|
Common_Test test;
|
||||||
Common_Test test;
|
vector<int> type{CV_32FC1};
|
||||||
vector<int> type{CV_32FC1};
|
|
||||||
|
|
||||||
for (size_t i = 0; i < type.size(); ++i)
|
for (size_t i = 0; i < type.size(); ++i) {
|
||||||
{
|
for (val = 8; val <= valmax; val *= 2) {
|
||||||
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_src(val, val, type[i], Scalar{1, 2});
|
Mat mat_dest(val, val, type[i], Scalar{6});
|
||||||
Mat mat_kernel(3, 3, type[i], Scalar(1, 4));
|
|
||||||
Mat mat_dest(val, val, type[i], Scalar{6});
|
|
||||||
|
|
||||||
aclMat aclmat_src(val, val, type[i], mat_src.data, acl_context);
|
aclMat aclmat_src(val, val, type[i], mat_src.data, acl_context);
|
||||||
aclMat aclmat_kernel(3, 3, type[i], mat_kernel.data, acl_context);
|
aclMat aclmat_kernel(3, 3, type[i], mat_kernel.data, acl_context);
|
||||||
aclMat aclmat_dest(val, val, type[i], mat_dest.data, acl_context);
|
aclMat aclmat_dest(val, val, type[i], mat_dest.data, acl_context);
|
||||||
|
|
||||||
n = cycle_index;
|
n = cycle_index;
|
||||||
begin = static_cast<double>(getTickCount());
|
begin = static_cast<double>(getTickCount());
|
||||||
while (n--)
|
while (n--) filter2D(mat_src, mat_dest, -1, mat_kernel);
|
||||||
filter2D(mat_src, mat_dest, -1, mat_kernel);
|
end = static_cast<double>(getTickCount());
|
||||||
end = static_cast<double>(getTickCount());
|
time = (end - begin) / getTickFrequency() / cycle_index;
|
||||||
time = (end - begin) / getTickFrequency() / cycle_index;
|
|
||||||
|
|
||||||
vector<int64_t> strides{1, 1, 1, 1};
|
vector<int64_t> strides{1, 1, 1, 1};
|
||||||
vector<int64_t> pads{1, 1, 1, 1};
|
vector<int64_t> pads{1, 1, 1, 1};
|
||||||
n = (cycle_index - 1);
|
n = (cycle_index - 1);
|
||||||
Convolution(aclmat_src, aclmat_kernel, aclmat_dest, strides, pads, 0);
|
Convolution(aclmat_src, aclmat_kernel, aclmat_dest, strides, pads, 0);
|
||||||
wait_stream(acl_context, 0);
|
wait_stream(acl_context, 0);
|
||||||
begin = static_cast<double>(getTickCount());
|
begin = static_cast<double>(getTickCount());
|
||||||
while (n--)
|
while (n--)
|
||||||
Convolution(aclmat_src, aclmat_kernel, aclmat_dest, strides, pads, 1);
|
Convolution(aclmat_src, aclmat_kernel, aclmat_dest, strides, pads, 1);
|
||||||
wait_stream(acl_context, 1);
|
wait_stream(acl_context, 1);
|
||||||
end = static_cast<double>(getTickCount());
|
end = static_cast<double>(getTickCount());
|
||||||
Mat mat_dest1(aclmat_dest.rows, aclmat_dest.cols, type[i]);
|
Mat mat_dest1(aclmat_dest.rows, aclmat_dest.cols, type[i]);
|
||||||
acltime = (end - begin) / getTickFrequency() / (cycle_index - 1);
|
acltime = (end - begin) / getTickFrequency() / (cycle_index - 1);
|
||||||
|
|
||||||
aclmat_dest.download(mat_dest1);
|
aclmat_dest.download(mat_dest1);
|
||||||
/*
|
/*
|
||||||
bool ret = test.Test_Diff(mat_dest, mat_dest1);
|
bool ret = test.Test_Diff(mat_dest, mat_dest1);
|
||||||
ASSERT_TRUE(ret);
|
ASSERT_TRUE(ret);
|
||||||
*/
|
*/
|
||||||
if (val < 128)
|
if (val < 128)
|
||||||
cout << "Shape: " << val << " x " << val << "\t\t";
|
cout << "Shape: " << val << " x " << val << "\t\t";
|
||||||
else
|
else
|
||||||
cout << "Shape: " << val << " x " << val << "\t";
|
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,10 +1,10 @@
|
|||||||
// This file is part of OpenCV project.
|
// This file is part of OpenCV project.
|
||||||
// It is subject to the license terms in the LICENSE file found in the top-level directory
|
// It is subject to the license terms in the LICENSE file found in the top-level
|
||||||
// of this distribution and at http://opencv.org/license.html.
|
// directory of this distribution and at http://opencv.org/license.html.
|
||||||
#include "test_precomp.hpp"
|
#include "test_precomp.hpp"
|
||||||
|
|
||||||
#if defined(HAVE_HPX)
|
#if defined(HAVE_HPX)
|
||||||
#include <hpx/hpx_main.hpp>
|
#include <hpx/hpx_main.hpp>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
CV_TEST_MAIN("cv")
|
CV_TEST_MAIN("cv")
|
||||||
|
@@ -1,481 +1,446 @@
|
|||||||
#include "test_common.hpp"
|
#include "test_common.hpp"
|
||||||
#include "test_perf.hpp"
|
#include "test_perf.hpp"
|
||||||
|
|
||||||
void PERF_TEST::Test_Abs(aclCxt *acl_context)
|
using namespace cv;
|
||||||
{
|
using namespace cv::acl;
|
||||||
int val, n;
|
using namespace cvtest;
|
||||||
int valmax = 8192;
|
using namespace testing;
|
||||||
int cycle_index = 10;
|
using namespace std;
|
||||||
double begin, end, time, acltime;
|
|
||||||
Common_Test test;
|
|
||||||
|
|
||||||
//vector<int> type{CV_32FC1};
|
void PERF_TEST::Test_Abs(aclCxt *acl_context) {
|
||||||
vector<int> type{CV_32FC1,CV_32SC1};
|
int val, n;
|
||||||
for (size_t i = 0; i < type.size(); ++i)
|
int valmax = 8192;
|
||||||
{
|
int cycle_index = 10;
|
||||||
test.PrintLog("Perf test : Function: Abs()", type[i]);
|
double begin, end, time, acltime;
|
||||||
for (val = 8; val <= valmax; val *= 2)
|
Common_Test test;
|
||||||
{
|
|
||||||
n = cycle_index;
|
|
||||||
Mat mat_src(val, val, type[i], Scalar{-2});
|
|
||||||
Mat mat_dest(val, val, type[i], Scalar{-4});
|
|
||||||
Mat mat_dest1(val, val, type[i], Scalar{-6});
|
|
||||||
|
|
||||||
aclMat aclmat_src(val, val, type[i], mat_src.data, acl_context);
|
// vector<int> type{CV_32FC1};
|
||||||
aclMat aclmat_dest(val, val, type[i], mat_dest.data, acl_context);
|
vector<int> type{CV_32FC1, CV_32SC1};
|
||||||
|
for (size_t i = 0; i < type.size(); ++i) {
|
||||||
|
test.PrintLog("Perf test : Function: Abs()", type[i]);
|
||||||
|
for (val = 8; val <= valmax; val *= 2) {
|
||||||
|
n = cycle_index;
|
||||||
|
Mat mat_src(val, val, type[i], Scalar{-2});
|
||||||
|
Mat mat_dest(val, val, type[i], Scalar{-4});
|
||||||
|
Mat mat_dest1(val, val, type[i], Scalar{-6});
|
||||||
|
|
||||||
begin = static_cast<double>(getTickCount());
|
aclMat aclmat_src(val, val, type[i], mat_src.data, acl_context);
|
||||||
while (n--)
|
aclMat aclmat_dest(val, val, type[i], mat_dest.data, acl_context);
|
||||||
mat_dest = abs(mat_src);
|
|
||||||
end = static_cast<double>(getTickCount());
|
|
||||||
time = (end - begin) / getTickFrequency() / cycle_index;
|
|
||||||
|
|
||||||
n = (cycle_index - 1);
|
begin = static_cast<double>(getTickCount());
|
||||||
aclmat_dest = abs(aclmat_src, 0);
|
while (n--) mat_dest = abs(mat_src);
|
||||||
wait_stream(acl_context, 0);
|
end = static_cast<double>(getTickCount());
|
||||||
begin = static_cast<double>(getTickCount());
|
time = (end - begin) / getTickFrequency() / cycle_index;
|
||||||
while (n--)
|
|
||||||
aclmat_dest = abs(aclmat_src, 1);
|
|
||||||
wait_stream(acl_context, 1);
|
|
||||||
end = static_cast<double>(getTickCount());
|
|
||||||
acltime = (end - begin) / getTickFrequency() / (cycle_index - 1);
|
|
||||||
|
|
||||||
aclmat_dest.download(mat_dest1);
|
n = (cycle_index - 1);
|
||||||
bool ret = test.Test_Diff(mat_dest, mat_dest1);
|
aclmat_dest = abs(aclmat_src, 0);
|
||||||
ASSERT_TRUE(ret);
|
wait_stream(acl_context, 0);
|
||||||
if (val < 128)
|
begin = static_cast<double>(getTickCount());
|
||||||
cout << "Shape: " << val << " x " << val << "\t\t";
|
while (n--) aclmat_dest = abs(aclmat_src, 1);
|
||||||
else
|
wait_stream(acl_context, 1);
|
||||||
cout << "Shape: " << val << " x " << val << "\t";
|
end = static_cast<double>(getTickCount());
|
||||||
cout << "CpuTimes: " << time << "\tAclTimes: " << acltime << "\tRate: " << time / acltime << endl;
|
acltime = (end - begin) / getTickFrequency() / (cycle_index - 1);
|
||||||
}
|
|
||||||
|
aclmat_dest.download(mat_dest1);
|
||||||
|
bool ret = test.Test_Diff(mat_dest, mat_dest1);
|
||||||
|
ASSERT_TRUE(ret);
|
||||||
|
if (val < 128)
|
||||||
|
cout << "Shape: " << val << " x " << val << "\t\t";
|
||||||
|
else
|
||||||
|
cout << "Shape: " << val << " x " << val << "\t";
|
||||||
|
cout << "CpuTimes: " << time << "\tAclTimes: " << acltime
|
||||||
|
<< "\tRate: " << time / acltime << endl;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PERF_TEST::Test_Pow(aclCxt *acl_context)
|
void PERF_TEST::Test_Pow(aclCxt *acl_context) {
|
||||||
{
|
int val, n;
|
||||||
int val, n;
|
int valmax = 8192;
|
||||||
int valmax = 8192;
|
int cycle_index = 10;
|
||||||
int cycle_index = 10;
|
double begin, end, time, acltime;
|
||||||
double begin, end, time, acltime;
|
Common_Test test;
|
||||||
Common_Test test;
|
|
||||||
|
|
||||||
//vector<int> type{CV_32FC1};
|
// vector<int> type{CV_32FC1};
|
||||||
vector<int> type{CV_8UC1, CV_32FC1,CV_32SC1};
|
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]);
|
||||||
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);
|
||||||
n = cycle_index;
|
Mat mat_src(val, val, type[i]);
|
||||||
int power = test.RandDom_(6);
|
Mat mat_dest(val, val, type[i]);
|
||||||
Mat mat_src(val, val, type[i]);
|
Mat mat_dest1(val, val, type[i]);
|
||||||
Mat mat_dest(val, val, type[i]);
|
|
||||||
Mat mat_dest1(val, val, type[i]);
|
|
||||||
|
|
||||||
test.SetDataRange(mat_src, 32);
|
test.SetDataRange(mat_src, 32);
|
||||||
|
|
||||||
aclMat aclmat_src(val, val, type[i], mat_src.data, acl_context);
|
aclMat aclmat_src(val, val, type[i], mat_src.data, acl_context);
|
||||||
aclMat aclmat_dest(val, val, type[i], mat_dest.data, acl_context);
|
aclMat aclmat_dest(val, val, type[i], mat_dest.data, acl_context);
|
||||||
|
|
||||||
begin = static_cast<double>(getTickCount());
|
begin = static_cast<double>(getTickCount());
|
||||||
while (n--)
|
while (n--) pow(mat_src, power, mat_dest);
|
||||||
pow(mat_src, power, mat_dest);
|
end = static_cast<double>(getTickCount());
|
||||||
end = static_cast<double>(getTickCount());
|
time = (end - begin) / getTickFrequency() / cycle_index;
|
||||||
time = (end - begin) / getTickFrequency() / cycle_index;
|
|
||||||
|
|
||||||
n = (cycle_index - 1);
|
n = (cycle_index - 1);
|
||||||
pow(aclmat_src, power, aclmat_dest, 0);
|
pow(aclmat_src, power, aclmat_dest, 0);
|
||||||
wait_stream(acl_context, 0);
|
wait_stream(acl_context, 0);
|
||||||
begin = static_cast<double>(getTickCount());
|
begin = static_cast<double>(getTickCount());
|
||||||
while (n--)
|
while (n--) pow(aclmat_src, power, aclmat_dest, 1);
|
||||||
pow(aclmat_src, power, aclmat_dest, 1);
|
wait_stream(acl_context, 1);
|
||||||
wait_stream(acl_context, 1);
|
end = static_cast<double>(getTickCount());
|
||||||
end = static_cast<double>(getTickCount());
|
acltime = (end - begin) / getTickFrequency() / (cycle_index - 1);
|
||||||
acltime = (end - begin) / getTickFrequency() / (cycle_index - 1);
|
|
||||||
|
|
||||||
aclmat_dest.download(mat_dest1);
|
aclmat_dest.download(mat_dest1);
|
||||||
if (val < 128)
|
if (val < 128)
|
||||||
cout << "Shape: " << val << " x " << val << "\t\t";
|
cout << "Shape: " << val << " x " << val << "\t\t";
|
||||||
else
|
else
|
||||||
cout << "Shape: " << val << " x " << val << "\t";
|
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 val, n;
|
int valmax = 8192;
|
||||||
int valmax = 8192;
|
int cycle_index = 10;
|
||||||
int cycle_index = 10;
|
double begin, end, time, acltime;
|
||||||
double begin, end, time, acltime;
|
Common_Test test;
|
||||||
Common_Test test;
|
// vector<int> type{CV_32FC1};
|
||||||
//vector<int> type{CV_32FC1};
|
vector<int> type{CV_32FC1, CV_64FC1};
|
||||||
vector<int> type{CV_32FC1,CV_64FC1};
|
for (size_t i = 0; i < type.size(); ++i) {
|
||||||
for (size_t i = 0; i < type.size(); ++i)
|
for (val = 8; val <= valmax; val *= 2) {
|
||||||
{
|
n = cycle_index;
|
||||||
for (val = 8; val <= valmax; val *= 2)
|
Mat mat_src(val, val, type[i]);
|
||||||
{
|
Mat mat_dest(val, val, type[i]);
|
||||||
n = cycle_index;
|
Mat mat_dest1(val, val, type[i]);
|
||||||
Mat mat_src(val, val, type[i]);
|
|
||||||
Mat mat_dest(val, val, type[i]);
|
|
||||||
Mat mat_dest1(val, val, type[i]);
|
|
||||||
|
|
||||||
test.SetDataRange(mat_src, 32);
|
test.SetDataRange(mat_src, 32);
|
||||||
test.SetDataRange(mat_dest, 32);
|
test.SetDataRange(mat_dest, 32);
|
||||||
|
|
||||||
aclMat aclmat_src(val, val, type[i], mat_src.data, acl_context);
|
aclMat aclmat_src(val, val, type[i], mat_src.data, acl_context);
|
||||||
aclMat aclmat_dest(val, val, type[i], mat_dest.data, acl_context);
|
aclMat aclmat_dest(val, val, type[i], mat_dest.data, acl_context);
|
||||||
|
|
||||||
begin = static_cast<double>(getTickCount());
|
begin = static_cast<double>(getTickCount());
|
||||||
while (n--)
|
while (n--) sqrt(mat_src, mat_dest);
|
||||||
sqrt(mat_src, mat_dest);
|
end = static_cast<double>(getTickCount());
|
||||||
end = static_cast<double>(getTickCount());
|
time = (end - begin) / getTickFrequency() / cycle_index;
|
||||||
time = (end - begin) / getTickFrequency() / cycle_index;
|
|
||||||
|
|
||||||
n = (cycle_index - 1);
|
n = (cycle_index - 1);
|
||||||
sqrt(aclmat_src, aclmat_dest);
|
sqrt(aclmat_src, aclmat_dest);
|
||||||
wait_stream(acl_context);
|
wait_stream(acl_context);
|
||||||
begin = static_cast<double>(getTickCount());
|
begin = static_cast<double>(getTickCount());
|
||||||
while (n--)
|
while (n--) sqrt(aclmat_src, aclmat_dest, 1);
|
||||||
sqrt(aclmat_src, aclmat_dest, 1);
|
wait_stream(acl_context, 1);
|
||||||
wait_stream(acl_context, 1);
|
end = static_cast<double>(getTickCount());
|
||||||
end = static_cast<double>(getTickCount());
|
acltime = (end - begin) / getTickFrequency() / (cycle_index - 1);
|
||||||
acltime = (end - begin) / getTickFrequency() / (cycle_index - 1);
|
|
||||||
|
|
||||||
aclmat_dest.download(mat_dest1);
|
aclmat_dest.download(mat_dest1);
|
||||||
if (val < 128)
|
if (val < 128)
|
||||||
cout << "Shape: " << val << " x " << val << "\t\t";
|
cout << "Shape: " << val << " x " << val << "\t\t";
|
||||||
else
|
else
|
||||||
cout << "Shape: " << val << " x " << val << "\t";
|
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 val, n;
|
int valmax = 8192;
|
||||||
int valmax = 8192;
|
int cycle_index = 10;
|
||||||
int cycle_index = 10;
|
double begin, end, time, acltime;
|
||||||
double begin, end, time, acltime;
|
Common_Test test;
|
||||||
Common_Test test;
|
// vector<int> type{CV_32FC1};
|
||||||
//vector<int> type{CV_32FC1};
|
vector<int> type{CV_8UC1, CV_32FC1, CV_32SC1, CV_64FC1};
|
||||||
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)
|
for (val = 8; val <= valmax; val *= 2) {
|
||||||
{
|
n = cycle_index;
|
||||||
for (val = 8; val <= valmax; val *= 2)
|
Mat mat_src1(val, val, type[i]);
|
||||||
{
|
Mat mat_src2(val, val, type[i]);
|
||||||
n = cycle_index;
|
Mat mat_dest(val, val, type[i]);
|
||||||
Mat mat_src1(val, val, type[i]);
|
Mat mat_dest1(val, val, type[i]);
|
||||||
Mat mat_src2(val, val, type[i]);
|
|
||||||
Mat mat_dest(val, val, type[i]);
|
|
||||||
Mat mat_dest1(val, val, type[i]);
|
|
||||||
|
|
||||||
test.SetDataRange(mat_src1, 32);
|
test.SetDataRange(mat_src1, 32);
|
||||||
test.SetDataRange(mat_src2, 32);
|
test.SetDataRange(mat_src2, 32);
|
||||||
test.SetDataRange(mat_dest, 32);
|
test.SetDataRange(mat_dest, 32);
|
||||||
|
|
||||||
aclMat aclmat_src1(val, val, type[i], mat_src1.data, acl_context);
|
aclMat aclmat_src1(val, val, type[i], mat_src1.data, acl_context);
|
||||||
aclMat aclmat_src2(val, val, type[i], mat_src2.data, acl_context);
|
aclMat aclmat_src2(val, val, type[i], mat_src2.data, acl_context);
|
||||||
aclMat aclmat_dest(val, val, type[i], mat_dest.data, acl_context);
|
aclMat aclmat_dest(val, val, type[i], mat_dest.data, acl_context);
|
||||||
|
|
||||||
begin = static_cast<double>(getTickCount());
|
begin = static_cast<double>(getTickCount());
|
||||||
while (n--)
|
while (n--) add(mat_src1, mat_src2, mat_dest);
|
||||||
add(mat_src1, mat_src2, mat_dest);
|
end = static_cast<double>(getTickCount());
|
||||||
end = static_cast<double>(getTickCount());
|
time = (end - begin) / getTickFrequency() / cycle_index;
|
||||||
time = (end - begin) / getTickFrequency() / cycle_index;
|
|
||||||
|
|
||||||
n = (cycle_index - 1);
|
n = (cycle_index - 1);
|
||||||
add(aclmat_src1, aclmat_src2, aclmat_dest);
|
add(aclmat_src1, aclmat_src2, aclmat_dest);
|
||||||
wait_stream(acl_context);
|
wait_stream(acl_context);
|
||||||
begin = static_cast<double>(getTickCount());
|
begin = static_cast<double>(getTickCount());
|
||||||
while (n--)
|
while (n--) add(aclmat_src1, aclmat_src2, aclmat_dest, 1);
|
||||||
add(aclmat_src1, aclmat_src2, aclmat_dest, 1);
|
wait_stream(acl_context, 1);
|
||||||
wait_stream(acl_context, 1);
|
end = static_cast<double>(getTickCount());
|
||||||
end = static_cast<double>(getTickCount());
|
acltime = (end - begin) / getTickFrequency() / (cycle_index - 1);
|
||||||
acltime = (end - begin) / getTickFrequency() / (cycle_index - 1);
|
|
||||||
|
|
||||||
aclmat_dest.download(mat_dest1);
|
aclmat_dest.download(mat_dest1);
|
||||||
bool ret = test.Test_Diff(mat_dest, mat_dest1);
|
bool ret = test.Test_Diff(mat_dest, mat_dest1);
|
||||||
ASSERT_TRUE(ret);
|
ASSERT_TRUE(ret);
|
||||||
if (val < 128)
|
if (val < 128)
|
||||||
cout << "Shape: " << val << " x " << val << "\t\t";
|
cout << "Shape: " << val << " x " << val << "\t\t";
|
||||||
else
|
else
|
||||||
cout << "Shape: " << val << " x " << val << "\t";
|
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 val, n;
|
int valmax = 8192;
|
||||||
int valmax = 8192;
|
int cycle_index = 10;
|
||||||
int cycle_index = 10;
|
double begin, end, time, acltime;
|
||||||
double begin, end, time, acltime;
|
Common_Test test;
|
||||||
Common_Test test;
|
// vector<int> type{CV_32FC1};
|
||||||
//vector<int> type{CV_32FC1};
|
vector<int> type{CV_8UC1, CV_32FC1, CV_32SC1};
|
||||||
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)
|
for (val = 8; val <= valmax; val *= 2) {
|
||||||
{
|
n = cycle_index;
|
||||||
for (val = 8; val <= valmax; val *= 2)
|
Mat mat_src1(val, val, type[i]);
|
||||||
{
|
Mat mat_src2(val, val, type[i]);
|
||||||
n = cycle_index;
|
Mat mat_dest(val, val, type[i]);
|
||||||
Mat mat_src1(val, val, type[i]);
|
Mat mat_dest1(val, val, type[i]);
|
||||||
Mat mat_src2(val, val, type[i]);
|
|
||||||
Mat mat_dest(val, val, type[i]);
|
|
||||||
Mat mat_dest1(val, val, type[i]);
|
|
||||||
|
|
||||||
test.SetDataRange(mat_src1, 32);
|
test.SetDataRange(mat_src1, 32);
|
||||||
test.SetDataRange(mat_src2, 4);
|
test.SetDataRange(mat_src2, 4);
|
||||||
test.SetDataRange(mat_dest, 32);
|
test.SetDataRange(mat_dest, 32);
|
||||||
|
|
||||||
aclMat aclmat_src1(val, val, type[i], mat_src1.data, acl_context);
|
aclMat aclmat_src1(val, val, type[i], mat_src1.data, acl_context);
|
||||||
aclMat aclmat_src2(val, val, type[i], mat_src2.data, acl_context);
|
aclMat aclmat_src2(val, val, type[i], mat_src2.data, acl_context);
|
||||||
aclMat aclmat_dest(val, val, type[i], mat_dest.data, acl_context);
|
aclMat aclmat_dest(val, val, type[i], mat_dest.data, acl_context);
|
||||||
|
|
||||||
begin = static_cast<double>(getTickCount());
|
begin = static_cast<double>(getTickCount());
|
||||||
while (n--)
|
while (n--) divide(mat_src1, mat_src2, mat_dest);
|
||||||
divide(mat_src1, mat_src2, mat_dest);
|
end = static_cast<double>(getTickCount());
|
||||||
end = static_cast<double>(getTickCount());
|
time = (end - begin) / getTickFrequency() / cycle_index;
|
||||||
time = (end - begin) / getTickFrequency() / cycle_index;
|
|
||||||
|
|
||||||
n = (cycle_index - 1);
|
n = (cycle_index - 1);
|
||||||
divide(aclmat_src1, aclmat_src2, aclmat_dest);
|
divide(aclmat_src1, aclmat_src2, aclmat_dest);
|
||||||
wait_stream(acl_context);
|
wait_stream(acl_context);
|
||||||
begin = static_cast<double>(getTickCount());
|
begin = static_cast<double>(getTickCount());
|
||||||
while (n--)
|
while (n--) divide(aclmat_src1, aclmat_src2, aclmat_dest, 1);
|
||||||
divide(aclmat_src1, aclmat_src2, aclmat_dest, 1);
|
wait_stream(acl_context, 1);
|
||||||
wait_stream(acl_context, 1);
|
end = static_cast<double>(getTickCount());
|
||||||
end = static_cast<double>(getTickCount());
|
acltime = (end - begin) / getTickFrequency() / (cycle_index - 1);
|
||||||
acltime = (end - begin) / getTickFrequency() / (cycle_index - 1);
|
|
||||||
|
|
||||||
aclmat_dest.download(mat_dest1);
|
aclmat_dest.download(mat_dest1);
|
||||||
// bool ret = test.Test_Diff(mat_dest, mat_dest1);
|
// bool ret = test.Test_Diff(mat_dest, mat_dest1);
|
||||||
// ASSERT_TRUE(ret);
|
// ASSERT_TRUE(ret);
|
||||||
if (val < 128)
|
if (val < 128)
|
||||||
cout << "Shape: " << val << " x " << val << "\t\t";
|
cout << "Shape: " << val << " x " << val << "\t\t";
|
||||||
else
|
else
|
||||||
cout << "Shape: " << val << " x " << val << "\t";
|
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 val, n;
|
int valmax = 8192;
|
||||||
int valmax = 8192;
|
int cycle_index = 10;
|
||||||
int cycle_index = 10;
|
double begin, end, time, acltime;
|
||||||
double begin, end, time, acltime;
|
Common_Test test;
|
||||||
Common_Test test;
|
|
||||||
|
|
||||||
//vector<int> type{CV_32FC1};
|
// vector<int> type{CV_32FC1};
|
||||||
vector<int> type{CV_32FC1,CV_64FC1};
|
vector<int> type{CV_32FC1, CV_64FC1};
|
||||||
for (size_t i = 0; i < type.size(); ++i)
|
for (size_t i = 0; i < type.size(); ++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]);
|
||||||
n = cycle_index;
|
Mat mat_dest(val, val, type[i]);
|
||||||
Mat mat_src(val, val, type[i]);
|
Mat mat_dest1(val, val, type[i]);
|
||||||
Mat mat_dest(val, val, type[i]);
|
|
||||||
Mat mat_dest1(val, val, type[i]);
|
|
||||||
|
|
||||||
test.SetDataRange(mat_src, 32);
|
test.SetDataRange(mat_src, 32);
|
||||||
test.SetDataRange(mat_dest, 2);
|
test.SetDataRange(mat_dest, 2);
|
||||||
|
|
||||||
aclMat aclmat_src(val, val, type[i], mat_src.data, acl_context);
|
aclMat aclmat_src(val, val, type[i], mat_src.data, acl_context);
|
||||||
aclMat aclmat_dest(val, val, type[i], mat_dest.data, acl_context);
|
aclMat aclmat_dest(val, val, type[i], mat_dest.data, acl_context);
|
||||||
|
|
||||||
begin = static_cast<double>(getTickCount());
|
begin = static_cast<double>(getTickCount());
|
||||||
while (n--)
|
while (n--) exp(mat_src, mat_dest);
|
||||||
exp(mat_src, mat_dest);
|
end = static_cast<double>(getTickCount());
|
||||||
end = static_cast<double>(getTickCount());
|
time = (end - begin) / getTickFrequency() / cycle_index;
|
||||||
time = (end - begin) / getTickFrequency() / cycle_index;
|
|
||||||
|
|
||||||
n = (cycle_index - 1);
|
n = (cycle_index - 1);
|
||||||
exp(aclmat_src, aclmat_dest);
|
exp(aclmat_src, aclmat_dest);
|
||||||
wait_stream(acl_context);
|
wait_stream(acl_context);
|
||||||
begin = static_cast<double>(getTickCount());
|
begin = static_cast<double>(getTickCount());
|
||||||
while (n--)
|
while (n--) exp(aclmat_src, aclmat_dest, 1);
|
||||||
exp(aclmat_src, aclmat_dest, 1);
|
wait_stream(acl_context, 1);
|
||||||
wait_stream(acl_context, 1);
|
end = static_cast<double>(getTickCount());
|
||||||
end = static_cast<double>(getTickCount());
|
acltime = (end - begin) / getTickFrequency() / (cycle_index - 1);
|
||||||
acltime = (end - begin) / getTickFrequency() / (cycle_index - 1);
|
|
||||||
|
|
||||||
aclmat_dest.download(mat_dest1);
|
aclmat_dest.download(mat_dest1);
|
||||||
if (val < 128)
|
if (val < 128)
|
||||||
cout << "Shape: " << val << " x " << val << "\t\t";
|
cout << "Shape: " << val << " x " << val << "\t\t";
|
||||||
else
|
else
|
||||||
cout << "Shape: " << val << " x " << val << "\t";
|
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 val, n;
|
int valmax = 8192;
|
||||||
int valmax = 8192;
|
int cycle_index = 10;
|
||||||
int cycle_index = 10;
|
double begin, end, time, acltime;
|
||||||
double begin, end, time, acltime;
|
Common_Test test;
|
||||||
Common_Test test;
|
// vector<int> type{CV_32FC1};
|
||||||
//vector<int> type{CV_32FC1};
|
vector<int> type{CV_32FC1, CV_64FC1};
|
||||||
vector<int> type{CV_32FC1,CV_64FC1};
|
for (size_t i = 0; i < type.size(); ++i) {
|
||||||
for (size_t i = 0; i < type.size(); ++i)
|
for (val = 8; val <= valmax; val *= 2) {
|
||||||
{
|
n = cycle_index;
|
||||||
for (val = 8; val <= valmax; val *= 2)
|
Mat mat_src(val, val, type[i]);
|
||||||
{
|
Mat mat_dest(val, val, type[i]);
|
||||||
n = cycle_index;
|
Mat mat_dest1(val, val, type[i]);
|
||||||
Mat mat_src(val, val, type[i]);
|
|
||||||
Mat mat_dest(val, val, type[i]);
|
|
||||||
Mat mat_dest1(val, val, type[i]);
|
|
||||||
|
|
||||||
test.SetDataRange(mat_src, 32);
|
test.SetDataRange(mat_src, 32);
|
||||||
test.SetDataRange(mat_dest, 32);
|
test.SetDataRange(mat_dest, 32);
|
||||||
|
|
||||||
aclMat aclmat_src(val, val, type[i], mat_src.data, acl_context);
|
aclMat aclmat_src(val, val, type[i], mat_src.data, acl_context);
|
||||||
aclMat aclmat_dest(val, val, type[i], mat_dest.data, acl_context);
|
aclMat aclmat_dest(val, val, type[i], mat_dest.data, acl_context);
|
||||||
|
|
||||||
begin = static_cast<double>(getTickCount());
|
begin = static_cast<double>(getTickCount());
|
||||||
while (n--)
|
while (n--) log(mat_src, mat_dest);
|
||||||
log(mat_src, mat_dest);
|
end = static_cast<double>(getTickCount());
|
||||||
end = static_cast<double>(getTickCount());
|
time = (end - begin) / getTickFrequency() / cycle_index;
|
||||||
time = (end - begin) / getTickFrequency() / cycle_index;
|
|
||||||
|
|
||||||
n = (cycle_index - 1);
|
n = (cycle_index - 1);
|
||||||
log(aclmat_src, aclmat_dest, 1);
|
log(aclmat_src, aclmat_dest, 1);
|
||||||
wait_stream(acl_context);
|
wait_stream(acl_context);
|
||||||
begin = static_cast<double>(getTickCount());
|
begin = static_cast<double>(getTickCount());
|
||||||
while (n--)
|
while (n--) log(aclmat_src, aclmat_dest, 1);
|
||||||
log(aclmat_src, aclmat_dest, 1);
|
wait_stream(acl_context, 1);
|
||||||
wait_stream(acl_context, 1);
|
end = static_cast<double>(getTickCount());
|
||||||
end = static_cast<double>(getTickCount());
|
acltime = (end - begin) / getTickFrequency() / (cycle_index - 1);
|
||||||
acltime = (end - begin) / getTickFrequency() / (cycle_index - 1);
|
|
||||||
|
|
||||||
aclmat_dest.download(mat_dest1);
|
aclmat_dest.download(mat_dest1);
|
||||||
if (val < 128)
|
if (val < 128)
|
||||||
cout << "Shape: " << val << " x " << val << "\t\t";
|
cout << "Shape: " << val << " x " << val << "\t\t";
|
||||||
else
|
else
|
||||||
cout << "Shape: " << val << " x " << val << "\t";
|
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 val, n;
|
int valmax = 8192;
|
||||||
int valmax = 8192;
|
int cycle_index = 10;
|
||||||
int cycle_index = 10;
|
double begin, end, time, acltime;
|
||||||
double begin, end, time, acltime;
|
Common_Test test;
|
||||||
Common_Test test;
|
// vector<int> type{CV_32FC2};
|
||||||
// vector<int> type{CV_32FC2};
|
vector<int> type{CV_32FC2, CV_32SC2, CV_64FC2};
|
||||||
vector<int> type{CV_32FC2,CV_32SC2, CV_64FC2};
|
for (size_t i = 0; i < type.size(); ++i) {
|
||||||
for (size_t i = 0; i < type.size(); ++i)
|
for (val = 8; val <= valmax; val *= 2) {
|
||||||
{
|
n = cycle_index;
|
||||||
for (val = 8; val <= valmax; val *= 2)
|
Mat mat_src1(val, val, type[i]);
|
||||||
{
|
Mat mat_src2(val, val, type[i]);
|
||||||
n = cycle_index;
|
Mat mat_dest(val, val, type[i]);
|
||||||
Mat mat_src1(val, val, type[i]);
|
Mat mat_dest1(val, val, type[i]);
|
||||||
Mat mat_src2(val, val, type[i]);
|
|
||||||
Mat mat_dest(val, val, type[i]);
|
|
||||||
Mat mat_dest1(val, val, type[i]);
|
|
||||||
|
|
||||||
test.SetDataRange(mat_src1, 32);
|
test.SetDataRange(mat_src1, 32);
|
||||||
test.SetDataRange(mat_src2, 32);
|
test.SetDataRange(mat_src2, 32);
|
||||||
test.SetDataRange(mat_dest, 32);
|
test.SetDataRange(mat_dest, 32);
|
||||||
|
|
||||||
aclMat aclmat_src1(val, val, type[i], mat_src2.data, acl_context);
|
aclMat aclmat_src1(val, val, type[i], mat_src2.data, acl_context);
|
||||||
aclMat aclmat_src2(val, val, type[i], mat_src1.data, acl_context);
|
aclMat aclmat_src2(val, val, type[i], mat_src1.data, acl_context);
|
||||||
aclMat aclmat_dest(val, val, type[i], mat_dest.data, acl_context);
|
aclMat aclmat_dest(val, val, type[i], mat_dest.data, acl_context);
|
||||||
|
|
||||||
begin = static_cast<double>(getTickCount());
|
begin = static_cast<double>(getTickCount());
|
||||||
while (n--)
|
while (n--) cv::max(mat_src1, mat_src2, mat_dest);
|
||||||
cv::max(mat_src1, mat_src2, mat_dest);
|
end = static_cast<double>(getTickCount());
|
||||||
end = static_cast<double>(getTickCount());
|
time = (end - begin) / getTickFrequency() / cycle_index;
|
||||||
time = (end - begin) / getTickFrequency() / cycle_index;
|
|
||||||
|
|
||||||
n = (cycle_index - 1);
|
n = (cycle_index - 1);
|
||||||
cv::acl::max(aclmat_src1, aclmat_src2, aclmat_dest);
|
cv::acl::max(aclmat_src1, aclmat_src2, aclmat_dest);
|
||||||
wait_stream(acl_context);
|
wait_stream(acl_context);
|
||||||
begin = static_cast<double>(getTickCount());
|
begin = static_cast<double>(getTickCount());
|
||||||
while (n--)
|
while (n--) cv::acl::max(aclmat_src1, aclmat_src2, aclmat_dest, 1);
|
||||||
cv::acl::max(aclmat_src1, aclmat_src2, aclmat_dest, 1);
|
wait_stream(acl_context, 1);
|
||||||
wait_stream(acl_context, 1);
|
end = static_cast<double>(getTickCount());
|
||||||
end = static_cast<double>(getTickCount());
|
acltime = (end - begin) / getTickFrequency() / (cycle_index - 1);
|
||||||
acltime = (end - begin) / getTickFrequency() / (cycle_index - 1);
|
|
||||||
|
|
||||||
aclmat_dest.download(mat_dest1);
|
aclmat_dest.download(mat_dest1);
|
||||||
bool ret = test.Test_Diff(mat_dest, mat_dest1);
|
bool ret = test.Test_Diff(mat_dest, mat_dest1);
|
||||||
ASSERT_TRUE(ret);
|
ASSERT_TRUE(ret);
|
||||||
if (val < 128)
|
if (val < 128)
|
||||||
cout << "Shape: " << val << " x " << val << "\t\t";
|
cout << "Shape: " << val << " x " << val << "\t\t";
|
||||||
else
|
else
|
||||||
cout << "Shape: " << val << " x " << val << "\t";
|
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 val, n;
|
int valmax = 8192;
|
||||||
int valmax = 8192;
|
int cycle_index = 10;
|
||||||
int cycle_index = 10;
|
double begin, end, time, acltime;
|
||||||
double begin, end, time, acltime;
|
Common_Test test;
|
||||||
Common_Test test;
|
// vector<int> type{CV_32FC3};
|
||||||
//vector<int> type{CV_32FC3};
|
vector<int> type{CV_32FC3, CV_32SC3, CV_64FC3};
|
||||||
vector<int> type{CV_32FC3,CV_32SC3, CV_64FC3};
|
for (size_t i = 0; i < type.size(); ++i) {
|
||||||
for (size_t i = 0; i < type.size(); ++i)
|
for (val = 8; val <= valmax; val *= 2) {
|
||||||
{
|
n = cycle_index;
|
||||||
for (val = 8; val <= valmax; val *= 2)
|
Mat mat_src1(val, val, type[i]);
|
||||||
{
|
Mat mat_src2(val, val, type[i]);
|
||||||
n = cycle_index;
|
Mat mat_dest(val, val, type[i]);
|
||||||
Mat mat_src1(val, val, type[i]);
|
Mat mat_dest1(val, val, type[i]);
|
||||||
Mat mat_src2(val, val, type[i]);
|
|
||||||
Mat mat_dest(val, val, type[i]);
|
|
||||||
Mat mat_dest1(val, val, type[i]);
|
|
||||||
|
|
||||||
test.SetDataRange(mat_src1, 32);
|
test.SetDataRange(mat_src1, 32);
|
||||||
test.SetDataRange(mat_src2, 32);
|
test.SetDataRange(mat_src2, 32);
|
||||||
test.SetDataRange(mat_dest, 32);
|
test.SetDataRange(mat_dest, 32);
|
||||||
|
|
||||||
aclMat aclmat_src1(val, val, type[i], mat_src2.data, acl_context);
|
aclMat aclmat_src1(val, val, type[i], mat_src2.data, acl_context);
|
||||||
aclMat aclmat_src2(val, val, type[i], mat_src1.data, acl_context);
|
aclMat aclmat_src2(val, val, type[i], mat_src1.data, acl_context);
|
||||||
aclMat aclmat_dest(val, val, type[i], mat_dest.data, acl_context);
|
aclMat aclmat_dest(val, val, type[i], mat_dest.data, acl_context);
|
||||||
|
|
||||||
begin = static_cast<double>(getTickCount());
|
begin = static_cast<double>(getTickCount());
|
||||||
while (n--)
|
while (n--) cv::min(mat_src1, mat_src2, mat_dest);
|
||||||
cv::min(mat_src1, mat_src2, mat_dest);
|
end = static_cast<double>(getTickCount());
|
||||||
end = static_cast<double>(getTickCount());
|
time = (end - begin) / getTickFrequency() / cycle_index;
|
||||||
time = (end - begin) / getTickFrequency() / cycle_index;
|
|
||||||
|
|
||||||
n = (cycle_index - 1);
|
n = (cycle_index - 1);
|
||||||
cv::acl::min(aclmat_src1, aclmat_src2, aclmat_dest);
|
cv::acl::min(aclmat_src1, aclmat_src2, aclmat_dest);
|
||||||
wait_stream(acl_context);
|
wait_stream(acl_context);
|
||||||
begin = static_cast<double>(getTickCount());
|
begin = static_cast<double>(getTickCount());
|
||||||
while (n--)
|
while (n--) cv::acl::min(aclmat_src1, aclmat_src2, aclmat_dest, 1);
|
||||||
cv::acl::min(aclmat_src1, aclmat_src2, aclmat_dest, 1);
|
wait_stream(acl_context, 1);
|
||||||
wait_stream(acl_context, 1);
|
end = static_cast<double>(getTickCount());
|
||||||
end = static_cast<double>(getTickCount());
|
acltime = (end - begin) / getTickFrequency() / (cycle_index - 1);
|
||||||
acltime = (end - begin) / getTickFrequency() / (cycle_index - 1);
|
|
||||||
|
|
||||||
aclmat_dest.download(mat_dest1);
|
aclmat_dest.download(mat_dest1);
|
||||||
bool ret = test.Test_Diff(mat_dest, mat_dest1);
|
bool ret = test.Test_Diff(mat_dest, mat_dest1);
|
||||||
ASSERT_TRUE(ret);
|
ASSERT_TRUE(ret);
|
||||||
if (val < 128)
|
if (val < 128)
|
||||||
cout << "Shape: " << val << " x " << val << "\t\t";
|
cout << "Shape: " << val << " x " << val << "\t\t";
|
||||||
else
|
else
|
||||||
cout << "Shape: " << val << " x " << val << "\t";
|
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,278 +1,239 @@
|
|||||||
#include "test_common.hpp"
|
#include "test_common.hpp"
|
||||||
#include "test_perf.hpp"
|
#include "test_perf.hpp"
|
||||||
|
|
||||||
/*
|
using namespace cv;
|
||||||
//disable
|
using namespace cv::acl;
|
||||||
void PERF_TEST::Test_Lookuptable(aclCxt *acl_context_0)
|
using namespace cvtest;
|
||||||
{
|
using namespace testing;
|
||||||
int type = CV_8UC1;
|
using namespace std;
|
||||||
Common_Test test;
|
|
||||||
Mat mat_src(1, 256, type);
|
|
||||||
Mat mat_dest(1, 256, type);
|
|
||||||
Mat lookuptable(1, 256, type);
|
|
||||||
|
|
||||||
test.SetDataRange(mat_src, 32);
|
void PERF_TEST::Test_Merge(aclCxt *acl_context) {
|
||||||
test.SetDataRange(lookuptable, 32);
|
int val, n;
|
||||||
|
int valmax = 8192;
|
||||||
|
int cycle_index = 10;
|
||||||
|
double begin, end, time, acltime;
|
||||||
|
Common_Test test;
|
||||||
|
|
||||||
aclMat aclmat_src(1, 256, type, mat_src.data, acl_context_0);
|
vector<int> srcType{CV_8UC1, CV_32FC1, CV_32SC1};
|
||||||
aclMat aclmat_dest(1, 256, type, mat_dest.data, acl_context_0);
|
|
||||||
aclMat lut(1, 256, type, lookuptable.data, acl_context_0);
|
|
||||||
// LUT(mat_src, lookuptable, mat_dest);
|
|
||||||
lookUpTable(aclmat_src, lut, aclmat_dest);
|
|
||||||
cout << mat_src << endl;
|
|
||||||
cout << lookuptable << endl;
|
|
||||||
cout << mat_dest << endl;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
// vector<int> destType{CV_32FC3};
|
||||||
|
vector<int> destType{CV_8UC3, CV_32FC3, CV_32SC3};
|
||||||
|
for (size_t i = 0; i < srcType.size(); ++i) {
|
||||||
|
test.PrintLog("Perf test : Function: merge()", srcType[i]);
|
||||||
|
for (val = 8; val <= valmax; val *= 2) {
|
||||||
|
n = cycle_index;
|
||||||
|
Mat mat_src1(val, val, srcType[i], Scalar(1));
|
||||||
|
Mat mat_src2(val, val, srcType[i], Scalar(2));
|
||||||
|
Mat mat_src3(val, val, srcType[i], Scalar(3));
|
||||||
|
Mat mat_dest(val, val, destType[i]);
|
||||||
|
Mat mat_dest1(val, val, destType[i]);
|
||||||
|
|
||||||
void PERF_TEST::Test_Merge(aclCxt *acl_context)
|
test.SetDataRange(mat_src1, 32);
|
||||||
{
|
test.SetDataRange(mat_src2, 32);
|
||||||
int val, n;
|
test.SetDataRange(mat_src3, 32);
|
||||||
int valmax = 8192;
|
|
||||||
int cycle_index = 10;
|
|
||||||
double begin, end, time, acltime;
|
|
||||||
Common_Test test;
|
|
||||||
|
|
||||||
|
aclMat aclmat_src1(val, val, srcType[i], mat_src1.data, acl_context);
|
||||||
|
aclMat aclmat_src2(val, val, srcType[i], mat_src2.data, acl_context);
|
||||||
|
aclMat aclmat_src3(val, val, srcType[i], mat_src3.data, acl_context);
|
||||||
|
aclMat aclmat_dest(val, val, destType[i], mat_dest.data, acl_context);
|
||||||
|
|
||||||
vector<int> srcType{CV_8UC1,CV_32FC1, CV_32SC1};
|
vector<Mat> src;
|
||||||
|
src.emplace_back(mat_src1);
|
||||||
|
src.emplace_back(mat_src2);
|
||||||
|
src.emplace_back(mat_src3);
|
||||||
|
|
||||||
//vector<int> destType{CV_32FC3};
|
vector<aclMat> acl_src;
|
||||||
vector<int> destType{CV_8UC3,CV_32FC3, CV_32SC3};
|
acl_src.emplace_back(aclmat_src1);
|
||||||
for (size_t i = 0; i < srcType.size(); ++i)
|
acl_src.emplace_back(aclmat_src2);
|
||||||
{
|
acl_src.emplace_back(aclmat_src3);
|
||||||
test.PrintLog("Perf test : Function: merge()", srcType[i]);
|
|
||||||
for (val = 8; val <= valmax; val *= 2)
|
|
||||||
{
|
|
||||||
n = cycle_index;
|
|
||||||
Mat mat_src1(val, val, srcType[i], Scalar(1));
|
|
||||||
Mat mat_src2(val, val, srcType[i], Scalar(2));
|
|
||||||
Mat mat_src3(val, val, srcType[i], Scalar(3));
|
|
||||||
Mat mat_dest(val, val, destType[i]);
|
|
||||||
Mat mat_dest1(val, val, destType[i]);
|
|
||||||
|
|
||||||
test.SetDataRange(mat_src1, 32);
|
begin = static_cast<double>(getTickCount());
|
||||||
test.SetDataRange(mat_src2, 32);
|
while (n--) merge(src, mat_dest);
|
||||||
test.SetDataRange(mat_src3, 32);
|
end = static_cast<double>(getTickCount());
|
||||||
|
time = (end - begin) / getTickFrequency() / cycle_index;
|
||||||
|
|
||||||
aclMat aclmat_src1(val, val, srcType[i], mat_src1.data, acl_context);
|
n = (cycle_index - 1);
|
||||||
aclMat aclmat_src2(val, val, srcType[i], mat_src2.data, acl_context);
|
merge(acl_src, aclmat_dest);
|
||||||
aclMat aclmat_src3(val, val, srcType[i], mat_src3.data, acl_context);
|
wait_stream(acl_context);
|
||||||
aclMat aclmat_dest(val, val, destType[i], mat_dest.data, acl_context);
|
begin = static_cast<double>(getTickCount());
|
||||||
|
while (n--) merge(acl_src, aclmat_dest, 1);
|
||||||
vector<Mat> src;
|
wait_stream(acl_context, 1);
|
||||||
src.emplace_back(mat_src1);
|
end = static_cast<double>(getTickCount());
|
||||||
src.emplace_back(mat_src2);
|
acltime = (end - begin) / getTickFrequency() / (cycle_index - 1);
|
||||||
src.emplace_back(mat_src3);
|
aclmat_dest.download(mat_dest1);
|
||||||
|
bool ret = test.Test_Diff(mat_dest, mat_dest1);
|
||||||
vector<aclMat> acl_src;
|
ASSERT_TRUE(ret);
|
||||||
acl_src.emplace_back(aclmat_src1);
|
if (val < 128)
|
||||||
acl_src.emplace_back(aclmat_src2);
|
cout << "Shape: " << val << " x " << val << "\t\t";
|
||||||
acl_src.emplace_back(aclmat_src3);
|
else
|
||||||
|
cout << "Shape: " << val << " x " << val << "\t";
|
||||||
begin = static_cast<double>(getTickCount());
|
cout << "CpuTimes: " << time << "\tAclTimes: " << acltime
|
||||||
while (n--)
|
<< "\tRate: " << time / acltime << endl;
|
||||||
merge(src, mat_dest);
|
|
||||||
end = static_cast<double>(getTickCount());
|
|
||||||
time = (end - begin) / getTickFrequency() / cycle_index;
|
|
||||||
|
|
||||||
n = (cycle_index - 1);
|
|
||||||
merge(acl_src, aclmat_dest);
|
|
||||||
wait_stream(acl_context);
|
|
||||||
begin = static_cast<double>(getTickCount());
|
|
||||||
while (n--)
|
|
||||||
merge(acl_src, aclmat_dest, 1);
|
|
||||||
wait_stream(acl_context, 1);
|
|
||||||
end = static_cast<double>(getTickCount());
|
|
||||||
acltime = (end - begin) / getTickFrequency() / (cycle_index - 1);
|
|
||||||
aclmat_dest.download(mat_dest1);
|
|
||||||
bool ret = test.Test_Diff(mat_dest, mat_dest1);
|
|
||||||
ASSERT_TRUE(ret);
|
|
||||||
if (val < 128)
|
|
||||||
cout << "Shape: " << val << " x " << val << "\t\t";
|
|
||||||
else
|
|
||||||
cout << "Shape: " << val << " x " << val << "\t";
|
|
||||||
cout << "CpuTimes: " << time << "\tAclTimes: " << acltime << "\tRate: " << time / acltime << endl;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PERF_TEST::Test_Transpose(aclCxt *acl_context) {
|
||||||
|
int val, n;
|
||||||
|
int valmax = 8192;
|
||||||
|
int cycle_index = 10;
|
||||||
|
double begin, end, time, acltime;
|
||||||
|
Common_Test test;
|
||||||
|
|
||||||
void PERF_TEST::Test_Transpose(aclCxt *acl_context)
|
// vector<int> type{CV_32FC1};
|
||||||
{
|
vector<int> type{CV_32FC1, CV_32SC1};
|
||||||
int val, n;
|
for (size_t i = 0; i < type.size(); ++i) {
|
||||||
int valmax = 8192;
|
test.PrintLog("Perf test : Function: transpose()", type[i]);
|
||||||
int cycle_index = 10;
|
for (val = 8; val <= valmax; val *= 2) {
|
||||||
double begin, end, time, acltime;
|
n = cycle_index;
|
||||||
Common_Test test;
|
Mat mat_src(val, val, type[i]);
|
||||||
|
Mat mat_dest(val, val, type[i]);
|
||||||
|
Mat mat_dest1(val, val, type[i]);
|
||||||
|
|
||||||
//vector<int> type{CV_32FC1};
|
test.SetDataRange(mat_src, 32);
|
||||||
vector<int> type{CV_32FC1,CV_32SC1};
|
|
||||||
for (size_t i = 0; i < type.size(); ++i)
|
|
||||||
{
|
|
||||||
test.PrintLog("Perf test : Function: transpose()", type[i]);
|
|
||||||
for (val = 8; val <= valmax; val *= 2)
|
|
||||||
{
|
|
||||||
n = cycle_index;
|
|
||||||
Mat mat_src(val, val, type[i]);
|
|
||||||
Mat mat_dest(val, val, type[i]);
|
|
||||||
Mat mat_dest1(val, val, type[i]);
|
|
||||||
|
|
||||||
test.SetDataRange(mat_src, 32);
|
aclMat aclmat_src(val, val, type[i], mat_src.data, acl_context);
|
||||||
|
aclMat aclmat_dest(val, val, type[i], mat_dest.data, acl_context);
|
||||||
|
|
||||||
aclMat aclmat_src(val, val, type[i], mat_src.data, acl_context);
|
begin = static_cast<double>(getTickCount());
|
||||||
aclMat aclmat_dest(val, val, type[i], mat_dest.data, acl_context);
|
while (n--) transpose(mat_src, mat_dest);
|
||||||
|
end = static_cast<double>(getTickCount());
|
||||||
|
time = (end - begin) / getTickFrequency() / cycle_index;
|
||||||
|
|
||||||
begin = static_cast<double>(getTickCount());
|
n = (cycle_index - 1);
|
||||||
while (n--)
|
transpose(aclmat_src, aclmat_dest);
|
||||||
transpose(mat_src, mat_dest);
|
wait_stream(acl_context);
|
||||||
end = static_cast<double>(getTickCount());
|
begin = static_cast<double>(getTickCount());
|
||||||
time = (end - begin) / getTickFrequency() / cycle_index;
|
while (n--) transpose(aclmat_src, aclmat_dest, 1);
|
||||||
|
wait_stream(acl_context, 1);
|
||||||
|
end = static_cast<double>(getTickCount());
|
||||||
|
acltime = (end - begin) / getTickFrequency() / (cycle_index - 1);
|
||||||
|
|
||||||
n = (cycle_index - 1);
|
aclmat_dest.download(mat_dest1);
|
||||||
transpose(aclmat_src, aclmat_dest);
|
bool ret = test.Test_Diff(mat_dest, mat_dest1);
|
||||||
wait_stream(acl_context);
|
ASSERT_TRUE(ret);
|
||||||
begin = static_cast<double>(getTickCount());
|
if (val < 128)
|
||||||
while (n--)
|
cout << "Shape: " << val << " x " << val << "\t\t";
|
||||||
transpose(aclmat_src, aclmat_dest, 1);
|
else
|
||||||
wait_stream(acl_context, 1);
|
cout << "Shape: " << val << " x " << val << "\t";
|
||||||
end = static_cast<double>(getTickCount());
|
cout << "CpuTimes: " << time << "\tAclTimes: " << acltime
|
||||||
acltime = (end - begin) / getTickFrequency() / (cycle_index - 1);
|
<< "\tRate: " << time / acltime << endl;
|
||||||
|
|
||||||
aclmat_dest.download(mat_dest1);
|
|
||||||
bool ret = test.Test_Diff(mat_dest, mat_dest1);
|
|
||||||
ASSERT_TRUE(ret);
|
|
||||||
if (val < 128)
|
|
||||||
cout << "Shape: " << val << " x " << val << "\t\t";
|
|
||||||
else
|
|
||||||
cout << "Shape: " << val << " x " << val << "\t";
|
|
||||||
cout << "CpuTimes: " << time << "\tAclTimes: " << acltime << "\tRate: " << time / acltime << endl;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PERF_TEST::Test_Split(aclCxt *acl_context)
|
void PERF_TEST::Test_Split(aclCxt *acl_context) {
|
||||||
{
|
int val, n;
|
||||||
int val, n;
|
int valmax = 8192;
|
||||||
int valmax = 8192;
|
int cycle_index = 10;
|
||||||
int cycle_index = 10;
|
double begin, end, time, acltime;
|
||||||
double begin, end, time, acltime;
|
Common_Test test;
|
||||||
Common_Test test;
|
|
||||||
|
|
||||||
//vector<int> srcType{CV_32FC3};
|
// vector<int> srcType{CV_32FC3};
|
||||||
vector<int> srcType{CV_8UC3,CV_32FC3, CV_32SC3};
|
vector<int> srcType{CV_8UC3, CV_32FC3, CV_32SC3};
|
||||||
vector<int> destType{CV_8UC1,CV_32FC1, CV_32SC1};
|
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]);
|
||||||
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]);
|
||||||
n = cycle_index;
|
Mat mat_dest1(val, val, destType[i]);
|
||||||
Mat mat_src(val, val, srcType[i]);
|
Mat mat_dest2(val, val, destType[i]);
|
||||||
Mat mat_dest1(val, val, destType[i]);
|
Mat mat_dest3(val, val, destType[i]);
|
||||||
Mat mat_dest2(val, val, destType[i]);
|
|
||||||
Mat mat_dest3(val, val, destType[i]);
|
|
||||||
|
|
||||||
test.SetDataRange(mat_src, 32);
|
test.SetDataRange(mat_src, 32);
|
||||||
|
|
||||||
aclMat aclmat_src(val, val, srcType[i], mat_src.data, acl_context);
|
aclMat aclmat_src(val, val, srcType[i], mat_src.data, acl_context);
|
||||||
aclMat aclmat_dest1;
|
aclMat aclmat_dest1;
|
||||||
aclMat aclmat_dest2;
|
aclMat aclmat_dest2;
|
||||||
aclMat aclmat_dest3;
|
aclMat aclmat_dest3;
|
||||||
|
|
||||||
vector<Mat> dest;
|
vector<Mat> dest;
|
||||||
dest.emplace_back(mat_dest1);
|
dest.emplace_back(mat_dest1);
|
||||||
dest.emplace_back(mat_dest2);
|
dest.emplace_back(mat_dest2);
|
||||||
dest.emplace_back(mat_dest3);
|
dest.emplace_back(mat_dest3);
|
||||||
|
|
||||||
vector<aclMat> acl_dest;
|
vector<aclMat> acl_dest;
|
||||||
acl_dest.emplace_back(aclmat_dest1);
|
acl_dest.emplace_back(aclmat_dest1);
|
||||||
acl_dest.emplace_back(aclmat_dest2);
|
acl_dest.emplace_back(aclmat_dest2);
|
||||||
acl_dest.emplace_back(aclmat_dest3);
|
acl_dest.emplace_back(aclmat_dest3);
|
||||||
|
|
||||||
begin = static_cast<double>(getTickCount());
|
begin = static_cast<double>(getTickCount());
|
||||||
while (n--)
|
while (n--) split(mat_src, dest);
|
||||||
split(mat_src, dest);
|
end = static_cast<double>(getTickCount());
|
||||||
end = static_cast<double>(getTickCount());
|
time = (end - begin) / getTickFrequency() / cycle_index;
|
||||||
time = (end - begin) / getTickFrequency() / cycle_index;
|
|
||||||
|
|
||||||
n = (cycle_index - 1);
|
n = (cycle_index - 1);
|
||||||
split(aclmat_src, acl_dest);
|
split(aclmat_src, acl_dest);
|
||||||
wait_stream(acl_context);
|
wait_stream(acl_context);
|
||||||
begin = static_cast<double>(getTickCount());
|
begin = static_cast<double>(getTickCount());
|
||||||
while (n--)
|
while (n--) split(aclmat_src, acl_dest, 1);
|
||||||
split(aclmat_src, acl_dest, 1);
|
wait_stream(acl_context, 1);
|
||||||
wait_stream(acl_context, 1);
|
end = static_cast<double>(getTickCount());
|
||||||
end = static_cast<double>(getTickCount());
|
acltime = (end - begin) / getTickFrequency() / (cycle_index - 1);
|
||||||
acltime = (end - begin) / getTickFrequency() / (cycle_index - 1);
|
|
||||||
|
|
||||||
(acl_dest.data())[0].download(mat_dest1);
|
(acl_dest.data())[0].download(mat_dest1);
|
||||||
(acl_dest.data())[1].download(mat_dest2);
|
(acl_dest.data())[1].download(mat_dest2);
|
||||||
(acl_dest.data())[2].download(mat_dest3);
|
(acl_dest.data())[2].download(mat_dest3);
|
||||||
|
|
||||||
bool ret = test.Test_Diff((dest.data())[0], mat_dest1);
|
bool ret = test.Test_Diff((dest.data())[0], mat_dest1);
|
||||||
ret &= test.Test_Diff((dest.data())[1], mat_dest2);
|
ret &= test.Test_Diff((dest.data())[1], mat_dest2);
|
||||||
ret &= test.Test_Diff((dest.data())[2], mat_dest3);
|
ret &= test.Test_Diff((dest.data())[2], mat_dest3);
|
||||||
ASSERT_TRUE(ret);
|
ASSERT_TRUE(ret);
|
||||||
if (val < 128)
|
if (val < 128)
|
||||||
cout << "Shape: " << val << " x " << val << "\t\t";
|
cout << "Shape: " << val << " x " << val << "\t\t";
|
||||||
else
|
else
|
||||||
cout << "Shape: " << val << " x " << val << "\t";
|
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 val, n;
|
int valmax = 8192;
|
||||||
int valmax = 8192;
|
int cycle_index = 100;
|
||||||
int cycle_index = 100;
|
double begin, end, time, acltime;
|
||||||
double begin, end, time, acltime;
|
Common_Test test;
|
||||||
Common_Test test;
|
|
||||||
|
|
||||||
vector<int> type{CV_8UC1, CV_32FC1, CV_32SC1, CV_64FC1};
|
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]);
|
||||||
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]);
|
||||||
n = cycle_index;
|
Mat mat_dest(val, val, type[i]);
|
||||||
Mat mat_src(val, val, type[i]);
|
Mat mat_dest1(val, val, type[i]);
|
||||||
Mat mat_dest(val, val, type[i]);
|
|
||||||
Mat mat_dest1(val, val, type[i]);
|
|
||||||
|
|
||||||
test.SetDataRange(mat_src, 32);
|
test.SetDataRange(mat_src, 32);
|
||||||
|
|
||||||
aclMat aclmat_src(val, val, type[i], mat_src.data, acl_context);
|
aclMat aclmat_src(val, val, type[i], mat_src.data, acl_context);
|
||||||
aclMat aclmat_dest(val, val, type[i], mat_dest.data, acl_context);
|
aclMat aclmat_dest(val, val, type[i], mat_dest.data, acl_context);
|
||||||
|
|
||||||
begin = static_cast<double>(getTickCount());
|
begin = static_cast<double>(getTickCount());
|
||||||
while (n--)
|
while (n--) flip(mat_src, mat_dest, 0);
|
||||||
flip(mat_src, mat_dest, 0);
|
end = static_cast<double>(getTickCount());
|
||||||
end = static_cast<double>(getTickCount());
|
time = (end - begin) / getTickFrequency() / cycle_index;
|
||||||
time = (end - begin) / getTickFrequency() / cycle_index;
|
|
||||||
|
|
||||||
n = (cycle_index - 1);
|
n = (cycle_index - 1);
|
||||||
flip(aclmat_src, aclmat_dest, 0);
|
flip(aclmat_src, aclmat_dest, 0);
|
||||||
wait_stream(acl_context);
|
wait_stream(acl_context);
|
||||||
begin = static_cast<double>(getTickCount());
|
begin = static_cast<double>(getTickCount());
|
||||||
while (n--)
|
while (n--) flip(aclmat_src, aclmat_dest, 0, 1);
|
||||||
flip(aclmat_src, aclmat_dest, 0, 1);
|
wait_stream(acl_context, 1);
|
||||||
wait_stream(acl_context, 1);
|
end = static_cast<double>(getTickCount());
|
||||||
end = static_cast<double>(getTickCount());
|
acltime = (end - begin) / getTickFrequency() / (cycle_index - 1);
|
||||||
acltime = (end - begin) / getTickFrequency() / (cycle_index - 1);
|
|
||||||
|
|
||||||
aclmat_dest.download(mat_dest1);
|
aclmat_dest.download(mat_dest1);
|
||||||
bool ret = test.Test_Diff(mat_dest, mat_dest1);
|
bool ret = test.Test_Diff(mat_dest, mat_dest1);
|
||||||
ASSERT_TRUE(ret);
|
ASSERT_TRUE(ret);
|
||||||
if (val < 128)
|
if (val < 128)
|
||||||
cout << "Shape: " << val << " x " << val << "\t\t";
|
cout << "Shape: " << val << " x " << val << "\t\t";
|
||||||
else
|
else
|
||||||
cout << "Shape: " << val << " x " << val << "\t";
|
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"
|
#include "test_precomp.hpp"
|
||||||
|
|
||||||
class PERF_TEST
|
class PERF_TEST {
|
||||||
{
|
public:
|
||||||
public:
|
CV_EXPORTS void Test_operator_add_perf(cv::acl::aclCxt *acl_context);
|
||||||
CV_EXPORTS void Test_operator_add_perf(aclCxt *acl_context);
|
CV_EXPORTS void Test_operator_sub_perf(cv::acl::aclCxt *acl_context);
|
||||||
CV_EXPORTS void Test_operator_sub_perf(aclCxt *acl_context);
|
CV_EXPORTS void Test_operator_div_perf(cv::acl::aclCxt *acl_context);
|
||||||
CV_EXPORTS void Test_operator_div_perf(aclCxt *acl_context);
|
CV_EXPORTS void Test_operator_mul_perf(cv::acl::aclCxt *acl_context);
|
||||||
CV_EXPORTS void Test_operator_mul_perf(aclCxt *acl_context);
|
CV_EXPORTS void Test_Abs(cv::acl::aclCxt *acl_context);
|
||||||
CV_EXPORTS void Test_Abs(aclCxt *acl_context);
|
CV_EXPORTS void Test_Pow(cv::acl::aclCxt *acl_context);
|
||||||
CV_EXPORTS void Test_Pow(aclCxt *acl_context);
|
CV_EXPORTS void Test_Sqrt(cv::acl::aclCxt *acl_context);
|
||||||
CV_EXPORTS void Test_Sqrt(aclCxt *acl_context);
|
CV_EXPORTS void Test_Add(cv::acl::aclCxt *acl_context);
|
||||||
CV_EXPORTS void Test_Add(aclCxt *acl_context);
|
CV_EXPORTS void Test_Divide(cv::acl::aclCxt *acl_context);
|
||||||
CV_EXPORTS void Test_Divide(aclCxt *acl_context);
|
CV_EXPORTS void Test_Exp(cv::acl::aclCxt *acl_context);
|
||||||
CV_EXPORTS void Test_Exp(aclCxt *acl_context);
|
CV_EXPORTS void Test_Log(cv::acl::aclCxt *acl_context);
|
||||||
CV_EXPORTS void Test_Log(aclCxt *acl_context);
|
CV_EXPORTS void Test_Max(cv::acl::aclCxt *acl_context);
|
||||||
CV_EXPORTS void Test_Max(aclCxt *acl_context);
|
CV_EXPORTS void Test_Min(cv::acl::aclCxt *acl_context);
|
||||||
CV_EXPORTS void Test_Min(aclCxt *acl_context);
|
|
||||||
|
|
||||||
CV_EXPORTS void Test_MatMul(aclCxt *acl_context);
|
CV_EXPORTS void Test_MatMul(cv::acl::aclCxt *acl_context);
|
||||||
CV_EXPORTS void Test_Convolution(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_Lookuptable(cv::acl::aclCxt *acl_context);
|
||||||
CV_EXPORTS void Test_Merge(aclCxt *acl_context);
|
CV_EXPORTS void Test_Merge(cv::acl::aclCxt *acl_context);
|
||||||
CV_EXPORTS void Test_Split(aclCxt *acl_context);
|
CV_EXPORTS void Test_Split(cv::acl::aclCxt *acl_context);
|
||||||
CV_EXPORTS void Test_Transpose(aclCxt *acl_context);
|
CV_EXPORTS void Test_Transpose(cv::acl::aclCxt *acl_context);
|
||||||
CV_EXPORTS void Test_Flip(aclCxt *acl_context);
|
CV_EXPORTS void Test_Flip(cv::acl::aclCxt *acl_context);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
@@ -1,27 +1,21 @@
|
|||||||
// This file is part of OpenCV project.
|
// This file is part of OpenCV project.
|
||||||
// It is subject to the license terms in the LICENSE file found in the top-level directory
|
// It is subject to the license terms in the LICENSE file found in the top-level
|
||||||
// of this distribution and at http://opencv.org/license.html.
|
// directory of this distribution and at http://opencv.org/license.html.
|
||||||
#ifndef __OPENCV_TEST_PRECOMP_HPP__
|
#ifndef __OPENCV_TEST_PRECOMP_HPP__
|
||||||
#define __OPENCV_TEST_PRECOMP_HPP__
|
#define __OPENCV_TEST_PRECOMP_HPP__
|
||||||
|
#include <iomanip>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <thread>
|
#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.h"
|
||||||
#include "acl/acl_op_compiler.h"
|
#include "acl/acl_op_compiler.h"
|
||||||
|
#include "opencv2/acl/acl.hpp"
|
||||||
using namespace cv;
|
#include "opencv2/core.hpp"
|
||||||
using namespace cv::acl;
|
#include "opencv2/highgui.hpp"
|
||||||
using namespace cvtest;
|
#include "opencv2/imgproc.hpp"
|
||||||
using namespace testing;
|
#include "opencv2/ts.hpp"
|
||||||
using namespace std;
|
#include "opencv2/videoio.hpp"
|
||||||
|
#include "sys/time.h"
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user