1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647
|
/*
BLIS
An object-based framework for developing high-performance BLAS-like
libraries.
Copyright (C) 2014, The University of Texas at Austin
Copyright (C) 2018 - 2019, Advanced Micro Devices, Inc.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
- Neither the name(s) of the copyright holder(s) nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "blis.h"
void bli_cntx_clear( cntx_t* cntx )
{
// Fill the entire cntx_t structure with zeros.
memset( ( void* )cntx, 0, sizeof( cntx_t ) );
}
// -----------------------------------------------------------------------------
void bli_cntx_set_blkszs( ind_t method, dim_t n_bs, ... )
{
// This function can be called from the bli_cntx_init_*() function for
// a particular architecture if the kernel developer wishes to use
// non-default blocksizes. It should be called after
// bli_cntx_init_defaults() so that the context begins with default
// blocksizes across all datatypes.
/* Example prototypes:
void bli_cntx_set_blkszs
(
ind_t method = BLIS_NAT,
dim_t n_bs,
bszid_t bs0_id, blksz_t* blksz0, bszid_t bm0_id,
bszid_t bs1_id, blksz_t* blksz1, bszid_t bm1_id,
bszid_t bs2_id, blksz_t* blksz2, bszid_t bm2_id,
...
cntx_t* cntx
);
void bli_cntx_set_blkszs
(
ind_t method != BLIS_NAT,
dim_t n_bs,
bszid_t bs0_id, blksz_t* blksz0, bszid_t bm0_id, dim_t def_scalr0, dim_t max_scalr0,
bszid_t bs1_id, blksz_t* blksz1, bszid_t bm1_id, dim_t def_scalr1, dim_t max_scalr1,
bszid_t bs2_id, blksz_t* blksz2, bszid_t bm2_id, dim_t def_scalr2, dim_t max_scalr2,
...
cntx_t* cntx
);
*/
va_list args;
dim_t i;
err_t r_val;
// Allocate some temporary local arrays.
#ifdef BLIS_ENABLE_MEM_TRACING
printf( "bli_cntx_set_blkszs(): " );
#endif
bszid_t* bszids = bli_malloc_intl( n_bs * sizeof( bszid_t ), &r_val );
#ifdef BLIS_ENABLE_MEM_TRACING
printf( "bli_cntx_set_blkszs(): " );
#endif
blksz_t** blkszs = bli_malloc_intl( n_bs * sizeof( blksz_t* ), &r_val );
#ifdef BLIS_ENABLE_MEM_TRACING
printf( "bli_cntx_set_blkszs(): " );
#endif
bszid_t* bmults = bli_malloc_intl( n_bs * sizeof( bszid_t ), &r_val );
#ifdef BLIS_ENABLE_MEM_TRACING
printf( "bli_cntx_set_blkszs(): " );
#endif
double* dsclrs = bli_malloc_intl( n_bs * sizeof( double ), &r_val );
#ifdef BLIS_ENABLE_MEM_TRACING
printf( "bli_cntx_set_blkszs(): " );
#endif
double* msclrs = bli_malloc_intl( n_bs * sizeof( double ), &r_val );
// -- Begin variable argument section --
// Initialize variable argument environment.
va_start( args, n_bs );
// Handle native and induced method cases separately.
if ( method == BLIS_NAT )
{
// Process n_bs tuples.
for ( i = 0; i < n_bs; ++i )
{
// Here, we query the variable argument list for:
// - the bszid_t of the blocksize we're about to process,
// - the address of the blksz_t object,
// - the bszid_t of the multiple we need to associate with
// the blksz_t object.
bszid_t bs_id = ( bszid_t )va_arg( args, bszid_t );
blksz_t* blksz = ( blksz_t* )va_arg( args, blksz_t* );
bszid_t bm_id = ( bszid_t )va_arg( args, bszid_t );
// Store the values in our temporary arrays.
bszids[ i ] = bs_id;
blkszs[ i ] = blksz;
bmults[ i ] = bm_id;
}
}
else // if induced method execution was indicated
{
// Process n_bs tuples.
for ( i = 0; i < n_bs; ++i )
{
// Here, we query the variable argument list for:
// - the bszid_t of the blocksize we're about to process,
// - the address of the blksz_t object,
// - the bszid_t of the multiple we need to associate with
// the blksz_t object,
// - the scalars we wish to apply to the real blocksizes to
// come up with the induced complex blocksizes (for default
// and maximum blocksizes).
bszid_t bs_id = ( bszid_t )va_arg( args, bszid_t );
blksz_t* blksz = ( blksz_t* )va_arg( args, blksz_t* );
bszid_t bm_id = ( bszid_t )va_arg( args, bszid_t );
double dsclr = ( double )va_arg( args, double );
double msclr = ( double )va_arg( args, double );
// Store the values in our temporary arrays.
bszids[ i ] = bs_id;
blkszs[ i ] = blksz;
bmults[ i ] = bm_id;
dsclrs[ i ] = dsclr;
msclrs[ i ] = msclr;
}
}
// The last argument should be the context pointer.
cntx_t* cntx = ( cntx_t* )va_arg( args, cntx_t* );
// Shutdown variable argument environment and clean up stack.
va_end( args );
// -- End variable argument section --
// Save the execution type into the context.
bli_cntx_set_method( method, cntx );
// Query the context for the addresses of:
// - the blocksize object array
// - the blocksize multiple array
blksz_t* cntx_blkszs = bli_cntx_blkszs_buf( cntx );
bszid_t* cntx_bmults = bli_cntx_bmults_buf( cntx );
// Now that we have the context address, we want to copy the values
// from the temporary buffers into the corresponding buffers in the
// context. Notice that the blksz_t* pointers were saved, rather than
// the objects themselves, but we copy the contents of the objects
// when copying into the context.
// Handle native and induced method cases separately.
if ( method == BLIS_NAT )
{
// Process each blocksize id tuple provided.
for ( i = 0; i < n_bs; ++i )
{
// Read the current blocksize id, blksz_t* pointer, blocksize
// multiple id, and blocksize scalar.
bszid_t bs_id = bszids[ i ];
bszid_t bm_id = bmults[ i ];
blksz_t* blksz = blkszs[ i ];
blksz_t* cntx_blksz = &cntx_blkszs[ bs_id ];
// Copy the blksz_t object contents into the appropriate
// location within the context's blksz_t array. Do the same
// for the blocksize multiple id.
//cntx_blkszs[ bs_id ] = *blksz;
//bli_blksz_copy( blksz, cntx_blksz );
bli_blksz_copy_if_pos( blksz, cntx_blksz );
// Copy the blocksize multiple id into the context.
cntx_bmults[ bs_id ] = bm_id;
}
}
else
{
// Process each blocksize id tuple provided.
for ( i = 0; i < n_bs; ++i )
{
// Read the current blocksize id, blksz_t pointer, blocksize
// multiple id, and blocksize scalar.
bszid_t bs_id = bszids[ i ];
bszid_t bm_id = bmults[ i ];
double dsclr = dsclrs[ i ];
double msclr = msclrs[ i ];
blksz_t* blksz = blkszs[ i ];
blksz_t* cntx_blksz = &cntx_blkszs[ bs_id ];
// Copy the real domain values of the source blksz_t object into
// the context, duplicating into the complex domain fields.
bli_blksz_copy_dt( BLIS_FLOAT, blksz, BLIS_FLOAT, cntx_blksz );
bli_blksz_copy_dt( BLIS_DOUBLE, blksz, BLIS_DOUBLE, cntx_blksz );
bli_blksz_copy_dt( BLIS_FLOAT, blksz, BLIS_SCOMPLEX, cntx_blksz );
bli_blksz_copy_dt( BLIS_DOUBLE, blksz, BLIS_DCOMPLEX, cntx_blksz );
// If the default blocksize scalar is non-unit, we need to scale
// the complex domain default blocksizes.
if ( dsclr != 1.0 )
{
// Scale the complex domain default blocksize values in the
// blocksize object.
bli_blksz_scale_def( 1, ( dim_t )dsclr, BLIS_SCOMPLEX, cntx_blksz );
bli_blksz_scale_def( 1, ( dim_t )dsclr, BLIS_DCOMPLEX, cntx_blksz );
}
// Similarly, if the maximum blocksize scalar is non-unit, we need
// to scale the complex domain maximum blocksizes.
if ( msclr != 1.0 )
{
// Scale the complex domain maximum blocksize values in the
// blocksize object.
bli_blksz_scale_max( 1, ( dim_t )msclr, BLIS_SCOMPLEX, cntx_blksz );
bli_blksz_scale_max( 1, ( dim_t )msclr, BLIS_DCOMPLEX, cntx_blksz );
}
// Copy the blocksize multiple id into the context.
cntx_bmults[ bs_id ] = bm_id;
}
}
// Free the temporary local arrays.
#ifdef BLIS_ENABLE_MEM_TRACING
printf( "bli_cntx_set_blkszs(): " );
#endif
bli_free_intl( blkszs );
#ifdef BLIS_ENABLE_MEM_TRACING
printf( "bli_cntx_set_blkszs(): " );
#endif
bli_free_intl( bszids );
#ifdef BLIS_ENABLE_MEM_TRACING
printf( "bli_cntx_set_blkszs(): " );
#endif
bli_free_intl( bmults );
#ifdef BLIS_ENABLE_MEM_TRACING
printf( "bli_cntx_set_blkszs(): " );
#endif
bli_free_intl( dsclrs );
#ifdef BLIS_ENABLE_MEM_TRACING
printf( "bli_cntx_set_blkszs(): " );
#endif
bli_free_intl( msclrs );
}
// -----------------------------------------------------------------------------
void bli_cntx_set_ind_blkszs( ind_t method, num_t dt, dim_t n_bs, ... )
{
/* Example prototypes:
void bli_gks_cntx_set_ind_blkszs
(
ind_t method != BLIS_NAT,
num_t dt,
dim_t n_bs,
bszid_t bs0_id, dim_t def_scalr0, dim_t max_scalr0,
bszid_t bs1_id, dim_t def_scalr1, dim_t max_scalr1,
bszid_t bs2_id, dim_t def_scalr2, dim_t max_scalr2,
...
cntx_t* cntx
);
NOTE: This function modifies an existing context that is presumed
to have been initialized for native execution.
*/
va_list args;
dim_t i;
err_t r_val;
// Project the given datatype to the real domain. This will be used later on.
num_t dt_real = bli_dt_proj_to_real( dt );
// Return early if called with BLIS_NAT.
if ( method == BLIS_NAT ) return;
// Allocate some temporary local arrays.
#ifdef BLIS_ENABLE_MEM_TRACING
printf( "bli_cntx_set_ind_blkszs(): " );
#endif
bszid_t* bszids = bli_malloc_intl( n_bs * sizeof( bszid_t ), &r_val );
#ifdef BLIS_ENABLE_MEM_TRACING
printf( "bli_cntx_set_ind_blkszs(): " );
#endif
double* dsclrs = bli_malloc_intl( n_bs * sizeof( double ), &r_val );
#ifdef BLIS_ENABLE_MEM_TRACING
printf( "bli_cntx_set_ind_blkszs(): " );
#endif
double* msclrs = bli_malloc_intl( n_bs * sizeof( double ), &r_val );
// -- Begin variable argument section --
// Initialize variable argument environment.
va_start( args, n_bs );
{
// Process n_bs tuples.
for ( i = 0; i < n_bs; ++i )
{
// Here, we query the variable argument list for:
// - the bszid_t of the blocksize we're about to process,
// - the scalars we wish to apply to the real blocksizes to
// come up with the induced complex blocksizes (for default
// and maximum blocksizes).
bszid_t bs_id = ( bszid_t )va_arg( args, bszid_t );
double dsclr = ( double )va_arg( args, double );
double msclr = ( double )va_arg( args, double );
// Store the values in our temporary arrays.
bszids[ i ] = bs_id;
dsclrs[ i ] = dsclr;
msclrs[ i ] = msclr;
}
}
// The last argument should be the context pointer.
cntx_t* cntx = ( cntx_t* )va_arg( args, cntx_t* );
// Shutdown variable argument environment and clean up stack.
va_end( args );
// -- End variable argument section --
// Save the execution type into the context.
bli_cntx_set_method( method, cntx );
// Now that we have the context address, we want to copy the values
// from the temporary buffers into the corresponding buffers in the
// context.
{
// Process each blocksize id tuple provided.
for ( i = 0; i < n_bs; ++i )
{
// Read the current blocksize id, blocksize multiple id,
// and blocksize scalar.
bszid_t bs_id = bszids[ i ];
double dsclr = dsclrs[ i ];
double msclr = msclrs[ i ];
//blksz_t* cntx_blksz = &cntx_blkszs[ bs_id ];
// Query the context for the blksz_t object assoicated with the
// current blocksize id, and also query the object corresponding
// to the blocksize multiple.
blksz_t* cntx_blksz = bli_cntx_get_blksz( bs_id, cntx );
// Copy the real domain value of the blksz_t object into the
// corresponding complex domain slot of the same object.
bli_blksz_copy_dt( dt_real, cntx_blksz, dt, cntx_blksz );
// If the default blocksize scalar is non-unit, we need to scale
// the complex domain default blocksizes.
if ( dsclr != 1.0 )
{
// Scale the default blocksize value corresponding to the given
// datatype.
bli_blksz_scale_def( 1, ( dim_t )dsclr, dt, cntx_blksz );
}
// Similarly, if the maximum blocksize scalar is non-unit, we need
// to scale the complex domain maximum blocksizes.
if ( msclr != 1.0 )
{
// Scale the maximum blocksize value corresponding to the given
// datatype.
bli_blksz_scale_max( 1, ( dim_t )msclr, dt, cntx_blksz );
}
}
}
// Free the temporary local arrays.
#ifdef BLIS_ENABLE_MEM_TRACING
printf( "bli_cntx_set_ind_blkszs(): " );
#endif
bli_free_intl( bszids );
#ifdef BLIS_ENABLE_MEM_TRACING
printf( "bli_cntx_set_ind_blkszs(): " );
#endif
bli_free_intl( dsclrs );
#ifdef BLIS_ENABLE_MEM_TRACING
printf( "bli_cntx_set_ind_blkszs(): " );
#endif
bli_free_intl( msclrs );
}
// -----------------------------------------------------------------------------
void bli_cntx_set_l3_nat_ukrs( dim_t n_ukrs, ... )
{
// This function can be called from the bli_cntx_init_*() function for
// a particular architecture if the kernel developer wishes to use
// non-default level-3 microkernels. It should be called after
// bli_cntx_init_defaults() so that the context begins with default
// microkernels across all datatypes.
/* Example prototypes:
void bli_cntx_set_l3_nat_ukrs
(
dim_t n_ukrs,
l3ukr_t ukr0_id, num_t dt0, void_fp ukr0_fp, bool pref0,
l3ukr_t ukr1_id, num_t dt1, void_fp ukr1_fp, bool pref1,
l3ukr_t ukr2_id, num_t dt2, void_fp ukr2_fp, bool pref2,
...
cntx_t* cntx
);
*/
va_list args;
dim_t i;
err_t r_val;
// Allocate some temporary local arrays.
#ifdef BLIS_ENABLE_MEM_TRACING
printf( "bli_cntx_set_l3_nat_ukrs(): " );
#endif
l3ukr_t* ukr_ids = bli_malloc_intl( n_ukrs * sizeof( l3ukr_t ), &r_val );
#ifdef BLIS_ENABLE_MEM_TRACING
printf( "bli_cntx_set_l3_nat_ukrs(): " );
#endif
num_t* ukr_dts = bli_malloc_intl( n_ukrs * sizeof( num_t ), &r_val );
#ifdef BLIS_ENABLE_MEM_TRACING
printf( "bli_cntx_set_l3_nat_ukrs(): " );
#endif
void_fp* ukr_fps = bli_malloc_intl( n_ukrs * sizeof( void_fp ), &r_val );
#ifdef BLIS_ENABLE_MEM_TRACING
printf( "bli_cntx_set_l3_nat_ukrs(): " );
#endif
bool* ukr_prefs = bli_malloc_intl( n_ukrs * sizeof( bool ), &r_val );
// -- Begin variable argument section --
// Initialize variable argument environment.
va_start( args, n_ukrs );
// Process n_ukrs tuples.
for ( i = 0; i < n_ukrs; ++i )
{
// Here, we query the variable argument list for:
// - the l3ukr_t of the kernel we're about to process,
// - the datatype of the kernel,
// - the kernel function pointer, and
// - the kernel function storage preference
// that we need to store to the context.
// NOTE: Though bool_t is no longer used, the following comment is
// being kept for historical reasons.
// The type that we pass into the va_arg() macro for the ukr
// preference matters. Using 'bool_t' may cause breakage on 64-bit
// systems that define int as 32 bits and long int and pointers as
// 64 bits. The problem is that TRUE or FALSE are defined as 1 and
// 0, respectively, and when "passed" into the variadic function
// they come with no contextual typecast. Thus, default rules of
// argument promotion kick in to treat these integer literals as
// being of type int. Thus, we need to let va_arg() treat the TRUE
// or FALSE value as an int, even if we cast it to and store it
// within a bool_t afterwards.
const l3ukr_t ukr_id = ( l3ukr_t )va_arg( args, l3ukr_t );
const num_t ukr_dt = ( num_t )va_arg( args, num_t );
void_fp ukr_fp = ( void_fp )va_arg( args, void_fp );
const bool ukr_pref = ( bool )va_arg( args, int );
// Store the values in our temporary arrays.
ukr_ids[ i ] = ukr_id;
ukr_dts[ i ] = ukr_dt;
ukr_fps[ i ] = ukr_fp;
ukr_prefs[ i ] = ukr_pref;
}
// The last argument should be the context pointer.
cntx_t* cntx = ( cntx_t* )va_arg( args, cntx_t* );
// Shutdown variable argument environment and clean up stack.
va_end( args );
// -- End variable argument section --
// Query the context for the addresses of:
// - the l3 virtual ukernel func_t array
// - the l3 native ukernel func_t array
// - the l3 native ukernel preferences array
func_t* cntx_l3_vir_ukrs = bli_cntx_l3_vir_ukrs_buf( cntx );
func_t* cntx_l3_nat_ukrs = bli_cntx_l3_nat_ukrs_buf( cntx );
mbool_t* cntx_l3_nat_ukrs_prefs = bli_cntx_l3_nat_ukrs_prefs_buf( cntx );
// Now that we have the context address, we want to copy the values
// from the temporary buffers into the corresponding buffers in the
// context.
// Process each blocksize id tuple provided.
for ( i = 0; i < n_ukrs; ++i )
{
// Read the current ukernel id, ukernel datatype, ukernel function
// pointer, and ukernel preference.
const l3ukr_t ukr_id = ukr_ids[ i ];
const num_t ukr_dt = ukr_dts[ i ];
void_fp ukr_fp = ukr_fps[ i ];
const bool ukr_pref = ukr_prefs[ i ];
// Index into the func_t and mbool_t for the current kernel id
// being processed.
func_t* vukrs = &cntx_l3_vir_ukrs[ ukr_id ];
func_t* ukrs = &cntx_l3_nat_ukrs[ ukr_id ];
mbool_t* prefs = &cntx_l3_nat_ukrs_prefs[ ukr_id ];
// Store the ukernel function pointer and preference values into
// the context. Notice that we redundantly store the native
// ukernel address in both the native and virtual ukernel slots
// in the context. This is standard practice when creating a
// native context. (Induced method contexts will overwrite the
// virtual function pointer with the address of the appropriate
// virtual ukernel.)
bli_func_set_dt( ukr_fp, ukr_dt, vukrs );
bli_func_set_dt( ukr_fp, ukr_dt, ukrs );
bli_mbool_set_dt( ukr_pref, ukr_dt, prefs );
}
// Free the temporary local arrays.
#ifdef BLIS_ENABLE_MEM_TRACING
printf( "bli_cntx_set_l3_nat_ukrs(): " );
#endif
bli_free_intl( ukr_ids );
#ifdef BLIS_ENABLE_MEM_TRACING
printf( "bli_cntx_set_l3_nat_ukrs(): " );
#endif
bli_free_intl( ukr_dts );
#ifdef BLIS_ENABLE_MEM_TRACING
printf( "bli_cntx_set_l3_nat_ukrs(): " );
#endif
bli_free_intl( ukr_fps );
#ifdef BLIS_ENABLE_MEM_TRACING
printf( "bli_cntx_set_l3_nat_ukrs(): " );
#endif
bli_free_intl( ukr_prefs );
}
// -----------------------------------------------------------------------------
void bli_cntx_set_l3_vir_ukrs( dim_t n_ukrs, ... )
{
// This function can be called from the bli_cntx_init_*() function for
// a particular architecture if the kernel developer wishes to use
// non-default level-3 virtual microkernels. It should be called after
// bli_cntx_init_defaults() so that the context begins with default
// microkernels across all datatypes.
/* Example prototypes:
void bli_cntx_set_l3_vir_ukrs
(
dim_t n_ukrs,
l3ukr_t ukr0_id, num_t dt0, void_fp ukr0_fp,
l3ukr_t ukr1_id, num_t dt1, void_fp ukr1_fp,
l3ukr_t ukr2_id, num_t dt2, void_fp ukr2_fp,
...
cntx_t* cntx
);
*/
va_list args;
dim_t i;
err_t r_val;
// Allocate some temporary local arrays.
#ifdef BLIS_ENABLE_MEM_TRACING
printf( "bli_cntx_set_l3_vir_ukrs(): " );
#endif
l3ukr_t* ukr_ids = bli_malloc_intl( n_ukrs * sizeof( l3ukr_t ), &r_val );
#ifdef BLIS_ENABLE_MEM_TRACING
printf( "bli_cntx_set_l3_vir_ukrs(): " );
#endif
num_t* ukr_dts = bli_malloc_intl( n_ukrs * sizeof( num_t ), &r_val );
#ifdef BLIS_ENABLE_MEM_TRACING
printf( "bli_cntx_set_l3_vir_ukrs(): " );
#endif
void_fp* ukr_fps = bli_malloc_intl( n_ukrs * sizeof( void_fp ), &r_val );
// -- Begin variable argument section --
// Initialize variable argument environment.
va_start( args, n_ukrs );
// Process n_ukrs tuples.
for ( i = 0; i < n_ukrs; ++i )
{
// Here, we query the variable argument list for:
// - the l3ukr_t of the kernel we're about to process,
// - the datatype of the kernel, and
// - the kernel function pointer.
// that we need to store to the context.
const l3ukr_t ukr_id = ( l3ukr_t )va_arg( args, l3ukr_t );
const num_t ukr_dt = ( num_t )va_arg( args, num_t );
void_fp ukr_fp = ( void_fp )va_arg( args, void_fp );
// Store the values in our temporary arrays.
ukr_ids[ i ] = ukr_id;
ukr_dts[ i ] = ukr_dt;
ukr_fps[ i ] = ukr_fp;
}
// The last argument should be the context pointer.
cntx_t* cntx = ( cntx_t* )va_arg( args, cntx_t* );
// Shutdown variable argument environment and clean up stack.
va_end( args );
// -- End variable argument section --
// Query the context for the addresses of:
// - the l3 virtual ukernel func_t array
func_t* cntx_l3_vir_ukrs = bli_cntx_l3_vir_ukrs_buf( cntx );
// Now that we have the context address, we want to copy the values
// from the temporary buffers into the corresponding buffers in the
// context.
// Process each blocksize id tuple provided.
for ( i = 0; i < n_ukrs; ++i )
{
// Read the current ukernel id, ukernel datatype, ukernel function
// pointer, and ukernel preference.
const l3ukr_t ukr_id = ukr_ids[ i ];
const num_t ukr_dt = ukr_dts[ i ];
void_fp ukr_fp = ukr_fps[ i ];
// Index into the func_t and mbool_t for the current kernel id
// being processed.
func_t* vukrs = &cntx_l3_vir_ukrs[ ukr_id ];
// Store the ukernel function pointer and preference values into
// the context. Notice that we redundantly store the native
// ukernel address in both the native and virtual ukernel slots
// in the context. This is standard practice when creating a
// native context. (Induced method contexts will overwrite the
// virtual function pointer with the address of the appropriate
// virtual ukernel.)
bli_func_set_dt( ukr_fp, ukr_dt, vukrs );
}
// Free the temporary local arrays.
#ifdef BLIS_ENABLE_MEM_TRACING
printf( "bli_cntx_set_l3_vir_ukrs(): " );
#endif
bli_free_intl( ukr_ids );
#ifdef BLIS_ENABLE_MEM_TRACING
printf( "bli_cntx_set_l3_vir_ukrs(): " );
#endif
bli_free_intl( ukr_dts );
#ifdef BLIS_ENABLE_MEM_TRACING
printf( "bli_cntx_set_l3_vir_ukrs(): " );
#endif
bli_free_intl( ukr_fps );
}
// -----------------------------------------------------------------------------
void bli_cntx_set_l3_sup_thresh( dim_t n_thresh, ... )
{
// This function can be called from the bli_cntx_init_*() function for
// a particular architecture if the kernel developer wishes to use
// non-default thresholds for small/unpacked matrix handling. It should
// be called after bli_cntx_init_defaults() so that the context begins
// with default thresholds.
/* Example prototypes:
void bli_cntx_set_l3_sup_thresh
(
dim_t n_thresh,
threshid_t th0_id, blksz_t* blksz0,
threshid_t th1_id, blksz_t* blksz1,
...
cntx_t* cntx
);
*/
va_list args;
dim_t i;
err_t r_val;
// Allocate some temporary local arrays.
#ifdef BLIS_ENABLE_MEM_TRACING
printf( "bli_cntx_set_l3_sup_thresh(): " );
#endif
threshid_t* threshids = bli_malloc_intl( n_thresh * sizeof( threshid_t ), &r_val );
#ifdef BLIS_ENABLE_MEM_TRACING
printf( "bli_cntx_set_l3_sup_thresh(): " );
#endif
blksz_t** threshs = bli_malloc_intl( n_thresh * sizeof( blksz_t* ), &r_val );
// -- Begin variable argument section --
// Initialize variable argument environment.
va_start( args, n_thresh );
// Process n_thresh tuples.
for ( i = 0; i < n_thresh; ++i )
{
// Here, we query the variable argument list for:
// - the threshid_t of the threshold we're about to process,
// - the address of the blksz_t object,
threshid_t th_id = ( threshid_t )va_arg( args, threshid_t );
blksz_t* thresh = ( blksz_t* )va_arg( args, blksz_t* );
// Store the values in our temporary arrays.
threshids[ i ] = th_id;
threshs[ i ] = thresh;
}
// The last argument should be the context pointer.
cntx_t* cntx = ( cntx_t* )va_arg( args, cntx_t* );
// Shutdown variable argument environment and clean up stack.
va_end( args );
// -- End variable argument section --
// Query the context for the addresses of:
// - the threshold array
blksz_t* cntx_threshs = bli_cntx_l3_sup_thresh_buf( cntx );
// Now that we have the context address, we want to copy the values
// from the temporary buffers into the corresponding buffers in the
// context. Notice that the blksz_t* pointers were saved, rather than
// the objects themselves, but we copy the contents of the objects
// when copying into the context.
// Process each blocksize id tuple provided.
for ( i = 0; i < n_thresh; ++i )
{
// Read the current blocksize id, blksz_t* pointer, blocksize
// multiple id, and blocksize scalar.
threshid_t th_id = threshids[ i ];
blksz_t* thresh = threshs[ i ];
blksz_t* cntx_thresh = &cntx_threshs[ th_id ];
// Copy the blksz_t object contents into the appropriate
// location within the context's blksz_t array.
//cntx_threshs[ th_id ] = *thresh;
//bli_blksz_copy( thresh, cntx_thresh );
bli_blksz_copy_if_pos( thresh, cntx_thresh );
}
// Free the temporary local arrays.
#ifdef BLIS_ENABLE_MEM_TRACING
printf( "bli_cntx_set_l3_sup_thresh(): " );
#endif
bli_free_intl( threshs );
#ifdef BLIS_ENABLE_MEM_TRACING
printf( "bli_cntx_set_l3_sup_thresh(): " );
#endif
bli_free_intl( threshids );
}
// -----------------------------------------------------------------------------
void bli_cntx_set_l3_sup_handlers( dim_t n_ops, ... )
{
// This function can be called from the bli_cntx_init_*() function for
// a particular architecture if the kernel developer wishes to use
// non-default level-3 operation handler for small/unpacked matrices. It
// should be called after bli_cntx_init_defaults() so that the context
// begins with default sup handlers across all datatypes.
/* Example prototypes:
void bli_cntx_set_l3_sup_handlers
(
dim_t n_ops,
opid_t op0_id, void* handler0_fp,
opid_t op1_id, void* handler1_fp,
opid_t op2_id, void* handler2_fp,
...
cntx_t* cntx
);
*/
va_list args;
dim_t i;
err_t r_val;
// Allocate some temporary local arrays.
#ifdef BLIS_ENABLE_MEM_TRACING
printf( "bli_cntx_set_l3_sup_handlers(): " );
#endif
opid_t* op_ids = bli_malloc_intl( n_ops * sizeof( opid_t ), &r_val );
#ifdef BLIS_ENABLE_MEM_TRACING
printf( "bli_cntx_set_l3_sup_handlers(): " );
#endif
void** op_fps = bli_malloc_intl( n_ops * sizeof( void* ), &r_val );
// -- Begin variable argument section --
// Initialize variable argument environment.
va_start( args, n_ops );
// Process n_ukrs tuples.
for ( i = 0; i < n_ops; ++i )
{
// Here, we query the variable argument list for:
// - the opid_t of the operation we're about to process,
// - the sup handler function pointer
// that we need to store to the context.
const opid_t op_id = ( opid_t )va_arg( args, opid_t );
void* op_fp = ( void* )va_arg( args, void* );
// Store the values in our temporary arrays.
op_ids[ i ] = op_id;
op_fps[ i ] = op_fp;
}
// The last argument should be the context pointer.
cntx_t* cntx = ( cntx_t* )va_arg( args, cntx_t* );
// Shutdown variable argument environment and clean up stack.
va_end( args );
// -- End variable argument section --
// Query the context for the addresses of:
// - the l3 small/unpacked handlers array
void** cntx_l3_sup_handlers = bli_cntx_l3_sup_handlers_buf( cntx );
// Now that we have the context address, we want to copy the values
// from the temporary buffers into the corresponding buffers in the
// context.
// Process each operation id tuple provided.
for ( i = 0; i < n_ops; ++i )
{
// Read the current operation id and handler function pointer.
const opid_t op_id = op_ids[ i ];
void* op_fp = op_fps[ i ];
// Store the sup handler function pointer into the slot for the
// specified operation id.
cntx_l3_sup_handlers[ op_id ] = op_fp;
}
// Free the temporary local arrays.
#ifdef BLIS_ENABLE_MEM_TRACING
printf( "bli_cntx_set_l3_sup_handlers(): " );
#endif
bli_free_intl( op_ids );
#ifdef BLIS_ENABLE_MEM_TRACING
printf( "bli_cntx_set_l3_sup_handlers(): " );
#endif
bli_free_intl( op_fps );
}
// -----------------------------------------------------------------------------
void bli_cntx_set_l3_sup_blkszs( dim_t n_bs, ... )
{
// This function can be called from the bli_cntx_init_*() function for
// a particular architecture if the kernel developer wishes to use
// non-default l3 sup blocksizes. It should be called after
// bli_cntx_init_defaults() so that the context begins with default
// blocksizes across all datatypes.
/* Example prototypes:
void bli_cntx_set_blkszs
(
dim_t n_bs,
bszid_t bs0_id, blksz_t* blksz0,
bszid_t bs1_id, blksz_t* blksz1,
bszid_t bs2_id, blksz_t* blksz2,
...
cntx_t* cntx
);
*/
va_list args;
dim_t i;
err_t r_val;
// Allocate some temporary local arrays.
#ifdef BLIS_ENABLE_MEM_TRACING
printf( "bli_cntx_set_blkszs(): " );
#endif
bszid_t* bszids = bli_malloc_intl( n_bs * sizeof( bszid_t ), &r_val );
#ifdef BLIS_ENABLE_MEM_TRACING
printf( "bli_cntx_set_blkszs(): " );
#endif
blksz_t** blkszs = bli_malloc_intl( n_bs * sizeof( blksz_t* ), &r_val );
// -- Begin variable argument section --
// Initialize variable argument environment.
va_start( args, n_bs );
// Process n_bs tuples.
for ( i = 0; i < n_bs; ++i )
{
// Here, we query the variable argument list for:
// - the bszid_t of the blocksize we're about to process,
// - the address of the blksz_t object.
bszid_t bs_id = ( bszid_t )va_arg( args, bszid_t );
blksz_t* blksz = ( blksz_t* )va_arg( args, blksz_t* );
// Store the values in our temporary arrays.
bszids[ i ] = bs_id;
blkszs[ i ] = blksz;
}
// The last argument should be the context pointer.
cntx_t* cntx = ( cntx_t* )va_arg( args, cntx_t* );
// Shutdown variable argument environment and clean up stack.
va_end( args );
// -- End variable argument section --
// Query the context for the addresses of:
// - the blocksize object array
blksz_t* cntx_l3_sup_blkszs = bli_cntx_l3_sup_blkszs_buf( cntx );
// Now that we have the context address, we want to copy the values
// from the temporary buffers into the corresponding buffers in the
// context. Notice that the blksz_t* pointers were saved, rather than
// the objects themselves, but we copy the contents of the objects
// when copying into the context.
// Process each blocksize id tuple provided.
for ( i = 0; i < n_bs; ++i )
{
// Read the current blocksize id, blksz_t* pointer, blocksize
// multiple id, and blocksize scalar.
bszid_t bs_id = bszids[ i ];
blksz_t* blksz = blkszs[ i ];
blksz_t* cntx_l3_sup_blksz = &cntx_l3_sup_blkszs[ bs_id ];
// Copy the blksz_t object contents into the appropriate
// location within the context's blksz_t array.
//cntx_l3_sup_blkszs[ bs_id ] = *blksz;
//bli_blksz_copy( blksz, cntx_l3_sup_blksz );
bli_blksz_copy_if_pos( blksz, cntx_l3_sup_blksz );
}
// Free the temporary local arrays.
#ifdef BLIS_ENABLE_MEM_TRACING
printf( "bli_cntx_set_blkszs(): " );
#endif
bli_free_intl( blkszs );
#ifdef BLIS_ENABLE_MEM_TRACING
printf( "bli_cntx_set_blkszs(): " );
#endif
bli_free_intl( bszids );
}
// -----------------------------------------------------------------------------
void bli_cntx_set_l3_sup_kers( dim_t n_ukrs, ... )
{
// This function can be called from the bli_cntx_init_*() function for
// a particular architecture if the kernel developer wishes to use
// non-default level-3 microkernels for small/unpacked matrices. It
// should be called after bli_cntx_init_defaults() so that the context
// begins with default sup micro/millikernels across all datatypes.
/* Example prototypes:
void bli_cntx_set_l3_sup_kers
(
dim_t n_ukrs,
stor3_t stor_id0, num_t dt0, void* ukr0_fp, bool pref0,
stor3_t stor_id1, num_t dt1, void* ukr1_fp, bool pref1,
stor3_t stor_id2, num_t dt2, void* ukr2_fp, bool pref2,
...
cntx_t* cntx
);
*/
va_list args;
dim_t i;
err_t r_val;
// Allocate some temporary local arrays.
#ifdef BLIS_ENABLE_MEM_TRACING
printf( "bli_cntx_set_l3_sup_kers(): " );
#endif
stor3_t* st3_ids = bli_malloc_intl( n_ukrs * sizeof( stor3_t ), &r_val );
#ifdef BLIS_ENABLE_MEM_TRACING
printf( "bli_cntx_set_l3_sup_kers(): " );
#endif
num_t* ukr_dts = bli_malloc_intl( n_ukrs * sizeof( num_t ), &r_val );
#ifdef BLIS_ENABLE_MEM_TRACING
printf( "bli_cntx_set_l3_sup_kers(): " );
#endif
void** ukr_fps = bli_malloc_intl( n_ukrs * sizeof( void* ), &r_val );
#ifdef BLIS_ENABLE_MEM_TRACING
printf( "bli_cntx_set_l3_sup_kers(): " );
#endif
bool* ukr_prefs = bli_malloc_intl( n_ukrs * sizeof( bool ), &r_val );
// -- Begin variable argument section --
// Initialize variable argument environment.
va_start( args, n_ukrs );
// Process n_ukrs tuples.
for ( i = 0; i < n_ukrs; ++i )
{
// Here, we query the variable argument list for:
// - the stor3_t storage case being assigned to the kernel we're
// about to process,
// - the datatype of the kernel,
// - the kernel function pointer, and
// - the kernel function storage preference
// that we need to store to the context.
const stor3_t st3_id = ( stor3_t )va_arg( args, stor3_t );
const num_t ukr_dt = ( num_t )va_arg( args, num_t );
void* ukr_fp = ( void* )va_arg( args, void* );
const bool ukr_pref = ( bool )va_arg( args, int );
// Store the values in our temporary arrays.
st3_ids[ i ] = st3_id;
ukr_dts[ i ] = ukr_dt;
ukr_fps[ i ] = ukr_fp;
ukr_prefs[ i ] = ukr_pref;
}
// The last argument should be the context pointer.
cntx_t* cntx = ( cntx_t* )va_arg( args, cntx_t* );
// Shutdown variable argument environment and clean up stack.
va_end( args );
// -- End variable argument section --
// Query the context for the addresses of:
// - the l3 small/unpacked ukernel func_t array
// - the l3 small/unpacked ukernel preferences array
func_t* cntx_l3_sup_kers = bli_cntx_l3_sup_kers_buf( cntx );
mbool_t* cntx_l3_sup_kers_prefs = bli_cntx_l3_sup_kers_prefs_buf( cntx );
// Now that we have the context address, we want to copy the values
// from the temporary buffers into the corresponding buffers in the
// context.
#if 0
dim_t sup_map[ BLIS_NUM_LEVEL3_SUP_UKRS ][2];
// Create the small/unpacked ukernel mappings:
// - rv -> rrr 0, rcr 2
// - rg -> rrc 1, rcc 3
// - cv -> ccr 6, ccc 7
// - cg -> crr 4, crc 5
// - rd -> rrc 1
// - cd -> crc 5
// - rc -> rcc 3
// - cr -> crr 4
// - gx -> xxx 8
// NOTE: We only need to set one slot in the context l3_sup_kers array
// for the general-stride/generic ukernel type, but since the loop below
// needs to be set up to set two slots to accommodate the RV, RG, CV, and
// CG, ukernel types, we will just be okay with the GX ukernel being set
// redundantly. (The RD, CD, CR, and RC ukernel types are set redundantly
// for the same reason.)
sup_map[ BLIS_GEMMSUP_RV_UKR ][0] = BLIS_RRR;
sup_map[ BLIS_GEMMSUP_RV_UKR ][1] = BLIS_RCR;
sup_map[ BLIS_GEMMSUP_RG_UKR ][0] = BLIS_RRC;
sup_map[ BLIS_GEMMSUP_RG_UKR ][1] = BLIS_RCC;
sup_map[ BLIS_GEMMSUP_CV_UKR ][0] = BLIS_CCR;
sup_map[ BLIS_GEMMSUP_CV_UKR ][1] = BLIS_CCC;
sup_map[ BLIS_GEMMSUP_CG_UKR ][0] = BLIS_CRR;
sup_map[ BLIS_GEMMSUP_CG_UKR ][1] = BLIS_CRC;
sup_map[ BLIS_GEMMSUP_RD_UKR ][0] = BLIS_RRC;
sup_map[ BLIS_GEMMSUP_RD_UKR ][1] = BLIS_RRC;
sup_map[ BLIS_GEMMSUP_CD_UKR ][0] = BLIS_CRC;
sup_map[ BLIS_GEMMSUP_CD_UKR ][1] = BLIS_CRC;
sup_map[ BLIS_GEMMSUP_RC_UKR ][0] = BLIS_RCC;
sup_map[ BLIS_GEMMSUP_RC_UKR ][1] = BLIS_RCC;
sup_map[ BLIS_GEMMSUP_CR_UKR ][0] = BLIS_CRR;
sup_map[ BLIS_GEMMSUP_CR_UKR ][1] = BLIS_CRR;
sup_map[ BLIS_GEMMSUP_GX_UKR ][0] = BLIS_XXX;
sup_map[ BLIS_GEMMSUP_GX_UKR ][1] = BLIS_XXX;
#endif
// Process each blocksize id tuple provided.
for ( i = 0; i < n_ukrs; ++i )
{
// Read the current stor3_t id, ukernel datatype, ukernel function
// pointer, and ukernel preference.
const stor3_t st3_id = st3_ids[ i ];
const num_t ukr_dt = ukr_dts[ i ];
void* ukr_fp = ukr_fps[ i ];
const bool ukr_pref = ukr_prefs[ i ];
// Index to the func_t and mbool_t for the current stor3_t id
// being processed.
func_t* ukrs = &cntx_l3_sup_kers[ st3_id ];
mbool_t* prefs = &cntx_l3_sup_kers_prefs[ st3_id ];
// Store the ukernel function pointer and preference values into
// the stor3_t location in the context.
bli_func_set_dt( ukr_fp, ukr_dt, ukrs );
bli_mbool_set_dt( ukr_pref, ukr_dt, prefs );
}
// Free the temporary local arrays.
#ifdef BLIS_ENABLE_MEM_TRACING
printf( "bli_cntx_set_l3_sup_kers(): " );
#endif
bli_free_intl( st3_ids );
#ifdef BLIS_ENABLE_MEM_TRACING
printf( "bli_cntx_set_l3_sup_kers(): " );
#endif
bli_free_intl( ukr_dts );
#ifdef BLIS_ENABLE_MEM_TRACING
printf( "bli_cntx_set_l3_sup_kers(): " );
#endif
bli_free_intl( ukr_fps );
#ifdef BLIS_ENABLE_MEM_TRACING
printf( "bli_cntx_set_l3_sup_kers(): " );
#endif
bli_free_intl( ukr_prefs );
}
// -----------------------------------------------------------------------------
void bli_cntx_set_l1f_kers( dim_t n_kers, ... )
{
// This function can be called from the bli_cntx_init_*() function for
// a particular architecture if the kernel developer wishes to use
// non-default level-1f kernels. It should be called after
// bli_cntx_init_defaults() so that the context begins with default l1f
// kernels across all datatypes.
/* Example prototypes:
void bli_cntx_set_l1f_kers
(
dim_t n_ukrs,
l1fkr_t ker0_id, num_t ker0_dt, void_fp ker0_fp,
l1fkr_t ker1_id, num_t ker1_dt, void_fp ker1_fp,
l1fkr_t ker2_id, num_t ker2_dt, void_fp ker2_fp,
...
cntx_t* cntx
);
*/
va_list args;
dim_t i;
err_t r_val;
// Allocate some temporary local arrays.
#ifdef BLIS_ENABLE_MEM_TRACING
printf( "bli_cntx_set_l1f_kers(): " );
#endif
l1fkr_t* ker_ids = bli_malloc_intl( n_kers * sizeof( l1fkr_t ), &r_val );
#ifdef BLIS_ENABLE_MEM_TRACING
printf( "bli_cntx_set_l1f_kers(): " );
#endif
num_t* ker_dts = bli_malloc_intl( n_kers * sizeof( num_t ), &r_val );
#ifdef BLIS_ENABLE_MEM_TRACING
printf( "bli_cntx_set_l1f_kers(): " );
#endif
void_fp* ker_fps = bli_malloc_intl( n_kers * sizeof( void_fp ), &r_val );
// -- Begin variable argument section --
// Initialize variable argument environment.
va_start( args, n_kers );
// Process n_kers tuples.
for ( i = 0; i < n_kers; ++i )
{
// Here, we query the variable argument list for:
// - the l1fkr_t of the kernel we're about to process,
// - the datatype of the kernel, and
// - the kernel function pointer
// that we need to store to the context.
const l1fkr_t ker_id = ( l1fkr_t )va_arg( args, l1fkr_t );
const num_t ker_dt = ( num_t )va_arg( args, num_t );
void_fp ker_fp = ( void_fp )va_arg( args, void_fp );
// Store the values in our temporary arrays.
ker_ids[ i ] = ker_id;
ker_dts[ i ] = ker_dt;
ker_fps[ i ] = ker_fp;
}
// The last argument should be the context pointer.
cntx_t* cntx = ( cntx_t* )va_arg( args, cntx_t* );
// Shutdown variable argument environment and clean up stack.
va_end( args );
// -- End variable argument section --
// Query the context for the address of:
// - the level-1f kernels func_t array
func_t* cntx_l1f_kers = bli_cntx_l1f_kers_buf( cntx );
// Now that we have the context address, we want to copy the values
// from the temporary buffers into the corresponding buffers in the
// context.
// Process each blocksize id tuple provided.
for ( i = 0; i < n_kers; ++i )
{
// Read the current kernel id, kernel datatype, and kernel function
// pointer.
const l1fkr_t ker_id = ker_ids[ i ];
const num_t ker_dt = ker_dts[ i ];
void_fp ker_fp = ker_fps[ i ];
// Index into the func_t and mbool_t for the current kernel id
// being processed.
func_t* kers = &cntx_l1f_kers[ ker_id ];
// Store the ukernel function pointer and preference values into
// the context.
bli_func_set_dt( ker_fp, ker_dt, kers );
}
// Free the temporary local arrays.
#ifdef BLIS_ENABLE_MEM_TRACING
printf( "bli_cntx_set_l1f_kers(): " );
#endif
bli_free_intl( ker_ids );
#ifdef BLIS_ENABLE_MEM_TRACING
printf( "bli_cntx_set_l1f_kers(): " );
#endif
bli_free_intl( ker_dts );
#ifdef BLIS_ENABLE_MEM_TRACING
printf( "bli_cntx_set_l1f_kers(): " );
#endif
bli_free_intl( ker_fps );
}
// -----------------------------------------------------------------------------
void bli_cntx_set_l1v_kers( dim_t n_kers, ... )
{
// This function can be called from the bli_cntx_init_*() function for
// a particular architecture if the kernel developer wishes to use
// non-default level-1v kernels. It should be called after
// bli_cntx_init_defaults() so that the context begins with default l1v
// kernels across all datatypes.
/* Example prototypes:
void bli_cntx_set_l1v_kers
(
dim_t n_ukrs,
l1vkr_t ker0_id, num_t ker0_dt, void_fp ker0_fp,
l1vkr_t ker1_id, num_t ker1_dt, void_fp ker1_fp,
l1vkr_t ker2_id, num_t ker2_dt, void_fp ker2_fp,
...
cntx_t* cntx
);
*/
va_list args;
dim_t i;
err_t r_val;
// Allocate some temporary local arrays.
#ifdef BLIS_ENABLE_MEM_TRACING
printf( "bli_cntx_set_l1v_kers(): " );
#endif
l1vkr_t* ker_ids = bli_malloc_intl( n_kers * sizeof( l1vkr_t ), &r_val );
#ifdef BLIS_ENABLE_MEM_TRACING
printf( "bli_cntx_set_l1v_kers(): " );
#endif
num_t* ker_dts = bli_malloc_intl( n_kers * sizeof( num_t ), &r_val );
#ifdef BLIS_ENABLE_MEM_TRACING
printf( "bli_cntx_set_l1v_kers(): " );
#endif
void_fp* ker_fps = bli_malloc_intl( n_kers * sizeof( void_fp ), &r_val );
// -- Begin variable argument section --
// Initialize variable argument environment.
va_start( args, n_kers );
// Process n_kers tuples.
for ( i = 0; i < n_kers; ++i )
{
// Here, we query the variable argument list for:
// - the l1vkr_t of the kernel we're about to process,
// - the datatype of the kernel, and
// - the kernel function pointer
// that we need to store to the context.
const l1vkr_t ker_id = ( l1vkr_t )va_arg( args, l1vkr_t );
const num_t ker_dt = ( num_t )va_arg( args, num_t );
void_fp ker_fp = ( void_fp )va_arg( args, void_fp );
// Store the values in our temporary arrays.
ker_ids[ i ] = ker_id;
ker_dts[ i ] = ker_dt;
ker_fps[ i ] = ker_fp;
}
// The last argument should be the context pointer.
cntx_t* cntx = ( cntx_t* )va_arg( args, cntx_t* );
// Shutdown variable argument environment and clean up stack.
va_end( args );
// -- End variable argument section --
// Query the context for the address of:
// - the level-1v kernels func_t array
func_t* cntx_l1v_kers = bli_cntx_l1v_kers_buf( cntx );
// Now that we have the context address, we want to copy the values
// from the temporary buffers into the corresponding buffers in the
// context.
// Process each blocksize id tuple provided.
for ( i = 0; i < n_kers; ++i )
{
// Read the current kernel id, kernel datatype, and kernel function
// pointer.
const l1vkr_t ker_id = ker_ids[ i ];
const num_t ker_dt = ker_dts[ i ];
void_fp ker_fp = ker_fps[ i ];
// Index into the func_t and mbool_t for the current kernel id
// being processed.
func_t* kers = &cntx_l1v_kers[ ker_id ];
// Store the ukernel function pointer and preference values into
// the context.
bli_func_set_dt( ker_fp, ker_dt, kers );
}
// Free the temporary local arrays.
#ifdef BLIS_ENABLE_MEM_TRACING
printf( "bli_cntx_set_l1v_kers(): " );
#endif
bli_free_intl( ker_ids );
#ifdef BLIS_ENABLE_MEM_TRACING
printf( "bli_cntx_set_l1v_kers(): " );
#endif
bli_free_intl( ker_dts );
#ifdef BLIS_ENABLE_MEM_TRACING
printf( "bli_cntx_set_l1v_kers(): " );
#endif
bli_free_intl( ker_fps );
}
// -----------------------------------------------------------------------------
void bli_cntx_set_packm_kers( dim_t n_kers, ... )
{
// This function can be called from the bli_cntx_init_*() function for
// a particular architecture if the kernel developer wishes to use
// non-default packing kernels. It should be called after
// bli_cntx_init_defaults() so that the context begins with default packm
// kernels across all datatypes.
/* Example prototypes:
void bli_cntx_set_packm_kers
(
dim_t n_ukrs,
l1mkr_t ker0_id, num_t ker0_dt, void_fp ker0_fp,
l1mkr_t ker1_id, num_t ker1_dt, void_fp ker1_fp,
l1mkr_t ker2_id, num_t ker2_dt, void_fp ker2_fp,
...
cntx_t* cntx
);
*/
va_list args;
dim_t i;
err_t r_val;
// Allocate some temporary local arrays.
#ifdef BLIS_ENABLE_MEM_TRACING
printf( "bli_cntx_set_packm_kers(): " );
#endif
l1mkr_t* ker_ids = bli_malloc_intl( n_kers * sizeof( l1mkr_t ), &r_val );
#ifdef BLIS_ENABLE_MEM_TRACING
printf( "bli_cntx_set_packm_kers(): " );
#endif
num_t* ker_dts = bli_malloc_intl( n_kers * sizeof( num_t ), &r_val );
#ifdef BLIS_ENABLE_MEM_TRACING
printf( "bli_cntx_set_packm_kers(): " );
#endif
void_fp* ker_fps = bli_malloc_intl( n_kers * sizeof( void_fp ), &r_val );
// -- Begin variable argument section --
// Initialize variable argument environment.
va_start( args, n_kers );
// Process n_kers tuples.
for ( i = 0; i < n_kers; ++i )
{
// Here, we query the variable argument list for:
// - the l1mkr_t of the kernel we're about to process,
// - the datatype of the kernel, and
// - the kernel function pointer
// that we need to store to the context.
const l1mkr_t ker_id = ( l1mkr_t )va_arg( args, l1mkr_t );
const num_t ker_dt = ( num_t )va_arg( args, num_t );
void_fp ker_fp = ( void_fp )va_arg( args, void_fp );
// Store the values in our temporary arrays.
ker_ids[ i ] = ker_id;
ker_dts[ i ] = ker_dt;
ker_fps[ i ] = ker_fp;
}
// The last argument should be the context pointer.
cntx_t* cntx = ( cntx_t* )va_arg( args, cntx_t* );
// Shutdown variable argument environment and clean up stack.
va_end( args );
// -- End variable argument section --
// Query the context for the address of:
// - the packm kernels func_t array
func_t* cntx_packm_kers = bli_cntx_packm_kers_buf( cntx );
// Now that we have the context address, we want to copy the values
// from the temporary buffers into the corresponding buffers in the
// context.
// Process each blocksize id tuple provided.
for ( i = 0; i < n_kers; ++i )
{
// Read the current kernel id, kernel datatype, and kernel function
// pointer.
const l1mkr_t ker_id = ker_ids[ i ];
const num_t ker_dt = ker_dts[ i ];
void_fp ker_fp = ker_fps[ i ];
// Index into the func_t and mbool_t for the current kernel id
// being processed.
func_t* kers = &cntx_packm_kers[ ker_id ];
// Store the ukernel function pointer and preference values into
// the context.
bli_func_set_dt( ker_fp, ker_dt, kers );
}
// Free the temporary local arrays.
#ifdef BLIS_ENABLE_MEM_TRACING
printf( "bli_cntx_set_packm_kers(): " );
#endif
bli_free_intl( ker_ids );
#ifdef BLIS_ENABLE_MEM_TRACING
printf( "bli_cntx_set_packm_kers(): " );
#endif
bli_free_intl( ker_dts );
#ifdef BLIS_ENABLE_MEM_TRACING
printf( "bli_cntx_set_packm_kers(): " );
#endif
bli_free_intl( ker_fps );
}
// -----------------------------------------------------------------------------
void bli_cntx_print( cntx_t* cntx )
{
dim_t i;
// Print the values stored in the blksz_t objects.
printf( " s d c z\n" );
for ( i = 0; i < BLIS_NUM_BLKSZS; ++i )
{
printf( "blksz/mult %2lu: %13lu/%2lu %13lu/%2lu %13lu/%2lu %13lu/%2lu\n",
( unsigned long )i,
( unsigned long )bli_cntx_get_blksz_def_dt( BLIS_FLOAT, i, cntx ),
( unsigned long )bli_cntx_get_bmult_dt ( BLIS_FLOAT, i, cntx ),
( unsigned long )bli_cntx_get_blksz_def_dt( BLIS_DOUBLE, i, cntx ),
( unsigned long )bli_cntx_get_bmult_dt ( BLIS_DOUBLE, i, cntx ),
( unsigned long )bli_cntx_get_blksz_def_dt( BLIS_SCOMPLEX, i, cntx ),
( unsigned long )bli_cntx_get_bmult_dt ( BLIS_SCOMPLEX, i, cntx ),
( unsigned long )bli_cntx_get_blksz_def_dt( BLIS_DCOMPLEX, i, cntx ),
( unsigned long )bli_cntx_get_bmult_dt ( BLIS_DCOMPLEX, i, cntx )
);
}
for ( i = 0; i < BLIS_NUM_LEVEL3_UKRS; ++i )
{
func_t* ukr = bli_cntx_get_l3_vir_ukrs( i, cntx );
printf( "l3 vir ukr %2lu: %16p %16p %16p %16p\n",
( unsigned long )i,
bli_func_get_dt( BLIS_FLOAT, ukr ),
bli_func_get_dt( BLIS_DOUBLE, ukr ),
bli_func_get_dt( BLIS_SCOMPLEX, ukr ),
bli_func_get_dt( BLIS_DCOMPLEX, ukr )
);
}
for ( i = 0; i < BLIS_NUM_3OP_RC_COMBOS; ++i )
{
func_t* ukr = bli_cntx_get_l3_sup_kers( i, cntx );
printf( "l3 sup ukr %2lu: %16p %16p %16p %16p\n",
( unsigned long )i,
bli_func_get_dt( BLIS_FLOAT, ukr ),
bli_func_get_dt( BLIS_DOUBLE, ukr ),
bli_func_get_dt( BLIS_SCOMPLEX, ukr ),
bli_func_get_dt( BLIS_DCOMPLEX, ukr )
);
}
for ( i = 0; i < BLIS_NUM_LEVEL1F_KERS; ++i )
{
func_t* ker = bli_cntx_get_l1f_kers( i, cntx );
printf( "l1f ker %2lu: %16p %16p %16p %16p\n",
( unsigned long )i,
bli_func_get_dt( BLIS_FLOAT, ker ),
bli_func_get_dt( BLIS_DOUBLE, ker ),
bli_func_get_dt( BLIS_SCOMPLEX, ker ),
bli_func_get_dt( BLIS_DCOMPLEX, ker )
);
}
for ( i = 0; i < BLIS_NUM_LEVEL1V_KERS; ++i )
{
func_t* ker = bli_cntx_get_l1v_kers( i, cntx );
printf( "l1v ker %2lu: %16p %16p %16p %16p\n",
( unsigned long )i,
bli_func_get_dt( BLIS_FLOAT, ker ),
bli_func_get_dt( BLIS_DOUBLE, ker ),
bli_func_get_dt( BLIS_SCOMPLEX, ker ),
bli_func_get_dt( BLIS_DCOMPLEX, ker )
);
}
{
ind_t method = bli_cntx_method( cntx );
printf( "ind method : %lu\n", ( unsigned long )method );
}
}
|