1 /* ************************************************************************
2 * Copyright 2013 Advanced Micro Devices, Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 * ************************************************************************/
16
17
18 #include <gtest/gtest.h>
19 #include "BlasBase.h"
20
21
22 ///////////////////////////////////////////////////////////////////////////////
23
24 int
main(int argc,char * argv[])25 main(int argc, char *argv[])
26 {
27 ::clMath::BlasBase *base;
28 TestParams params;
29 int ret;
30
31 if ((argc > 1) && !strcmp(argv[1], "--test-help")) {
32 printUsage("test-functional");
33 return 0;
34 }
35
36 ::testing::InitGoogleTest(&argc, argv);
37 ::std::cerr << "Initialize OpenCL and clblas..." << ::std::endl;
38 base = ::clMath::BlasBase::getInstance();
39 if (base == NULL) {
40 ::std::cerr << "Fatal error, OpenCL or clblas initialization failed! "
41 "Leaving the test." << ::std::endl;
42 return -1;
43 }
44
45 if (argc != 1) {
46 params.optFlags = NO_FLAGS;
47 params.devType = CL_DEVICE_TYPE_GPU;
48 params.devName = NULL;
49 if (parseBlasCmdLineArgs(argc, argv, ¶ms) != 0) {
50 printUsage(argv[0]);
51 return 1;
52 }
53 if (params.optFlags & SET_SEED) {
54 base->setSeed(params.seed);
55 }
56 if (params.optFlags & SET_ALPHA) {
57 base->setAlpha(params.alpha);
58 }
59 if (params.optFlags & SET_BETA) {
60 base->setBeta(params.beta);
61 }
62 if (params.optFlags & SET_M) {
63 base->setM(params.M);
64 }
65 if (params.optFlags & SET_N) {
66 base->setN(params.N);
67 }
68 if (params.optFlags & SET_K) {
69 base->setK(params.K);
70 }
71 if (params.optFlags & SET_INCX) {
72 base->setIncX(params.incx);
73 }
74 if (params.optFlags & SET_INCY) {
75 base->setIncY(params.incy);
76 }
77 if (params.optFlags & SET_DEVICE_TYPE) {
78 if (!base->setDeviceType(¶ms.devType, params.devName)) {
79 ::std::cerr << "Fatal error, OpenCL or clblas "
80 "initialization failed! Leaving the test." <<
81 ::std::endl;
82 return -1;
83 }
84 }
85 if (params.optFlags & SET_NUM_COMMAND_QUEUES) {
86 base->setNumCommandQueues(params.numCommandQueues);
87 }
88 }
89
90 parseEnv(¶ms);
91 if ((params.optFlags & SET_USE_IMAGES) &&
92 (params.devType != CL_DEVICE_TYPE_CPU)) {
93 base->setUseImages(params.useImages);
94 }
95
96 /* Use of image based buffers is deprecated
97 if (base->useImages()) {
98 if (base->addScratchImages()) {
99 std::cerr << "FATAL ERROR, CANNOT CREATE SCRATCH IMAGES!" << std::endl;
100 }
101 }
102 */
103
104 ret = RUN_ALL_TESTS();
105
106 if (base->useImages()) {
107 base->removeScratchImages();
108 }
109
110 return ret;
111 }
112