| [33534bb] | 1 | /*
|
|---|
| 2 | * Copyright (c) 2016, NVIDIA Corporation. All rights reserved.
|
|---|
| 3 | *
|
|---|
| 4 | * Please refer to the NVIDIA end user license agreement (EULA) associated
|
|---|
| 5 | * with this source code for terms and conditions that govern your use of
|
|---|
| 6 | * this software. Any use, reproduction, disclosure, or distribution of
|
|---|
| 7 | * this software and related documentation outside the terms of the EULA
|
|---|
| 8 | * is strictly prohibited.
|
|---|
| 9 | *
|
|---|
| 10 | */
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 | #include <stdio.h>
|
|---|
| 15 | #include <math.h>
|
|---|
| 16 |
|
|---|
| 17 | #ifdef __cplusplus
|
|---|
| 18 | extern "C" {
|
|---|
| 19 | #endif
|
|---|
| 20 |
|
|---|
| 21 | void
|
|---|
| 22 | check(int* res, int* exp, int n)
|
|---|
| 23 | {
|
|---|
| 24 | int i;
|
|---|
| 25 | int tests_passed = 0;
|
|---|
| 26 | int tests_failed = 0;
|
|---|
| 27 |
|
|---|
| 28 | for (i = 0; i < n; i++) {
|
|---|
| 29 | if (exp[i] == res[i]) {
|
|---|
| 30 | tests_passed ++;
|
|---|
| 31 | } else {
|
|---|
| 32 | tests_failed ++;
|
|---|
| 33 | if( tests_failed < 50 )
|
|---|
| 34 | printf(
|
|---|
| 35 | "test number %d FAILED. res %d(%08x) exp %d(%08x)\n",
|
|---|
| 36 | i+1,res[i], res[i], exp[i], exp[i] );
|
|---|
| 37 | }
|
|---|
| 38 | }
|
|---|
| 39 | if (tests_failed == 0) {
|
|---|
| 40 | printf("%3d tests completed. %d tests PASSED. %d tests failed.\n",
|
|---|
| 41 | n, tests_passed, tests_failed);
|
|---|
| 42 | } else {
|
|---|
| 43 | printf("%3d tests completed. %d tests passed. %d tests FAILED.\n",
|
|---|
| 44 | n, tests_passed, tests_failed);
|
|---|
| 45 | }
|
|---|
| 46 | }
|
|---|
| 47 |
|
|---|
| 48 | void
|
|---|
| 49 | check_(int* res, int* exp, int* np)
|
|---|
| 50 | {
|
|---|
| 51 | check(res, exp, *np);
|
|---|
| 52 | }
|
|---|
| 53 |
|
|---|
| 54 | void
|
|---|
| 55 | checkf(float* res, float* exp, int n)
|
|---|
| 56 | {
|
|---|
| 57 | int i;
|
|---|
| 58 | int tests_passed = 0;
|
|---|
| 59 | int tests_failed = 0;
|
|---|
| 60 |
|
|---|
| 61 | for (i = 0; i < n; i++) {
|
|---|
| 62 | if (exp[i] == res[i]) {
|
|---|
| 63 | tests_passed ++;
|
|---|
| 64 | } else {
|
|---|
| 65 | tests_failed ++;
|
|---|
| 66 | if( tests_failed < 50 )
|
|---|
| 67 | printf(
|
|---|
| 68 | "test number %d FAILED. res %g exp %g\n",
|
|---|
| 69 | i+1,res[i], exp[i]);
|
|---|
| 70 | }
|
|---|
| 71 | }
|
|---|
| 72 | if (tests_failed == 0) {
|
|---|
| 73 | printf("%3d tests completed. %d tests PASSED. %d tests failed.\n",
|
|---|
| 74 | n, tests_passed, tests_failed);
|
|---|
| 75 | } else {
|
|---|
| 76 | printf("%3d tests completed. %d tests passed. %d tests FAILED.\n",
|
|---|
| 77 | n, tests_passed, tests_failed);
|
|---|
| 78 | }
|
|---|
| 79 | }
|
|---|
| 80 |
|
|---|
| 81 | void
|
|---|
| 82 | checkf_(float* res, float* exp, int* np)
|
|---|
| 83 | {
|
|---|
| 84 | checkf(res, exp, *np);
|
|---|
| 85 | }
|
|---|
| 86 |
|
|---|
| 87 | void
|
|---|
| 88 | checkftol(float* res, float* exp, int n)
|
|---|
| 89 | {
|
|---|
| 90 | int i;
|
|---|
| 91 | int tests_passed = 0;
|
|---|
| 92 | int tests_failed = 0;
|
|---|
| 93 | float tol = 0.000001;
|
|---|
| 94 |
|
|---|
| 95 | for (i = 0; i < n; i++) {
|
|---|
| 96 | if (exp[i] == res[i]) {
|
|---|
| 97 | tests_passed ++;
|
|---|
| 98 | }else if( exp[i] != 0.0 && fabsf((exp[i]-res[i])/exp[i]) <= tol ){
|
|---|
| 99 | tests_passed ++;
|
|---|
| 100 | }else if( exp[i] == 0.0 && res[i] <= tol ){
|
|---|
| 101 | tests_passed ++;
|
|---|
| 102 | } else {
|
|---|
| 103 | tests_failed ++;
|
|---|
| 104 | if( tests_failed < 50 )
|
|---|
| 105 | printf(
|
|---|
| 106 | "test number %d FAILED. res %f exp %f\n",
|
|---|
| 107 | i+1,res[i], exp[i]);
|
|---|
| 108 | }
|
|---|
| 109 | }
|
|---|
| 110 | if (tests_failed == 0) {
|
|---|
| 111 | printf("%3d tests completed. %d tests PASSED. %d tests failed.\n",
|
|---|
| 112 | n, tests_passed, tests_failed);
|
|---|
| 113 | } else {
|
|---|
| 114 | printf("%3d tests completed. %d tests passed. %d tests FAILED.\n",
|
|---|
| 115 | n, tests_passed, tests_failed);
|
|---|
| 116 | }
|
|---|
| 117 | }
|
|---|
| 118 |
|
|---|
| 119 | void
|
|---|
| 120 | checkftol_(float* res, float* exp, int* np)
|
|---|
| 121 | {
|
|---|
| 122 | checkftol(res, exp, *np);
|
|---|
| 123 | }
|
|---|
| 124 |
|
|---|
| 125 | void
|
|---|
| 126 | checkftol5(float* res, float* exp, int n)
|
|---|
| 127 | {
|
|---|
| 128 | int i;
|
|---|
| 129 | int tests_passed = 0;
|
|---|
| 130 | int tests_failed = 0;
|
|---|
| 131 | float tol = 0.00002;
|
|---|
| 132 |
|
|---|
| 133 | for (i = 0; i < n; i++) {
|
|---|
| 134 | if (exp[i] == res[i]) {
|
|---|
| 135 | tests_passed ++;
|
|---|
| 136 | }else if( exp[i] != 0.0 && fabsf((exp[i]-res[i])/exp[i]) <= tol ){
|
|---|
| 137 | tests_passed ++;
|
|---|
| 138 | }else if( exp[i] == 0.0 && res[i] <= tol ){
|
|---|
| 139 | tests_passed ++;
|
|---|
| 140 | } else {
|
|---|
| 141 | tests_failed ++;
|
|---|
| 142 | if( tests_failed < 50 )
|
|---|
| 143 | printf(
|
|---|
| 144 | "test number %d FAILED. res %f exp %f\n",
|
|---|
| 145 | i+1,res[i], exp[i]);
|
|---|
| 146 | }
|
|---|
| 147 | }
|
|---|
| 148 | if (tests_failed == 0) {
|
|---|
| 149 | printf("%3d tests completed. %d tests PASSED. %d tests failed.\n",
|
|---|
| 150 | n, tests_passed, tests_failed);
|
|---|
| 151 | } else {
|
|---|
| 152 | printf("%3d tests completed. %d tests passed. %d tests FAILED.\n",
|
|---|
| 153 | n, tests_passed, tests_failed);
|
|---|
| 154 | }
|
|---|
| 155 | }
|
|---|
| 156 |
|
|---|
| 157 |
|
|---|
| 158 | void
|
|---|
| 159 | checkll(long long *res, long long *exp, int n)
|
|---|
| 160 | {
|
|---|
| 161 | int i;
|
|---|
| 162 | int tests_passed = 0;
|
|---|
| 163 | int tests_failed = 0;
|
|---|
| 164 |
|
|---|
| 165 | for (i = 0; i < n; i++) {
|
|---|
| 166 | if (exp[i] == res[i]) {
|
|---|
| 167 | tests_passed ++;
|
|---|
| 168 | } else {
|
|---|
| 169 | tests_failed ++;
|
|---|
| 170 | if( tests_failed < 50 )
|
|---|
| 171 | printf( "test number %d FAILED. res %lld(%0llx) exp %lld(%0llx)\n",
|
|---|
| 172 | i+1,res[i], res[i], exp[i], exp[i] );
|
|---|
| 173 | }
|
|---|
| 174 | }
|
|---|
| 175 | if (tests_failed == 0) {
|
|---|
| 176 | printf("%3d tests completed. %d tests PASSED. %d tests failed.\n",
|
|---|
| 177 | n, tests_passed, tests_failed);
|
|---|
| 178 | } else {
|
|---|
| 179 | printf("%3d tests completed. %d tests passed. %d tests FAILED.\n",
|
|---|
| 180 | n, tests_passed, tests_failed);
|
|---|
| 181 | }
|
|---|
| 182 | }
|
|---|
| 183 |
|
|---|
| 184 | void
|
|---|
| 185 | checkll_(long long *res, long long *exp, int *np)
|
|---|
| 186 | {
|
|---|
| 187 | checkll(res, exp, *np);
|
|---|
| 188 | }
|
|---|
| 189 |
|
|---|
| 190 | void
|
|---|
| 191 | checkd(double* res, double* exp, int n)
|
|---|
| 192 | {
|
|---|
| 193 | int i;
|
|---|
| 194 | int tests_passed = 0;
|
|---|
| 195 | int tests_failed = 0;
|
|---|
| 196 |
|
|---|
| 197 | for (i = 0; i < n; i++) {
|
|---|
| 198 | if (exp[i] == res[i])
|
|---|
| 199 | tests_passed ++;
|
|---|
| 200 | else {
|
|---|
| 201 | tests_failed ++;
|
|---|
| 202 | if( tests_failed < 50 )
|
|---|
| 203 | printf("test number %d FAILED. res %lg exp %lg\n",
|
|---|
| 204 | i+1, res[i], exp[i] );
|
|---|
| 205 | }
|
|---|
| 206 | }
|
|---|
| 207 | if (tests_failed == 0) {
|
|---|
| 208 | printf("%3d tests completed. %d tests PASSED. %d tests failed.\n",
|
|---|
| 209 | n, tests_passed, tests_failed);
|
|---|
| 210 | } else {
|
|---|
| 211 | printf("%3d tests completed. %d tests passed. %d tests FAILED.\n",
|
|---|
| 212 | n, tests_passed, tests_failed);
|
|---|
| 213 | }
|
|---|
| 214 | }
|
|---|
| 215 |
|
|---|
| 216 | void
|
|---|
| 217 | checkd_(double* res, double* exp, int* np)
|
|---|
| 218 | {
|
|---|
| 219 | checkd(res, exp, *np);
|
|---|
| 220 | }
|
|---|
| 221 |
|
|---|
| 222 | void
|
|---|
| 223 | checkdtol(double* res, double* exp, int n)
|
|---|
| 224 | {
|
|---|
| 225 | int i;
|
|---|
| 226 | int tests_passed = 0;
|
|---|
| 227 | int tests_failed = 0;
|
|---|
| 228 | double tol = 0.00000000002;
|
|---|
| 229 |
|
|---|
| 230 | for (i = 0; i < n; i++) {
|
|---|
| 231 | if (exp[i] == res[i]){
|
|---|
| 232 | tests_passed ++;
|
|---|
| 233 | }else if( exp[i] != 0.0 && ((exp[i]-res[i])/exp[i]) <= tol ){
|
|---|
| 234 | tests_passed ++;
|
|---|
| 235 | }else if( exp[i] == 0.0 && res[i] <= tol ){
|
|---|
| 236 | tests_passed ++;
|
|---|
| 237 | }else{
|
|---|
| 238 | tests_failed ++;
|
|---|
| 239 | if( tests_failed < 50 )
|
|---|
| 240 | printf(
|
|---|
| 241 | "test number %d FAILED. res %lg exp %lg\n",
|
|---|
| 242 | i+1,res[i], exp[i]);
|
|---|
| 243 | }
|
|---|
| 244 | }
|
|---|
| 245 | if (tests_failed == 0) {
|
|---|
| 246 | printf("%3d tests completed. %d tests PASSED. %d tests failed.\n",
|
|---|
| 247 | n, tests_passed, tests_failed);
|
|---|
| 248 | } else {
|
|---|
| 249 | printf("%3d tests completed. %d tests passed. %d tests FAILED.\n",
|
|---|
| 250 | n, tests_passed, tests_failed);
|
|---|
| 251 | }
|
|---|
| 252 | }
|
|---|
| 253 |
|
|---|
| 254 | void
|
|---|
| 255 | checkdtol_(double* res, double* exp, int* np)
|
|---|
| 256 | {
|
|---|
| 257 | checkdtol(res, exp, *np);
|
|---|
| 258 | }
|
|---|
| 259 |
|
|---|
| 260 | void
|
|---|
| 261 | fcpyf_(float *r, float f)
|
|---|
| 262 | {
|
|---|
| 263 | *r = f;
|
|---|
| 264 | }
|
|---|
| 265 |
|
|---|
| 266 | void
|
|---|
| 267 | fcpyf(float *r, float f)
|
|---|
| 268 | {
|
|---|
| 269 | fcpyf_(r, f);
|
|---|
| 270 | }
|
|---|
| 271 |
|
|---|
| 272 | void
|
|---|
| 273 | fcpyi_(int *r, int f)
|
|---|
| 274 | {
|
|---|
| 275 | *r = f;
|
|---|
| 276 | }
|
|---|
| 277 |
|
|---|
| 278 | void
|
|---|
| 279 | fcpyi(int *r, int f)
|
|---|
| 280 | {
|
|---|
| 281 | fcpyi_(r, f);
|
|---|
| 282 | }
|
|---|
| 283 |
|
|---|
| 284 | #if defined(WINNT) || defined(WIN32)
|
|---|
| 285 | void
|
|---|
| 286 | __stdcall CHECK(int* res, int* exp, int* np)
|
|---|
| 287 | {
|
|---|
| 288 | check_(res, exp, np);
|
|---|
| 289 | }
|
|---|
| 290 |
|
|---|
| 291 | void
|
|---|
| 292 | __stdcall CHECKD( double* res, double* exp, int* np)
|
|---|
| 293 | {
|
|---|
| 294 | checkd_(res, exp, np);
|
|---|
| 295 | }
|
|---|
| 296 |
|
|---|
| 297 | void
|
|---|
| 298 | __stdcall CHECKF( double* res, double* exp, int* np)
|
|---|
| 299 | {
|
|---|
| 300 | checkf_(res, exp, np);
|
|---|
| 301 | }
|
|---|
| 302 |
|
|---|
| 303 | void
|
|---|
| 304 | __stdcall CHECKFTOL( double* res, double* exp, int* np)
|
|---|
| 305 | {
|
|---|
| 306 | checkftol_(res, exp, np);
|
|---|
| 307 | }
|
|---|
| 308 |
|
|---|
| 309 | void
|
|---|
| 310 | __stdcall CHECKDTOL( double* res, double* exp, int* np)
|
|---|
| 311 | {
|
|---|
| 312 | checkdtol_(res, exp, np);
|
|---|
| 313 | }
|
|---|
| 314 |
|
|---|
| 315 | void
|
|---|
| 316 | __stdcall CHECKLL(long long *res, long long *exp, int *np)
|
|---|
| 317 | {
|
|---|
| 318 | checkll_(res, exp, np);
|
|---|
| 319 | }
|
|---|
| 320 |
|
|---|
| 321 | void
|
|---|
| 322 | __stdcall FCPYF(float *r, float f)
|
|---|
| 323 | {
|
|---|
| 324 | fcpyf_(r, f);
|
|---|
| 325 | }
|
|---|
| 326 |
|
|---|
| 327 | void
|
|---|
| 328 | __stdcall FCPYI(int *r, int f)
|
|---|
| 329 | {
|
|---|
| 330 | fcpyi_(r, f);
|
|---|
| 331 | }
|
|---|
| 332 | #endif
|
|---|
| 333 | #ifdef __cplusplus
|
|---|
| 334 | }
|
|---|
| 335 | #endif
|
|---|
| 336 |
|
|---|