okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
62db0bf10
main
1// src/core/amd_community_test.cpp - STRATA_AMD_COMMUNITY_TUNING turns each community-made AMD change off (no GPU needed). 2// 3// Built twice by CMake: once as the default build (EXPECT_DOT_BUILT=1) and once with STRATA_AMD_COMMUNITY_DOT_OFF defined 4// (EXPECT_DOT_BUILT=0), which is what cmake -DSTRATA_AMD_COMMUNITY_TUNING=OFF does. Run from the source directory. 5#include "strata/core/amd_community.hpp" 6#include "../prefill/rocblas_tuning.hpp" 7 8#include <cstdio> 9#include <cstdlib> 10#include <fstream> 11#include <sstream> 12#include <string> 13 14static int fails = 0 ; 15#define CHECK (c ) do { if (!(c)) { std::printf("FAIL line %d: %s\n", __LINE__, #c); ++fails; } } while (0) 16 17static void unset (const char * k ) { 18#if defined(_WIN32 ) 19_putenv_s (k ,"" ); 20#else 21unsetenv (k ); 22#endif 23} 24static void put (const char * k ,const char * v ) { 25#if defined(_WIN32 ) 26_putenv_s (k ,v ); 27#else 28setenv (k ,v ,1 ); 29#endif 30} 31 32int main () { 33namespace ac= strata::amd_community; 34const char * kSwitch = "STRATA_AMD_COMMUNITY_TUNING" ; 35 36// the switch: on by default, off for 0 / off / false / no, on for anything else 37unset (kSwitch ); 38CHECK (ac::tuning_on ()); 39put (kSwitch ,"1" ); 40CHECK (ac::tuning_on ()); 41for (const char * off : {"0" ,"off" ,"false" ,"no" }) { 42put (kSwitch ,off ); 43CHECK (!ac::tuning_on ()); 44 } 45 46// which tables are the community's: exactly the two named, only for gfx1030 (feature suffix allowed) 47CHECK (ac::is_community_rocblas_table ("gfx1030" ,"5.4.0.ad84daa81c" )); 48CHECK (ac::is_community_rocblas_table ("gfx1030:xnack-" ,"5.2.0.dabb6df2b98-dirty" )); 49CHECK (!ac::is_community_rocblas_table ("gfx1030" ,"5.6.0.8d1ae90e" ));// shipped before, not under the switch 50CHECK (!ac::is_community_rocblas_table ("gfx1031" ,"5.4.0.ad84daa81c" ));// another card 51CHECK (!ac::is_community_rocblas_table ("gfx1030" ,"5.2.0.dabb6df2b9" ));// AMD's Ubuntu build: not this table 52CHECK (!ac::is_community_rocblas_table ("gfx1201" ,"5.4.0.ad84daa81c" )); 53 54// rocBLAS tables: the switch off refuses every community table and nothing else 55unset (kSwitch ); 56for (const auto & t : ac::kRocblasTables )CHECK (ac::rocblas_table_allowed (t .arch ,t .version )); 57put (kSwitch ,"0" ); 58for (const auto & t : ac::kRocblasTables )CHECK (!ac::rocblas_table_allowed (t .arch ,t .version )); 59CHECK (ac::rocblas_table_allowed ("gfx1030" ,"5.6.0.8d1ae90e" )); 60CHECK (ac::rocblas_table_allowed ("gfx1201" ,"anything" )); 61 62// the shipped files are well-formed, name the arch and version of the list, and the loader takes each only for that pair 63for (const auto & t : ac::kRocblasTables ) { 64 std::string tag (t .version ); 65while (!tag .empty ()&& tag .back ()== '.' )tag .pop_back (); 66const std::string path = std::string ("tools/hip/" )+ t .arch + "-rocblas-" + tag + ".txt" ; 67 std::string err ; 68 strata::prefill::rocblas_tuning::Table ok ; 69CHECK (ok .load (path ,t .arch ,t .version ,err )); 70CHECK (ok .rows ().size ()== 112 ); 71 strata::prefill::rocblas_tuning::Table other_version ,other_arch ; 72CHECK (!other_version .load (path ,t .arch ,"5.6.0.8d1ae90e" ,err ));// a non-matching rocBLAS build just does not load 73CHECK (!other_arch .load (path ,"gfx1031" ,t .version ,err )); 74 } 75 76// the dot product (device code): the build option decides; the intrinsics header carries the guard 77CHECK (ac::dot4_gfx1010_built ()== (EXPECT_DOT_BUILT != 0 )); 78 { 79 std::ifstream in ("include/strata/hip_compat/intrinsics.hpp" ); 80 std::stringstream ss ; 81ss <<in .rdbuf (); 82const std::string text = ss .str (); 83CHECK (text .find ("defined(__gfx1010__) && !defined(STRATA_AMD_COMMUNITY_DOT_OFF)" )!= std::string::npos ); 84CHECK (text .find ("!defined(STRATA_GFX1012_PORTABLE_DOT)" )!= std::string::npos ); 85 } 86 87// #3073: the simt2 selector is the default of gfx103x only, and only with the switch on 88unset (kSwitch ); 89CHECK (ac::select_simt2_default ("gfx1030" )&& ac::select_simt2_default ("gfx1031:xnack-" )&& ac::select_simt2_default ("gfx1032" )); 90CHECK (!ac::select_simt2_default ("gfx1201" )&& !ac::select_simt2_default ("gfx1100" )&& !ac::select_simt2_default ("gfx906" )&& 91 !ac::select_simt2_default ("gfx1010" )&& !ac::select_simt2_default ("" )&& !ac::select_simt2_default (nullptr )); 92put (kSwitch ,"0" ); 93CHECK (!ac::select_simt2_default ("gfx1030" )); 94unset (kSwitch ); 95 96// the log line: only gfx1010 / gfx103x, and it says what the switch does 97unset (kSwitch ); 98CHECK (ac::startup_line ("gfx1201" ).empty ()); 99CHECK (ac::startup_line ("gfx1100" ).empty ()); 100CHECK (ac::startup_line ("gfx1012" ).empty ()); 101CHECK (ac::startup_line ("gfx1031" ).find ("simt2" )!= std::string::npos );// gfx1031: the selector default only 102CHECK (ac::startup_line ("gfx1030" ).find ("simt2" )!= std::string::npos ); 103CHECK (ac::startup_line ("" ).empty ()); 104CHECK (ac::startup_line (nullptr ).empty ()); 105CHECK (ac::startup_line ("gfx1030:xnack-" ).find ("on:" )!= std::string::npos ); 106CHECK (ac::startup_line ("gfx1010" ).find ("STRATA_AMD_COMMUNITY_TUNING=0" )!= std::string::npos ); 107put (kSwitch ,"0" ); 108CHECK (ac::startup_line ("gfx1030" ).find ("off:" )!= std::string::npos ); 109CHECK (ac::startup_line ("gfx1010" ).find ("rebuild" )!= std::string::npos || !ac::dot4_gfx1010_built ()); 110 111if (fails == 0 ) std::printf ("amd_community_test: OK\n" ); 112return fails == 0 ?0 :1 ; 113}