catching OpenCL double not supported exceptions
[profile/ivi/opencv.git] / modules / ocl / test / test_gemm.cpp
1 /*M///////////////////////////////////////////////////////////////////////////////////////
2 //
3 //  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
4 //
5 //  By downloading, copying, installing or using the software you agree to this license.
6 //  If you do not agree to this license, do not download, install,
7 //  copy or use the software.
8 //
9 //
10 //                           License Agreement
11 //                For Open Source Computer Vision Library
12 //
13 // Copyright (C) 2010-2012, Multicoreware, Inc., all rights reserved.
14 // Copyright (C) 2010-2012, Advanced Micro Devices, Inc., all rights reserved.
15 // Third party copyrights are property of their respective owners.
16 //
17 // @Authors
18 //    Peng Xiao, pengxiao@multicorewareinc.com
19 // Redistribution and use in source and binary forms, with or without modification,
20 // are permitted provided that the following conditions are met:
21 //
22 //   * Redistribution's of source code must retain the above copyright notice,
23 //     this list of conditions and the following disclaimer.
24 //
25 //   * Redistribution's in binary form must reproduce the above copyright notice,
26 //     this list of conditions and the following disclaimer in the documentation
27 //     and/or other oclMaterials provided with the distribution.
28 //
29 //   * The name of the copyright holders may not be used to endorse or promote products
30 //     derived from this software without specific prior written permission.
31 //
32 // This software is provided by the copyright holders and contributors as is and
33 // any express or implied warranties, including, but not limited to, the implied
34 // warranties of merchantability and fitness for a particular purpose are disclaimed.
35 // In no event shall the Intel Corporation or contributors be liable for any direct,
36 // indirect, incidental, special, exemplary, or consequential damages
37 // (including, but not limited to, procurement of substitute goods or services;
38 // loss of use, data, or profits; or business interruption) however caused
39 // and on any theory of liability, whether in contract, strict liability,
40 // or tort (including negligence or otherwise) arising in any way out of
41 // the use of this software, even if advised of the possibility of such damage.
42 //
43 //M*/
44
45
46 #include "test_precomp.hpp"
47 using namespace std;
48 #ifdef HAVE_CLAMDBLAS
49 ////////////////////////////////////////////////////////////////////////////
50 // GEMM
51 PARAM_TEST_CASE(Gemm, int, cv::Size, int)
52 {
53     int      type;
54     cv::Size mat_size;
55     int          flags;
56
57     virtual void SetUp()
58     {
59         type     = GET_PARAM(0);
60         mat_size = GET_PARAM(1);
61         flags    = GET_PARAM(2);
62     }
63 };
64
65 OCL_TEST_P(Gemm, Accuracy)
66 {
67     cv::Mat a = randomMat(mat_size, type, 0.0, 10.0);
68     cv::Mat b = randomMat(mat_size, type, 0.0, 10.0);
69     cv::Mat c = randomMat(mat_size, type, 0.0, 10.0);
70
71     cv::Mat dst;
72     cv::ocl::oclMat ocl_dst;
73
74     cv::gemm(a, b, 1.0, c, 1.0, dst, flags);
75     cv::ocl::gemm(cv::ocl::oclMat(a), cv::ocl::oclMat(b), 1.0, cv::ocl::oclMat(c), 1.0, ocl_dst, flags);
76
77     EXPECT_MAT_NEAR(dst, ocl_dst, mat_size.area() * 1e-4);
78 }
79
80 INSTANTIATE_TEST_CASE_P(ocl_gemm, Gemm, testing::Combine(
81                             testing::Values(CV_32FC1, CV_32FC2/*, CV_64FC1, CV_64FC2*/),
82                             testing::Values(cv::Size(20, 20), cv::Size(300, 300)),
83                             testing::Values(0, (int)cv::GEMM_1_T, (int)cv::GEMM_2_T, (int)(cv::GEMM_1_T + cv::GEMM_2_T))));
84 #endif