File size: 1,854 Bytes
dffe123 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | // This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
//
// Copyright (C) 2019 Intel Corporation
#include "precomp.hpp"
#include <opencv2/gapi/core.hpp>
#include <opencv2/gapi/plaidml/core.hpp>
#ifdef HAVE_PLAIDML
#include <opencv2/gapi/plaidml/gplaidmlkernel.hpp>
#include <plaidml2/edsl/edsl.h>
#define GAPI_PLAIDML_LOGICAL_OP(Name, API, Op) \
GAPI_PLAIDML_KERNEL(Name, API) \
{ \
static void run(const plaidml::edsl::Tensor& src1, \
const plaidml::edsl::Tensor& src2, \
plaidml::edsl::Tensor& dst) \
{ \
dst = src1 Op src2; \
}; \
}; \
#define GAPI_PLAIDML_ARITHMETIC_OP(Name, API, Op) \
GAPI_PLAIDML_KERNEL(Name, API) \
{ \
static void run(const plaidml::edsl::Tensor& src1, \
const plaidml::edsl::Tensor& src2, \
int, /* dtype */ \
plaidml::edsl::Tensor& dst) \
{ \
dst = src1 Op src2; \
}; \
}; \
GAPI_PLAIDML_LOGICAL_OP(GPlaidMLAnd, cv::gapi::core::GAnd, &);
GAPI_PLAIDML_LOGICAL_OP(GPlaidMLXor, cv::gapi::core::GXor, ^);
GAPI_PLAIDML_LOGICAL_OP(GPlaidMLOr , cv::gapi::core::GOr , |)
GAPI_PLAIDML_ARITHMETIC_OP(GPlaidMLAdd, cv::gapi::core::GAdd, +);
GAPI_PLAIDML_ARITHMETIC_OP(GPlaidMLSub, cv::gapi::core::GSub, -);
cv::GKernelPackage cv::gapi::core::plaidml::kernels()
{
static auto pkg = cv::gapi::kernels<GPlaidMLAdd, GPlaidMLSub, GPlaidMLAnd, GPlaidMLXor, GPlaidMLOr>();
return pkg;
}
#else // HAVE_PLAIDML
cv::GKernelPackage cv::gapi::core::plaidml::kernels()
{
// Still provide this symbol to avoid linking issues
util::throw_error(std::runtime_error("G-API has been compiled without PlaidML2 support"));
}
#endif // HAVE_PLAIDML
|