1 /*
2  * Copyright (c) 2017-2020, NVIDIA CORPORATION. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * * Redistributions of source code must retain the above copyright
8  *   notice, this list of conditions and the following disclaimer.
9  * * Redistributions in binary form must reproduce the above copyright
10  *   notice, this list of conditions and the following disclaimer in the
11  *   documentation and/or other materials provided with the distribution.
12  * * Neither the name of NVIDIA CORPORATION nor the names of its
13  *   contributors may be used to endorse or promote products derived
14  *   from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
17  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
20  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
24  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 /*
30   Extended example for building on-the-fly kernels with C interface.
31   Simple examples demonstrating different ways to load source code
32     and call kernels.
33  */
34 
35 
36 #include "jitTestFactory.hpp"
37 
38 
main(int argc,char * argv[])39 int main(int argc, char* argv[]) {
40 #if __cplusplus >= 201103L
41 
42 #define TEST_RESULT(result) (result ? "PASSED" : "FAILED")
43 std::cout << "Running tests..."<<std::endl;
44 
45   std::cout<<" spdot_plus_times_ffd_non_uniform"<<std::endl;
46   bool test_spdot_plus_times_ffd_nu = test_spdotfactoryUM<float,float,double>(256, 32,120,"PLUS_TIMES");
47   std::cout << "test_spdotfactoryUM<float,float,double> non-uniform uncached:       "
48             << TEST_RESULT(test_spdot_plus_times_ffd_nu)
49             << std::endl;
50 
51   std::cout<<" spdot_plus_times_ffd_large_non_uniform"<<std::endl;
52   bool test_spdot_plus_times_ffd_lrg_nu = test_spdotfactoryUM<float,float,double>(4096, 256,256,"PLUS_TIMES");
53   std::cout << "test_spdotfactoryUM<float,float,double> non-uniform uncached:       "
54             << TEST_RESULT(test_spdot_plus_times_ffd_lrg_nu)
55             << std::endl;
56 
57   std::cout<<" spdot_plus_times_fff"<<std::endl;
58   bool test_spdot_plus_times_fff = test_spdotfactoryUM<float,float,float>(256, 32,32,"PLUS_TIMES");
59   std::cout << "test_spdotfactoryUM<float,float,float> uncached:       "
60             << TEST_RESULT(test_spdot_plus_times_fff)
61             << std::endl;
62 
63   std::cout<<" spdot_plus_times_ffd"<<std::endl;
64   bool test_spdot_plus_times_ffd = test_spdotfactoryUM<float,float,double>(256, 32,32,"PLUS_TIMES");
65   std::cout << "test_spdotfactoryUM<float,float,double> uncached:       "
66             << TEST_RESULT(test_spdot_plus_times_ffd)
67             << std::endl;
68 
69 
70   cudaSetDevice(0);
71   bool test_spdot_batch_ffff = test_spdot_batch_factoryUM<float, float, float, float>(5, 32, 128, 128, "PLUS_TIMES");
72   std::cout << "test_spdot_batchUM<float,float,float,float> uncached:       "
73             << TEST_RESULT(test_spdot_batch_ffff)
74             << std::endl;
75 
76   bool test_spdot_batch_iiii = test_spdot_batch_factoryUM<int, int, int, int>(5, 32, 128, 128, "PLUS_TIMES");
77   std::cout << "test_spdot_batchUM<int,int,int,int> uncached:       "
78             << TEST_RESULT(test_spdot_batch_iiii)
79             << std::endl;
80 
81   cudaSetDevice(1);
82 
83   bool test_spdot_batch_liii= test_spdot_batch_factoryUM<int64_t, int, int, int>(5, 32, 256, 128, "PLUS_TIMES");
84   std::cout << "test_spdot_batchUM<int64_t,int, int,int> uncached:       "
85             << TEST_RESULT(test_spdot_batch_liii)
86             << std::endl;
87 /*
88 
89 
90 
91   bool test_dot_min_plus_iil = test_dotfactoryUM<int,int,long>(4096,"MIN_PLUS");
92   std::cout << "test_dotfactoryUM<int,int,long> uncached:       "
93             << TEST_RESULT(test_dot_min_plus_iil)
94             << std::endl;
95 
96   bool test_dot_min_plus_ffd = test_dotfactoryUM<float,float,double>(4096,"MIN_PLUS");
97   std::cout << "test_dotfactoryUM<float,float,double> uncached:       "
98             << TEST_RESULT(test_dot_min_plus_ffd)
99             << std::endl;
100 
101   bool test_dot_plus_times_ffd = test_dotfactoryUM<float,float,double>(4096,"PLUS_TIMES");
102   std::cout << "test_dotfactoryUM<float,float,double> uncached:       "
103             << TEST_RESULT(test_dot_plus_times_ffd)
104             << std::endl;
105 
106   bool test_dot_plus_times_fii = test_dotfactoryUM<float,int,int>(4096,"PLUS_TIMES");
107   std::cout << "test_dotfactoryUM<float,int,int> uncached:       "
108             << TEST_RESULT(test_dot_plus_times_fii)
109             << std::endl;
110 
111   bool test_dot_plus_times_iil = test_dotfactoryUM<int,int,long>(4096,"PLUS_TIMES");
112   std::cout << "test_dotfactoryUM<int,int,long> uncached:       "
113             << TEST_RESULT(test_dot_plus_times_iil)
114             << std::endl;
115 
116   bool test_reducefactory_float_result = test_reducefactoryUM<float>(4096, "PLUS");
117   std::cout << "test_reducefactoryUM<float> uncached:       "
118             << TEST_RESULT(test_reducefactory_float_result)
119             << std::endl;
120 
121   bool test_reducefactory_double_plus_result = test_reducefactoryUM<double>(4096, "PLUS");
122   std::cout << "test_reducefactoryUM<double> uncached:       "
123             << TEST_RESULT(test_reducefactory_double_plus_result)
124             << std::endl;
125 
126   std::cout << "testing cached kernel" <<std::endl;
127   bool test2_reducefactory_double_plus_result = test_reducefactoryUM<double>(4096, "PLUS");
128   std::cout << "test_reducefactoryUM<double> cached:       "
129             << TEST_RESULT(test2_reducefactory_double_plus_result)
130             << std::endl;
131 
132   bool test_reducefactory_float_min_result = test_reducefactoryUM<float>(32,"MIN");
133   std::cout << "test_reducefactoryUM<float> MIN uncached:       "
134             << TEST_RESULT(test_reducefactory_float_min_result)
135             << std::endl;
136 
137   bool test_reducefactory_int_min_result = test_reducefactoryUM<int>(32,"MIN");
138   std::cout << "test_reducefactoryUM<int> MIN uncached:       "
139             << TEST_RESULT(test_reducefactory_int_min_result)
140             << std::endl;
141 
142   bool test_reducefactory_int_max_result = test_reducefactoryUM<int>(32,"MAX");
143   std::cout << "test_reducefactoryUM<int> MAX uncached:       "
144             << TEST_RESULT(test_reducefactory_int_max_result)
145             << std::endl;
146 
147   bool test_reducefactory_int_result = test_reducefactoryUM<int>(4096,"PLUS");
148   std::cout << "test_reducefactoryUM<int> PLUS uncached:       "
149             << TEST_RESULT(test_reducefactory_int_result)
150             << std::endl;
151 
152   bool test_reducefactory_int_cache_result =
153                 test_reducefactoryUM<int>(4096,"PLUS");
154   std::cout << "test_reducefactoryUM<int> PLUS cached:          "
155             << TEST_RESULT(test_reducefactory_int_cache_result)
156             << std::endl;
157 */
158   return 0;
159 
160 #else
161   std::cout << "Tests require building with C++14 support (make CXX14=1)"
162             << std::endl;
163   return 0;
164 #endif
165 }
166