1 // The main caffeine test code. Your test cpp code should include this hpp
2 // to allow a main function to be compiled into the binary.
3 #ifndef CAFFEINE_TEST_TEST_CAFFEINE_MAIN_HPP_
4 #define CAFFEINE_TEST_TEST_CAFFEINE_MAIN_HPP_
6 #include <cstdlib>
7 #include <cstdio>
8 #include <iostream>
10 #include <cuda_runtime.h>
11 #include <glog/logging.h>
12 #include <gtest/gtest.h>
14 namespace caffeine {
16 cudaDeviceProp CAFFEINE_TEST_CUDA_PROP;
18 } // namespace caffeine
20 using namespace caffeine;
21 using namespace std;
23 int main(int argc, char** argv) {
24 ::testing::InitGoogleTest(&argc, argv);
25 ::google::InitGoogleLogging(argv[0]);
26 // Before starting testing, let's first print out a few cuda defice info.
27 int device;
28 cudaGetDeviceCount(&device);
29 cout << "Cuda number of devices: " << device << endl;
30 if (argc > 1) {
31 // Use the given device
32 device = atoi(argv[1]);
33 cudaSetDevice(device);
34 cout << "Setting to use device " << device << endl;
35 }
36 cudaGetDevice(&device);
37 cout << "Current device id: " << device << endl;
38 cudaGetDeviceProperties(&CAFFEINE_TEST_CUDA_PROP, device);
39 // invoke the test.
40 return RUN_ALL_TESTS();
41 }
43 #endif // CAFFEINE_TEST_TEST_CAFFEINE_MAIN_HPP_