summaryrefslogtreecommitdiff
path: root/external/clBLAS/src/tests/functional/test-functional.cpp
blob: c147b775e5d8bde31815bf90ae6a1816d5fc793c (plain)
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/* ************************************************************************
 * Copyright 2013 Advanced Micro Devices, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ************************************************************************/


#include <gtest/gtest.h>
#include "BlasBase.h"


///////////////////////////////////////////////////////////////////////////////

int
main(int argc, char *argv[])
{
    ::clMath::BlasBase *base;
    TestParams params;
    int ret;

    if ((argc > 1) && !strcmp(argv[1], "--test-help")) {
        printUsage("test-functional");
        return 0;
    }

    ::testing::InitGoogleTest(&argc, argv);
    ::std::cerr << "Initialize OpenCL and clblas..." << ::std::endl;
    base = ::clMath::BlasBase::getInstance();
    if (base == NULL) {
        ::std::cerr << "Fatal error, OpenCL or clblas initialization failed! "
                       "Leaving the test." << ::std::endl;
        return -1;
    }

    if (argc != 1) {
        params.optFlags = NO_FLAGS;
        params.devType = CL_DEVICE_TYPE_GPU;
        params.devName = NULL;
        if (parseBlasCmdLineArgs(argc, argv, &params) != 0) {
            printUsage(argv[0]);
            return 1;
        }
        if (params.optFlags & SET_SEED) {
            base->setSeed(params.seed);
        }
        if (params.optFlags & SET_ALPHA) {
            base->setAlpha(params.alpha);
        }
        if (params.optFlags & SET_BETA) {
            base->setBeta(params.beta);
        }
        if (params.optFlags & SET_M) {
            base->setM(params.M);
        }
        if (params.optFlags & SET_N) {
            base->setN(params.N);
        }
        if (params.optFlags & SET_K) {
            base->setK(params.K);
        }
        if (params.optFlags & SET_INCX) {
            base->setIncX(params.incx);
        }
        if (params.optFlags & SET_INCY) {
            base->setIncY(params.incy);
        }
        if (params.optFlags & SET_DEVICE_TYPE) {
            if (!base->setDeviceType(&params.devType, params.devName)) {
                ::std::cerr << "Fatal error, OpenCL or clblas "
                        "initialization failed! Leaving the test." <<
                        ::std::endl;
                return -1;
            }
        }
        if (params.optFlags & SET_NUM_COMMAND_QUEUES) {
            base->setNumCommandQueues(params.numCommandQueues);
        }
    }

    parseEnv(&params);
    if ((params.optFlags & SET_USE_IMAGES) &&
            (params.devType != CL_DEVICE_TYPE_CPU)) {
        base->setUseImages(params.useImages);
    }

	/* Use of image based buffers is deprecated
    if (base->useImages()) {
        if (base->addScratchImages()) {
            std::cerr << "FATAL ERROR, CANNOT CREATE SCRATCH IMAGES!" << std::endl;
        }
    }
	*/

    ret = RUN_ALL_TESTS();

    if (base->useImages()) {
        base->removeScratchImages();
    }

    return ret;
}