Lift
Library of parallel computing primitives for GPUs and multi-core CPUs
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
entrypoint.cu
Go to the documentation of this file.
1 /*
2  * Lift
3  *
4  * Copyright (c) 2014-2015, NVIDIA CORPORATION
5  * Copyright (c) 2015-2016, Nuno Subtil <subtil@gmail.com>
6  * Copyright (c) 2015-2016, Roche Molecular Systems Inc.
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions are met:
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in the
15  * documentation and/or other materials provided with the distribution.
16  * * Neither the name of the copyright holders nor the names of its
17  * contributors may be used to endorse or promote products derived from
18  * this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
21  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE
24  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #include <lift/tests/harness.h>
33 
37 
38 namespace lift {
39 
40 // the current test object pointer
41 thread_local test *current_test = nullptr;
42 // master list of tests to run
43 // will be populated by external code
44 std::vector<test *> test_list = { };
45 
46 }
47 
48 using namespace lift;
49 
50 // debugging aid: set a breakpoint here to catch check failures
52 {
53 }
54 
55 int main(int argc, char **argv)
56 {
58  bool has_cuda;
59 
60  printf("Lift test harness\n");
61  printf("CPU: %s\n", cpu.get_name());
62 
63  std::vector<cuda_device_config> gpu_list;
64  std::string err;
65 
67  if (gpu_list.size() == 0)
68  {
69  has_cuda = false;
70  } else {
71  has_cuda = true;
72 
73  if (gpu_list.size() == 1)
74  {
75  printf("GPU: %s\n", gpu_list[0].device_name);
76  } else {
77  printf("GPU list:\n");
78  for(size_t i = 0; i < gpu_list.size(); i++)
79  {
80  printf("%lu: %s\n", i, gpu_list[i].device_name);
81  }
82  }
83  }
84  printf("\n");
85 
87  bool success = true;
88 
89  size_t tests_run = 0;
90  size_t tests_passed = 0;
91  size_t tests_failed = 0;
92 
93  printf("running tests:\n");
94  for(size_t i = 0; i < test_list.size(); i++)
95  {
96  if (test_list[i]->need_cuda && !has_cuda)
97  {
98  continue;
99  }
100 
101  printf(" %s... ", test_list[i]->name.c_str());
102  fflush(stdout);
103 
104  current_test = test_list[i];
105 
106  test_list[i]->setup();
107 
108  test_list[i]->test_passed = true;
109  test_list[i]->run();
110 
111  tests_run++;
112 
113  test_list[i]->teardown();
114 
115  if (!test_list[i]->test_passed)
116  {
117  printf("\n FAILED!\n\n");
118  success = false;
119  tests_failed++;
120  } else {
121  printf("passed\n");
122  tests_passed++;
123  }
124 
125  fflush(stdout);
126  }
127 
128  printf("\n%lu out of %lu tests run, %lu passed / %lu failed\n",
129  tests_run, test_list.size(),
130  tests_passed, tests_failed);
131 
132  return (success ? 0 : 1);
133 }
virtual const char * get_name(void) override
void debug_check_failure(void)
Definition: entrypoint.cu:51
The test object interface.
Definition: harness.h:42
thread_local test * current_test
Definition: entrypoint.cu:41
int main(int argc, char **argv)
Definition: entrypoint.cu:55
static bool enumerate_gpus(std::vector< cuda_device_config > &devices, std::string &error, const cuda_device_config &requirements=cuda_device_config())
std::vector< test * > test_list
Definition: entrypoint.cu:44
void generate_test_list(void)