From 7b4ca1e0b98965ecf139092253f11eee107fc926 Mon Sep 17 00:00:00 2001 From: Artur Wojcik Date: Wed, 13 Dec 2023 22:52:44 +0100 Subject: [PATCH] rewrite generate_offload_arch script in Python The change is required to make the script run on Windows. There is no bash shell on Windows. The alternatives (like MSYS2, Cygwin, etc.) pollute the build environment with GNU tools and libraries, which are picked up automatically, making native Windows build impossible. --- llvm/lib/OffloadArch/CMakeLists.txt | 6 +- llvm/lib/OffloadArch/generated_offload_arch.h | 462 ------------------ .../make_generated_offload_arch_h.py | 190 +++++++ .../make_generated_offload_arch_h.sh | 201 -------- 4 files changed, 194 insertions(+), 665 deletions(-) delete mode 100644 llvm/lib/OffloadArch/generated_offload_arch.h create mode 100644 llvm/lib/OffloadArch/make_generated_offload_arch_h.py delete mode 100755 llvm/lib/OffloadArch/make_generated_offload_arch_h.sh diff --git a/llvm/lib/OffloadArch/CMakeLists.txt b/llvm/lib/OffloadArch/CMakeLists.txt index e30d31ca15b589..a1701389871486 100644 --- a/llvm/lib/OffloadArch/CMakeLists.txt +++ b/llvm/lib/OffloadArch/CMakeLists.txt @@ -1,8 +1,10 @@ +find_package(Python3 REQUIRED COMPONENTS Interpreter) + add_custom_command( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/generated_offload_arch.h - COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/make_generated_offload_arch_h.sh ${CMAKE_CURRENT_SOURCE_DIR} + COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/make_generated_offload_arch_h.py ${CMAKE_CURRENT_SOURCE_DIR} DEPENDS - ${CMAKE_CURRENT_SOURCE_DIR}/make_generated_offload_arch_h.sh + ${CMAKE_CURRENT_SOURCE_DIR}/make_generated_offload_arch_h.py ${CMAKE_CURRENT_SOURCE_DIR}/amdgpu/pciid2codename.txt ${CMAKE_CURRENT_SOURCE_DIR}/amdgpu/codename2offloadarch.txt ${CMAKE_CURRENT_SOURCE_DIR}/nvidia/pciid2codename.txt diff --git a/llvm/lib/OffloadArch/generated_offload_arch.h b/llvm/lib/OffloadArch/generated_offload_arch.h deleted file mode 100644 index 036ac481248906..00000000000000 --- a/llvm/lib/OffloadArch/generated_offload_arch.h +++ /dev/null @@ -1,462 +0,0 @@ -// This file is generated by make_generated_offload_arch_h.sh -// It is only included by OffloadArch.cpp -#include -#include -typedef enum { - AOT_GFX1010, - AOT_GFX1011, - AOT_GFX1012, - AOT_GFX1013, - AOT_GFX1030, - AOT_GFX1031, - AOT_GFX1032, - AOT_GFX1033, - AOT_GFX1034, - AOT_GFX1035, - AOT_GFX1036, - AOT_GFX1100, - AOT_GFX1101, - AOT_GFX1102, - AOT_GFX1103, - AOT_GFX700, - AOT_GFX701, - AOT_GFX801, - AOT_GFX802, - AOT_GFX803, - AOT_GFX900, - AOT_GFX902, - AOT_GFX904, - AOT_GFX906, - AOT_GFX908, - AOT_GFX90A, - AOT_GFX90C, - AOT_SM_30, - AOT_SM_35, - AOT_SM_50, - AOT_SM_60, - AOT_SM_61, - AOT_SM_70, -} AOT_OFFLOADARCH; -typedef enum { - AOT_CN_ALDEBARAN, - AOT_CN_ARCTURUS, - AOT_CN_BEIGE_GOBY, - AOT_CN_CARRIZO, - AOT_CN_CYAN_SKILLFISH, - AOT_CN_DIMGREY_CAVEFISH, - AOT_CN_FIJI, - AOT_CN_HAWAII, - AOT_CN_HOTPINK_BONEFISH, - AOT_CN_NAVI10, - AOT_CN_NAVI12, - AOT_CN_NAVI14, - AOT_CN_NAVY_FLOUNDER, - AOT_CN_PINK_SARDINE, - AOT_CN_PLUM_BONITO, - AOT_CN_POLARIS10, - AOT_CN_POLARIS11, - AOT_CN_POLARIS12, - AOT_CN_RAPHAEL, - AOT_CN_RAVEN, - AOT_CN_REMBRANDT, - AOT_CN_RENOIR, - AOT_CN_SIENNA_CICHLID, - AOT_CN_SPECTRE, - AOT_CN_SPOOKY, - AOT_CN_TONGA, - AOT_CN_VANGOGH, - AOT_CN_VEGA10, - AOT_CN_VEGA12, - AOT_CN_VEGA20, - AOT_CN_VEGAM, - AOT_CN_WHEAT_NAS, - AOT_CN_YELLOW_CARP, - AOT_CN_K4000, - AOT_CN_K4200, - AOT_CN_GTX750, - AOT_CN_GTX960M, - AOT_CN_GTX980, - AOT_CN_GTX1050, - AOT_CN_GTX1060, - AOT_CN_GTX1080, - AOT_CN_GT730, - AOT_CN_P100, - AOT_CN_GV100, - AOT_CN_V100, -} AOT_CODENAME; - -struct AOT_CODENAME_ID_TO_STRING{ - AOT_CODENAME codename_id; - const char* codename; -}; - -struct AOT_OFFLOADARCH_TO_STRING{ - AOT_OFFLOADARCH offloadarch_id; - const char* offloadarch; -}; - -struct AOT_OFFLOADARCH_TO_CODENAME_ENTRY{ - const char* offloadarch; - const char* codename; -}; - -struct AOT_TABLE_ENTRY{ - uint16_t vendorid; - uint16_t devid; - AOT_CODENAME codename_id; - AOT_OFFLOADARCH offloadarch_id; -}; -extern const AOT_CODENAME_ID_TO_STRING AOT_CODENAMES[] = { - {AOT_CN_ALDEBARAN, "ALDEBARAN"}, - {AOT_CN_ARCTURUS, "ARCTURUS"}, - {AOT_CN_BEIGE_GOBY, "BEIGE_GOBY"}, - {AOT_CN_CARRIZO, "CARRIZO"}, - {AOT_CN_CYAN_SKILLFISH, "CYAN_SKILLFISH"}, - {AOT_CN_DIMGREY_CAVEFISH, "DIMGREY_CAVEFISH"}, - {AOT_CN_FIJI, "FIJI"}, - {AOT_CN_HAWAII, "HAWAII"}, - {AOT_CN_HOTPINK_BONEFISH, "HOTPINK_BONEFISH"}, - {AOT_CN_NAVI10, "NAVI10"}, - {AOT_CN_NAVI12, "NAVI12"}, - {AOT_CN_NAVI14, "NAVI14"}, - {AOT_CN_NAVY_FLOUNDER, "NAVY_FLOUNDER"}, - {AOT_CN_PINK_SARDINE, "PINK_SARDINE"}, - {AOT_CN_PLUM_BONITO, "PLUM_BONITO"}, - {AOT_CN_POLARIS10, "POLARIS10"}, - {AOT_CN_POLARIS11, "POLARIS11"}, - {AOT_CN_POLARIS12, "POLARIS12"}, - {AOT_CN_RAPHAEL, "RAPHAEL"}, - {AOT_CN_RAVEN, "RAVEN"}, - {AOT_CN_REMBRANDT, "REMBRANDT"}, - {AOT_CN_RENOIR, "RENOIR"}, - {AOT_CN_SIENNA_CICHLID, "SIENNA_CICHLID"}, - {AOT_CN_SPECTRE, "SPECTRE"}, - {AOT_CN_SPOOKY, "SPOOKY"}, - {AOT_CN_TONGA, "TONGA"}, - {AOT_CN_VANGOGH, "VANGOGH"}, - {AOT_CN_VEGA10, "VEGA10"}, - {AOT_CN_VEGA12, "VEGA12"}, - {AOT_CN_VEGA20, "VEGA20"}, - {AOT_CN_VEGAM, "VEGAM"}, - {AOT_CN_WHEAT_NAS, "WHEAT_NAS"}, - {AOT_CN_YELLOW_CARP, "YELLOW_CARP"}, - {AOT_CN_K4000, "k4000"}, - {AOT_CN_K4200, "k4200"}, - {AOT_CN_GTX750, "gtx750"}, - {AOT_CN_GTX960M, "gtx960m"}, - {AOT_CN_GTX980, "gtx980"}, - {AOT_CN_GTX1050, "gtx1050"}, - {AOT_CN_GTX1060, "gtx1060"}, - {AOT_CN_GTX1080, "gtx1080"}, - {AOT_CN_GT730, "gt730"}, - {AOT_CN_P100, "p100"}, - {AOT_CN_GV100, "gv100"}, - {AOT_CN_V100, "v100"}, -}; -extern const AOT_OFFLOADARCH_TO_STRING AOT_OFFLOADARCHS[] = { - {AOT_GFX1010, "gfx1010"}, - {AOT_GFX1011, "gfx1011"}, - {AOT_GFX1012, "gfx1012"}, - {AOT_GFX1013, "gfx1013"}, - {AOT_GFX1030, "gfx1030"}, - {AOT_GFX1031, "gfx1031"}, - {AOT_GFX1032, "gfx1032"}, - {AOT_GFX1033, "gfx1033"}, - {AOT_GFX1034, "gfx1034"}, - {AOT_GFX1035, "gfx1035"}, - {AOT_GFX1036, "gfx1036"}, - {AOT_GFX1100, "gfx1100"}, - {AOT_GFX1101, "gfx1101"}, - {AOT_GFX1102, "gfx1102"}, - {AOT_GFX1103, "gfx1103"}, - {AOT_GFX700, "gfx700"}, - {AOT_GFX701, "gfx701"}, - {AOT_GFX801, "gfx801"}, - {AOT_GFX802, "gfx802"}, - {AOT_GFX803, "gfx803"}, - {AOT_GFX900, "gfx900"}, - {AOT_GFX902, "gfx902"}, - {AOT_GFX904, "gfx904"}, - {AOT_GFX906, "gfx906"}, - {AOT_GFX908, "gfx908"}, - {AOT_GFX90A, "gfx90a"}, - {AOT_GFX90C, "gfx90c"}, - {AOT_SM_30, "sm_30"}, - {AOT_SM_35, "sm_35"}, - {AOT_SM_50, "sm_50"}, - {AOT_SM_60, "sm_60"}, - {AOT_SM_61, "sm_61"}, - {AOT_SM_70, "sm_70"}, -}; -extern const AOT_OFFLOADARCH_TO_CODENAME_ENTRY AOT_AMD_OFFLOADARCH_TO_CODENAME_TABLE[] = { -{ "gfx1010", "NAVI10" }, -{ "gfx1011", "NAVI12" }, -{ "gfx1012", "NAVI14" }, -{ "gfx1013", "CYAN_SKILLFISH" }, -{ "gfx1030", "SIENNA_CICHLID" }, -{ "gfx1031", "NAVY_FLOUNDER" }, -{ "gfx1032", "DIMGREY_CAVEFISH" }, -{ "gfx1033", "VANGOGH" }, -{ "gfx1034", "BEIGE_GOBY" }, -{ "gfx1035", "REMBRANDT" }, -{ "gfx1036", "RAPHAEL" }, -{ "gfx1100", "PLUM_BONITO" }, -{ "gfx1101", "WHEAT_NAS" }, -{ "gfx1102", "HOTPINK_BONEFISH" }, -{ "gfx1103", "PINK_SARDINE" }, -{ "gfx700", "SPECTRE" }, -{ "gfx701", "HAWAII" }, -{ "gfx801", "CARRIZO" }, -{ "gfx802", "TONGA" }, -{ "gfx803", "FIJI" }, -{ "gfx900", "VEGA10" }, -{ "gfx902", "RAVEN" }, -{ "gfx904", "VEGA12" }, -{ "gfx906", "VEGA20" }, -{ "gfx908", "ARCTURUS" }, -{ "gfx90a", "ALDEBARAN" }, -{ "gfx90c", "RENOIR" }, -}; -extern const AOT_TABLE_ENTRY AOT_TABLE[] = { -{ 0x1002, 0x1304, AOT_CN_SPECTRE, AOT_GFX700 }, -{ 0x1002, 0x1305, AOT_CN_SPECTRE, AOT_GFX700 }, -{ 0x1002, 0x1306, AOT_CN_SPECTRE, AOT_GFX700 }, -{ 0x1002, 0x1307, AOT_CN_SPECTRE, AOT_GFX700 }, -{ 0x1002, 0x1309, AOT_CN_SPECTRE, AOT_GFX700 }, -{ 0x1002, 0x130A, AOT_CN_SPECTRE, AOT_GFX700 }, -{ 0x1002, 0x130B, AOT_CN_SPECTRE, AOT_GFX700 }, -{ 0x1002, 0x130C, AOT_CN_SPECTRE, AOT_GFX700 }, -{ 0x1002, 0x130D, AOT_CN_SPECTRE, AOT_GFX700 }, -{ 0x1002, 0x130E, AOT_CN_SPECTRE, AOT_GFX700 }, -{ 0x1002, 0x130F, AOT_CN_SPECTRE, AOT_GFX700 }, -{ 0x1002, 0x1310, AOT_CN_SPECTRE, AOT_GFX700 }, -{ 0x1002, 0x1311, AOT_CN_SPECTRE, AOT_GFX700 }, -{ 0x1002, 0x1312, AOT_CN_SPOOKY, AOT_GFX700 }, -{ 0x1002, 0x1313, AOT_CN_SPECTRE, AOT_GFX700 }, -{ 0x1002, 0x1315, AOT_CN_SPECTRE, AOT_GFX700 }, -{ 0x1002, 0x1316, AOT_CN_SPOOKY, AOT_GFX700 }, -{ 0x1002, 0x1317, AOT_CN_SPOOKY, AOT_GFX700 }, -{ 0x1002, 0x1318, AOT_CN_SPECTRE, AOT_GFX700 }, -{ 0x1002, 0x131B, AOT_CN_SPECTRE, AOT_GFX700 }, -{ 0x1002, 0x131C, AOT_CN_SPECTRE, AOT_GFX700 }, -{ 0x1002, 0x131D, AOT_CN_SPECTRE, AOT_GFX700 }, -{ 0x1002, 0x13F9, AOT_CN_CYAN_SKILLFISH, AOT_GFX1013 }, -{ 0x1002, 0x13FA, AOT_CN_CYAN_SKILLFISH, AOT_GFX1013 }, -{ 0x1002, 0x13FB, AOT_CN_CYAN_SKILLFISH, AOT_GFX1013 }, -{ 0x1002, 0x13FC, AOT_CN_CYAN_SKILLFISH, AOT_GFX1013 }, -{ 0x1002, 0x13FE, AOT_CN_CYAN_SKILLFISH, AOT_GFX1013 }, -{ 0x1002, 0x15D8, AOT_CN_RAVEN, AOT_GFX902 }, -{ 0x1002, 0x15DD, AOT_CN_RAVEN, AOT_GFX902 }, -{ 0x1002, 0x15E7, AOT_CN_RENOIR, AOT_GFX90C }, -{ 0x1002, 0x1636, AOT_CN_RENOIR, AOT_GFX90C }, -{ 0x1002, 0x1638, AOT_CN_RENOIR, AOT_GFX90C }, -{ 0x1002, 0x163F, AOT_CN_VANGOGH, AOT_GFX1033 }, -{ 0x1002, 0x164C, AOT_CN_RENOIR, AOT_GFX90C }, -{ 0x1002, 0x164d, AOT_CN_REMBRANDT, AOT_GFX1035 }, -{ 0x1002, 0x164D, AOT_CN_YELLOW_CARP, AOT_GFX1035 }, -{ 0x1002, 0x164e, AOT_CN_RAPHAEL, AOT_GFX1036 }, -{ 0x1002, 0x1681, AOT_CN_YELLOW_CARP, AOT_GFX1035 }, -{ 0x1002, 0x66A0, AOT_CN_VEGA20, AOT_GFX906 }, -{ 0x1002, 0x66A1, AOT_CN_VEGA20, AOT_GFX906 }, -{ 0x1002, 0x66A2, AOT_CN_VEGA20, AOT_GFX906 }, -{ 0x1002, 0x66A3, AOT_CN_VEGA20, AOT_GFX906 }, -{ 0x1002, 0x66A4, AOT_CN_VEGA20, AOT_GFX906 }, -{ 0x1002, 0x66A7, AOT_CN_VEGA20, AOT_GFX906 }, -{ 0x1002, 0x66AF, AOT_CN_VEGA20, AOT_GFX906 }, -{ 0x1002, 0x67A0, AOT_CN_HAWAII, AOT_GFX701 }, -{ 0x1002, 0x67A1, AOT_CN_HAWAII, AOT_GFX701 }, -{ 0x1002, 0x67A2, AOT_CN_HAWAII, AOT_GFX701 }, -{ 0x1002, 0x67A8, AOT_CN_HAWAII, AOT_GFX701 }, -{ 0x1002, 0x67A9, AOT_CN_HAWAII, AOT_GFX701 }, -{ 0x1002, 0x67AA, AOT_CN_HAWAII, AOT_GFX701 }, -{ 0x1002, 0x67B0, AOT_CN_HAWAII, AOT_GFX701 }, -{ 0x1002, 0x67B1, AOT_CN_HAWAII, AOT_GFX701 }, -{ 0x1002, 0x67B8, AOT_CN_HAWAII, AOT_GFX701 }, -{ 0x1002, 0x67B9, AOT_CN_HAWAII, AOT_GFX701 }, -{ 0x1002, 0x67BA, AOT_CN_HAWAII, AOT_GFX701 }, -{ 0x1002, 0x67BE, AOT_CN_HAWAII, AOT_GFX701 }, -{ 0x1002, 0x67C0, AOT_CN_POLARIS10, AOT_GFX803 }, -{ 0x1002, 0x67C1, AOT_CN_POLARIS10, AOT_GFX803 }, -{ 0x1002, 0x67C2, AOT_CN_POLARIS10, AOT_GFX803 }, -{ 0x1002, 0x67C4, AOT_CN_POLARIS10, AOT_GFX803 }, -{ 0x1002, 0x67C7, AOT_CN_POLARIS10, AOT_GFX803 }, -{ 0x1002, 0x67C8, AOT_CN_POLARIS10, AOT_GFX803 }, -{ 0x1002, 0x67C9, AOT_CN_POLARIS10, AOT_GFX803 }, -{ 0x1002, 0x67CA, AOT_CN_POLARIS10, AOT_GFX803 }, -{ 0x1002, 0x67CC, AOT_CN_POLARIS10, AOT_GFX803 }, -{ 0x1002, 0x67CF, AOT_CN_POLARIS10, AOT_GFX803 }, -{ 0x1002, 0x67D0, AOT_CN_POLARIS10, AOT_GFX803 }, -{ 0x1002, 0x67DF, AOT_CN_POLARIS10, AOT_GFX803 }, -{ 0x1002, 0x67E0, AOT_CN_POLARIS11, AOT_GFX803 }, -{ 0x1002, 0x67E1, AOT_CN_POLARIS11, AOT_GFX803 }, -{ 0x1002, 0x67E3, AOT_CN_POLARIS11, AOT_GFX803 }, -{ 0x1002, 0x67E7, AOT_CN_POLARIS11, AOT_GFX803 }, -{ 0x1002, 0x67E8, AOT_CN_POLARIS11, AOT_GFX803 }, -{ 0x1002, 0x67E9, AOT_CN_POLARIS11, AOT_GFX803 }, -{ 0x1002, 0x67EB, AOT_CN_POLARIS11, AOT_GFX803 }, -{ 0x1002, 0x67EF, AOT_CN_POLARIS11, AOT_GFX803 }, -{ 0x1002, 0x67FF, AOT_CN_POLARIS11, AOT_GFX803 }, -{ 0x1002, 0x6860, AOT_CN_VEGA10, AOT_GFX900 }, -{ 0x1002, 0x6861, AOT_CN_VEGA10, AOT_GFX900 }, -{ 0x1002, 0x6862, AOT_CN_VEGA10, AOT_GFX900 }, -{ 0x1002, 0x6863, AOT_CN_VEGA10, AOT_GFX900 }, -{ 0x1002, 0x6864, AOT_CN_VEGA10, AOT_GFX900 }, -{ 0x1002, 0x6867, AOT_CN_VEGA10, AOT_GFX900 }, -{ 0x1002, 0x6868, AOT_CN_VEGA10, AOT_GFX900 }, -{ 0x1002, 0x6869, AOT_CN_VEGA10, AOT_GFX900 }, -{ 0x1002, 0x686A, AOT_CN_VEGA10, AOT_GFX900 }, -{ 0x1002, 0x686B, AOT_CN_VEGA10, AOT_GFX900 }, -{ 0x1002, 0x686C, AOT_CN_VEGA10, AOT_GFX900 }, -{ 0x1002, 0x686D, AOT_CN_VEGA10, AOT_GFX900 }, -{ 0x1002, 0x686E, AOT_CN_VEGA10, AOT_GFX900 }, -{ 0x1002, 0x687F, AOT_CN_VEGA10, AOT_GFX900 }, -{ 0x1002, 0x6920, AOT_CN_TONGA, AOT_GFX802 }, -{ 0x1002, 0x6921, AOT_CN_TONGA, AOT_GFX802 }, -{ 0x1002, 0x6928, AOT_CN_TONGA, AOT_GFX802 }, -{ 0x1002, 0x6929, AOT_CN_TONGA, AOT_GFX802 }, -{ 0x1002, 0x692B, AOT_CN_TONGA, AOT_GFX802 }, -{ 0x1002, 0x692F, AOT_CN_TONGA, AOT_GFX802 }, -{ 0x1002, 0x6930, AOT_CN_TONGA, AOT_GFX802 }, -{ 0x1002, 0x6938, AOT_CN_TONGA, AOT_GFX802 }, -{ 0x1002, 0x6939, AOT_CN_TONGA, AOT_GFX802 }, -{ 0x1002, 0x694C, AOT_CN_VEGAM, AOT_GFX803 }, -{ 0x1002, 0x694E, AOT_CN_VEGAM, AOT_GFX803 }, -{ 0x1002, 0x694F, AOT_CN_VEGAM, AOT_GFX803 }, -{ 0x1002, 0x6980, AOT_CN_POLARIS12, AOT_GFX803 }, -{ 0x1002, 0x6981, AOT_CN_POLARIS12, AOT_GFX803 }, -{ 0x1002, 0x6985, AOT_CN_POLARIS12, AOT_GFX803 }, -{ 0x1002, 0x6986, AOT_CN_POLARIS12, AOT_GFX803 }, -{ 0x1002, 0x6987, AOT_CN_POLARIS12, AOT_GFX803 }, -{ 0x1002, 0x6995, AOT_CN_POLARIS12, AOT_GFX803 }, -{ 0x1002, 0x6997, AOT_CN_POLARIS12, AOT_GFX803 }, -{ 0x1002, 0x699F, AOT_CN_POLARIS12, AOT_GFX803 }, -{ 0x1002, 0x69A0, AOT_CN_VEGA12, AOT_GFX904 }, -{ 0x1002, 0x69A1, AOT_CN_VEGA12, AOT_GFX904 }, -{ 0x1002, 0x69A2, AOT_CN_VEGA12, AOT_GFX904 }, -{ 0x1002, 0x69A3, AOT_CN_VEGA12, AOT_GFX904 }, -{ 0x1002, 0x69Af, AOT_CN_VEGA12, AOT_GFX904 }, -{ 0x1002, 0x6FDF, AOT_CN_POLARIS10, AOT_GFX803 }, -{ 0x1002, 0x7300, AOT_CN_FIJI, AOT_GFX803 }, -{ 0x1002, 0x730F, AOT_CN_FIJI, AOT_GFX803 }, -{ 0x1002, 0x7310, AOT_CN_NAVI10, AOT_GFX1010 }, -{ 0x1002, 0x7312, AOT_CN_NAVI10, AOT_GFX1010 }, -{ 0x1002, 0x7318, AOT_CN_NAVI10, AOT_GFX1010 }, -{ 0x1002, 0x731A, AOT_CN_NAVI10, AOT_GFX1010 }, -{ 0x1002, 0x731E, AOT_CN_NAVI10, AOT_GFX1010 }, -{ 0x1002, 0x731F, AOT_CN_NAVI10, AOT_GFX1010 }, -{ 0x1002, 0x7340, AOT_CN_NAVI14, AOT_GFX1012 }, -{ 0x1002, 0x7341, AOT_CN_NAVI14, AOT_GFX1012 }, -{ 0x1002, 0x7347, AOT_CN_NAVI14, AOT_GFX1012 }, -{ 0x1002, 0x7360, AOT_CN_NAVI12, AOT_GFX1011 }, -{ 0x1002, 0x7362, AOT_CN_NAVI12, AOT_GFX1011 }, -{ 0x1002, 0x7388, AOT_CN_ARCTURUS, AOT_GFX908 }, -{ 0x1002, 0x738C, AOT_CN_ARCTURUS, AOT_GFX908 }, -{ 0x1002, 0x738E, AOT_CN_ARCTURUS, AOT_GFX908 }, -{ 0x1002, 0x7390, AOT_CN_ARCTURUS, AOT_GFX908 }, -{ 0x1002, 0x73A0, AOT_CN_SIENNA_CICHLID, AOT_GFX1030 }, -{ 0x1002, 0x73A1, AOT_CN_SIENNA_CICHLID, AOT_GFX1030 }, -{ 0x1002, 0x73A2, AOT_CN_SIENNA_CICHLID, AOT_GFX1030 }, -{ 0x1002, 0x73A3, AOT_CN_SIENNA_CICHLID, AOT_GFX1030 }, -{ 0x1002, 0x73A5, AOT_CN_SIENNA_CICHLID, AOT_GFX1030 }, -{ 0x1002, 0x73A8, AOT_CN_SIENNA_CICHLID, AOT_GFX1030 }, -{ 0x1002, 0x73A9, AOT_CN_SIENNA_CICHLID, AOT_GFX1030 }, -{ 0x1002, 0x73AB, AOT_CN_SIENNA_CICHLID, AOT_GFX1030 }, -{ 0x1002, 0x73AC, AOT_CN_SIENNA_CICHLID, AOT_GFX1030 }, -{ 0x1002, 0x73AD, AOT_CN_SIENNA_CICHLID, AOT_GFX1030 }, -{ 0x1002, 0x73AE, AOT_CN_SIENNA_CICHLID, AOT_GFX1030 }, -{ 0x1002, 0x73BF, AOT_CN_SIENNA_CICHLID, AOT_GFX1030 }, -{ 0x1002, 0x73C0, AOT_CN_NAVY_FLOUNDER, AOT_GFX1031 }, -{ 0x1002, 0x73C1, AOT_CN_NAVY_FLOUNDER, AOT_GFX1031 }, -{ 0x1002, 0x73C3, AOT_CN_NAVY_FLOUNDER, AOT_GFX1031 }, -{ 0x1002, 0x73DA, AOT_CN_NAVY_FLOUNDER, AOT_GFX1031 }, -{ 0x1002, 0x73DB, AOT_CN_NAVY_FLOUNDER, AOT_GFX1031 }, -{ 0x1002, 0x73DC, AOT_CN_NAVY_FLOUNDER, AOT_GFX1031 }, -{ 0x1002, 0x73DD, AOT_CN_NAVY_FLOUNDER, AOT_GFX1031 }, -{ 0x1002, 0x73DE, AOT_CN_NAVY_FLOUNDER, AOT_GFX1031 }, -{ 0x1002, 0x73DF, AOT_CN_NAVY_FLOUNDER, AOT_GFX1031 }, -{ 0x1002, 0x73E0, AOT_CN_DIMGREY_CAVEFISH, AOT_GFX1032 }, -{ 0x1002, 0x73E1, AOT_CN_DIMGREY_CAVEFISH, AOT_GFX1032 }, -{ 0x1002, 0x73E2, AOT_CN_DIMGREY_CAVEFISH, AOT_GFX1032 }, -{ 0x1002, 0x73E8, AOT_CN_DIMGREY_CAVEFISH, AOT_GFX1032 }, -{ 0x1002, 0x73E9, AOT_CN_DIMGREY_CAVEFISH, AOT_GFX1032 }, -{ 0x1002, 0x73EA, AOT_CN_DIMGREY_CAVEFISH, AOT_GFX1032 }, -{ 0x1002, 0x73EB, AOT_CN_DIMGREY_CAVEFISH, AOT_GFX1032 }, -{ 0x1002, 0x73EC, AOT_CN_DIMGREY_CAVEFISH, AOT_GFX1032 }, -{ 0x1002, 0x73ED, AOT_CN_DIMGREY_CAVEFISH, AOT_GFX1032 }, -{ 0x1002, 0x73EF, AOT_CN_DIMGREY_CAVEFISH, AOT_GFX1032 }, -{ 0x1002, 0x73FF, AOT_CN_DIMGREY_CAVEFISH, AOT_GFX1032 }, -{ 0x1002, 0x7408, AOT_CN_ALDEBARAN, AOT_GFX90A }, -{ 0x1002, 0x740C, AOT_CN_ALDEBARAN, AOT_GFX90A }, -{ 0x1002, 0x740F, AOT_CN_ALDEBARAN, AOT_GFX90A }, -{ 0x1002, 0x7410, AOT_CN_ALDEBARAN, AOT_GFX90A }, -{ 0x1002, 0x7420, AOT_CN_BEIGE_GOBY, AOT_GFX1034 }, -{ 0x1002, 0x7421, AOT_CN_BEIGE_GOBY, AOT_GFX1034 }, -{ 0x1002, 0x7422, AOT_CN_BEIGE_GOBY, AOT_GFX1034 }, -{ 0x1002, 0x7423, AOT_CN_BEIGE_GOBY, AOT_GFX1034 }, -{ 0x1002, 0x743F, AOT_CN_BEIGE_GOBY, AOT_GFX1034 }, -{ 0x1002, 0x744C, AOT_CN_PLUM_BONITO, AOT_GFX1100 }, -{ 0x1002, 0x9870, AOT_CN_CARRIZO, AOT_GFX801 }, -{ 0x1002, 0x9874, AOT_CN_CARRIZO, AOT_GFX801 }, -{ 0x1002, 0x9875, AOT_CN_CARRIZO, AOT_GFX801 }, -{ 0x1002, 0x9876, AOT_CN_CARRIZO, AOT_GFX801 }, -{ 0x1002, 0x9877, AOT_CN_CARRIZO, AOT_GFX801 }, -{ 0x10de, 0x0f02, AOT_CN_GT730, AOT_SM_35 }, -{ 0x10de, 0x0f06, AOT_CN_GT730, AOT_SM_35 }, -{ 0x10de, 0x0fc9, AOT_CN_GT730, AOT_SM_35 }, -{ 0x10de, 0x11b4, AOT_CN_K4200, AOT_SM_30 }, -{ 0x10de, 0x11c7, AOT_CN_GTX750, AOT_SM_50 }, -{ 0x10de, 0x11fa, AOT_CN_K4000, AOT_SM_30 }, -{ 0x10de, 0x1287, AOT_CN_GT730, AOT_SM_35 }, -{ 0x10de, 0x1380, AOT_CN_GTX750, AOT_SM_50 }, -{ 0x10de, 0x1381, AOT_CN_GTX750, AOT_SM_50 }, -{ 0x10de, 0x139b, AOT_CN_GTX960M, AOT_SM_50 }, -{ 0x10de, 0x139b, AOT_CN_GTX960M, AOT_SM_50 }, -{ 0x10de, 0x139b, AOT_CN_GTX960M, AOT_SM_50 }, -{ 0x10de, 0x139d, AOT_CN_GTX750, AOT_SM_50 }, -{ 0x10de, 0x13c0, AOT_CN_GTX980, AOT_SM_35 }, -{ 0x10de, 0x13c0, AOT_CN_GTX980, AOT_SM_35 }, -{ 0x10de, 0x13da, AOT_CN_GTX980, AOT_SM_35 }, -{ 0x10de, 0x13e7, AOT_CN_GTX980, AOT_SM_35 }, -{ 0x10de, 0x1407, AOT_CN_GTX750, AOT_SM_50 }, -{ 0x10de, 0x15f7, AOT_CN_P100, AOT_SM_60 }, -{ 0x10de, 0x15f8, AOT_CN_P100, AOT_SM_60 }, -{ 0x10de, 0x15f9, AOT_CN_P100, AOT_SM_60 }, -{ 0x10de, 0x161a, AOT_CN_GTX980, AOT_SM_35 }, -{ 0x10de, 0x17c8, AOT_CN_GTX980, AOT_SM_35 }, -{ 0x10de, 0x1b06, AOT_CN_GTX1080, AOT_SM_61 }, -{ 0x10de, 0x1b80, AOT_CN_GTX1080, AOT_SM_61 }, -{ 0x10de, 0x1b83, AOT_CN_GTX1060, AOT_SM_61 }, -{ 0x10de, 0x1b84, AOT_CN_GTX1060, AOT_SM_61 }, -{ 0x10de, 0x1ba0, AOT_CN_GTX1080, AOT_SM_61 }, -{ 0x10de, 0x1be0, AOT_CN_GTX1080, AOT_SM_61 }, -{ 0x10de, 0x1be0, AOT_CN_GTX1080, AOT_SM_61 }, -{ 0x10de, 0x1be0, AOT_CN_GTX1080, AOT_SM_61 }, -{ 0x10de, 0x1c02, AOT_CN_GTX1060, AOT_SM_61 }, -{ 0x10de, 0x1c03, AOT_CN_GTX1060, AOT_SM_61 }, -{ 0x10de, 0x1c04, AOT_CN_GTX1060, AOT_SM_61 }, -{ 0x10de, 0x1c06, AOT_CN_GTX1060, AOT_SM_61 }, -{ 0x10de, 0x1c20, AOT_CN_GTX1060, AOT_SM_61 }, -{ 0x10de, 0x1c20, AOT_CN_GTX1060, AOT_SM_61 }, -{ 0x10de, 0x1c21, AOT_CN_GTX1050, AOT_SM_61 }, -{ 0x10de, 0x1c22, AOT_CN_GTX1050, AOT_SM_61 }, -{ 0x10de, 0x1c60, AOT_CN_GTX1060, AOT_SM_61 }, -{ 0x10de, 0x1c60, AOT_CN_GTX1060, AOT_SM_61 }, -{ 0x10de, 0x1c61, AOT_CN_GTX1050, AOT_SM_61 }, -{ 0x10de, 0x1c62, AOT_CN_GTX1050, AOT_SM_61 }, -{ 0x10de, 0x1c81, AOT_CN_GTX1050, AOT_SM_61 }, -{ 0x10de, 0x1c82, AOT_CN_GTX1050, AOT_SM_61 }, -{ 0x10de, 0x1c83, AOT_CN_GTX1050, AOT_SM_61 }, -{ 0x10de, 0x1c8c, AOT_CN_GTX1050, AOT_SM_61 }, -{ 0x10de, 0x1c8d, AOT_CN_GTX1050, AOT_SM_61 }, -{ 0x10de, 0x1c8f, AOT_CN_GTX1050, AOT_SM_61 }, -{ 0x10de, 0x1c92, AOT_CN_GTX1050, AOT_SM_61 }, -{ 0x10de, 0x1ccc, AOT_CN_GTX1050, AOT_SM_61 }, -{ 0x10de, 0x1ccd, AOT_CN_GTX1050, AOT_SM_61 }, -{ 0x10de, 0x1db1, AOT_CN_V100, AOT_SM_70 }, -{ 0x10de, 0x1db4, AOT_CN_V100, AOT_SM_70 }, -{ 0x10de, 0x1db5, AOT_CN_V100, AOT_SM_70 }, -{ 0x10de, 0x1db6, AOT_CN_V100, AOT_SM_70 }, -{ 0x10de, 0x1db7, AOT_CN_V100, AOT_SM_70 }, -{ 0x10de, 0x1dba, AOT_CN_GV100, AOT_SM_70 }, -{ 0x10de, 0x1dba, AOT_CN_GV100, AOT_SM_70 }, -}; diff --git a/llvm/lib/OffloadArch/make_generated_offload_arch_h.py b/llvm/lib/OffloadArch/make_generated_offload_arch_h.py new file mode 100644 index 00000000000000..5f0a7afd7cfc98 --- /dev/null +++ b/llvm/lib/OffloadArch/make_generated_offload_arch_h.py @@ -0,0 +1,190 @@ +# +# make_generated_offload_arch_h.py - Create the fle generated_offload_arch.h +# +# Copyright (c) 2024 ADVANCED MICRO DEVICES, INC. +# +# AMD is granting you permission to use this software and documentation (if any) (collectively, the +# Materials) pursuant to the terms and conditions of the Software License Agreement included with the +# Materials. If you do not have a copy of the Software License Agreement, contact your AMD +# representative for a copy. +# +# You agree that you will not reverse engineer or decompile the Materials, in whole or in part, except for +# example code which is provided in source code form and as allowed by applicable law. +# +# WARRANTY DISCLAIMER: THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY +# KIND. AMD DISCLAIMS ALL WARRANTIES, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING BUT NOT +# LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR +# PURPOSE, TITLE, NON-INFRINGEMENT, THAT THE SOFTWARE WILL RUN UNINTERRUPTED OR ERROR- +# FREE OR WARRANTIES ARISING FROM CUSTOM OF TRADE OR COURSE OF USAGE. THE ENTIRE RISK +# ASSOCIATED WITH THE USE OF THE SOFTWARE IS ASSUMED BY YOU. Some jurisdictions do not +# allow the exclusion of implied warranties, so the above exclusion may not apply to You. +# +# LIMITATION OF LIABILITY AND INDEMNIFICATION: AMD AND ITS LICENSORS WILL NOT, +# UNDER ANY CIRCUMSTANCES BE LIABLE TO YOU FOR ANY PUNITIVE, DIRECT, INCIDENTAL, +# INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES ARISING FROM USE OF THE SOFTWARE OR THIS +# AGREEMENT EVEN IF AMD AND ITS LICENSORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH +# DAMAGES. In no event shall AMD's total liability to You for all damages, losses, and +# causes of action (whether in contract, tort (including negligence) or otherwise) +# exceed the amount of $100 USD. You agree to defend, indemnify and hold harmless +# AMD and its licensors, and any of their directors, officers, employees, affiliates or +# agents from and against any and all loss, damage, liability and other expenses +# (including reasonable attorneys' fees), resulting from Your use of the Software or +# violation of the terms and conditions of this Agreement. +# +# U.S. GOVERNMENT RESTRICTED RIGHTS: The Materials are provided with "RESTRICTED RIGHTS." +# Use, duplication, or disclosure by the Government is subject to the restrictions as set +# forth in FAR 52.227-14 and DFAR252.227-7013, et seq., or its successor. Use of the +# Materials by the Government constitutes acknowledgement of AMD's proprietary rights in them. +# +# EXPORT RESTRICTIONS: The Materials may be subject to export restrictions as stated in the +# Software License Agreement. +# + +import sys +from pathlib import Path +from typing import Dict, List, Set, Tuple + +# These are the input files +AOT_PCIID2CODENAME = ["amdgpu/pciid2codename.txt", "nvidia/pciid2codename.txt"] +AOT_CODENAME2OFFLIADARCH = ["amdgpu/codename2offloadarch.txt", "nvidia/codename2offloadarch.txt"] +AOT_CODENAME2OFFLIADARCH_AMD = ["amdgpu/codename2offloadarch.txt"] + +# This is the output file which is always written to current dir +AOT_DOTH_FILE = Path.cwd() / "generated_offload_arch.h" + + +def write_aot_prolog(file) -> None: + print('// This file is generated by make_generated_offload_arch_h.py\n' + '// It is only included by OffloadArch.cpp\n' + '#include \n' + '#include \n', file=file, flush=True) + + +def write_aot_offloadarch(file, archs: Set[str]) -> None: + print('typedef enum {', file=file) + for arch in sorted(archs): + print(f' AOT_{arch.upper()},', file=file) + print('} AOT_OFFLOADARCH;\n', file=file, flush=True) + + +def write_aot_codename(file, codenames: Set[str]) -> None: + print('typedef enum {', file=file) + for codename in sorted(codenames): + print(f' AOT_CN_{codename.upper()},', file=file) + print('} AOT_CODENAME;\n', file=file, flush=True) + + +def write_aot_structs(file) -> None: + print('struct AOT_CODENAME_ID_TO_STRING{\n' + ' AOT_CODENAME codename_id;\n' + ' const char* codename;\n' + '};\n' + '\n' + 'struct AOT_OFFLOADARCH_TO_STRING{\n' + ' AOT_OFFLOADARCH offloadarch_id;\n' + ' const char* offloadarch;\n' + '};\n' + '\n' + 'struct AOT_OFFLOADARCH_TO_CODENAME_ENTRY{\n' + ' const char* offloadarch;\n' + ' const char* codename;\n' + '};\n' + '\n' + 'struct AOT_TABLE_ENTRY{\n' + ' uint16_t vendorid;\n' + ' uint16_t devid;\n' + ' AOT_CODENAME codename_id;\n' + ' AOT_OFFLOADARCH offloadarch_id;\n' + '};\n', file=file, flush=True) + + +def write_aot_codename_to_string(file, codenames: Set[str]) -> None: + print('extern const AOT_CODENAME_ID_TO_STRING AOT_CODENAMES[] = {', file=file) + for codename in sorted(codenames): + print(' {AOT_CN_'f'{codename.upper()}, "{codename}"''},', file=file) + print('};\n', file=file, flush=True) + + +def write_aot_offloadarch_to_string(file, offload_archs: Set[str]) -> None: + print('extern const AOT_OFFLOADARCH_TO_STRING AOT_OFFLOADARCHS[] = {', file=file) + for arch in sorted(offload_archs): + print(' {AOT_'f'{arch.upper()}, "{arch}"''},', file=file) + print('};\n', file=file, flush=True) + + +def write_amd_offloadarch_to_codename_table(file, code_names: Dict[str, List[str]]) -> None: + print('extern const AOT_OFFLOADARCH_TO_CODENAME_ENTRY AOT_AMD_OFFLOADARCH_TO_CODENAME_TABLE[] = {', file=file) + for code_name, offload_arch in code_names.items(): + print(' {'f'"{offload_arch[0]}", "{code_name}"''},', file=file, flush=True) + print('};\n', file=file, flush=True) + + +def write_aot_table(file, offload_archs: Dict[str, List[str]], pci_ids: Dict[str, Tuple[str, str]]) -> None: + print('extern const AOT_TABLE_ENTRY AOT_TABLE[] = {', file=file) + for key, pci_id in pci_ids.items(): + offload_arch = offload_archs[key][0] + for pci_vid, pci_did in pci_id: + # Workaround, not enough information to map below correctly from txt files + if pci_vid == '0x1002' and pci_did == '0x74a1': + offload_arch = 'gfx941' + print(' {'f'{pci_vid}, {pci_did}, AOT_CN_{key.upper()}, AOT_{offload_arch.upper()}''},', file=file) + print('};\n', file=file, flush=True) + + +def read_codename2offloadarch(input_dir: Path, files: List[str]) -> Dict[str, List[str]]: + result = dict() + for file in files: + with (input_dir / file).open() as f: + for line in f.readlines(): + (codename, offload_arch) = line.strip().split(sep=' ', maxsplit=1) + result.setdefault(codename, []).append(offload_arch) + return result + + +def read_pciid2codename(input_path: Path, codenames: Set[str]) -> Dict[str, Tuple[str, str]]: + result = dict() + for file in AOT_PCIID2CODENAME: + with (input_path / file).open() as f: + for line in f.readlines(): + (pci_vid, pci_did, _, _, codename, _) = \ + line.strip() \ + .replace(' : ', ' ') \ + .replace(':', ' ') \ + .split(sep=' ', maxsplit=5) + # only proceed if we know about this codename + if codename in codenames: + result.setdefault(codename, []).append((f'0x{pci_vid}', f'0x{pci_did}')) + return result + + +# =========== Main code starts here ====================== + +def main(input_dir: Path): + # we don't want to append to existing file + AOT_DOTH_FILE.unlink(missing_ok=True) + + codename2offload_arch = read_codename2offloadarch(input_dir, AOT_CODENAME2OFFLIADARCH) + + codenames, offload_archs = set(), set() + for [key, offload_arch] in codename2offload_arch.items(): + codenames.add(key) + offload_archs.update(offload_arch) + + pciid2codename = read_pciid2codename(input_dir, codenames) + + codename2offload_arch_amd = read_codename2offloadarch(input_dir, AOT_CODENAME2OFFLIADARCH_AMD) + + with AOT_DOTH_FILE.open(mode="w") as f: + write_aot_prolog(f) + write_aot_offloadarch(f, offload_archs) + write_aot_codename(f, codenames) + write_aot_structs(f) + write_aot_codename_to_string(f, codenames) + write_aot_offloadarch_to_string(f, offload_archs) + write_amd_offloadarch_to_codename_table(f, codename2offload_arch_amd) + write_aot_table(f, codename2offload_arch, pciid2codename) + + +if __name__ == "__main__": + main(Path(sys.argv[1]) if len(sys.argv) > 1 else Path.cwd()) + diff --git a/llvm/lib/OffloadArch/make_generated_offload_arch_h.sh b/llvm/lib/OffloadArch/make_generated_offload_arch_h.sh deleted file mode 100755 index 9704b02ef5c58e..00000000000000 --- a/llvm/lib/OffloadArch/make_generated_offload_arch_h.sh +++ /dev/null @@ -1,201 +0,0 @@ -#!/usr/bin/env bash -# -# make_generated_offload_arch_h.sh - Create the fle generated_offload_arch.h -# -# Written by Greg Rodgers Gregory.Rodgers@amd.com -# Copyright (c) 2021 ADVANCED MICRO DEVICES, INC. -# -# AMD is granting you permission to use this software and documentation (if any) (collectively, the -# Materials) pursuant to the terms and conditions of the Software License Agreement included with the -# Materials. If you do not have a copy of the Software License Agreement, contact your AMD -# representative for a copy. -# -# You agree that you will not reverse engineer or decompile the Materials, in whole or in part, except for -# example code which is provided in source code form and as allowed by applicable law. -# -# WARRANTY DISCLAIMER: THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY -# KIND. AMD DISCLAIMS ALL WARRANTIES, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING BUT NOT -# LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR -# PURPOSE, TITLE, NON-INFRINGEMENT, THAT THE SOFTWARE WILL RUN UNINTERRUPTED OR ERROR- -# FREE OR WARRANTIES ARISING FROM CUSTOM OF TRADE OR COURSE OF USAGE. THE ENTIRE RISK -# ASSOCIATED WITH THE USE OF THE SOFTWARE IS ASSUMED BY YOU. Some jurisdictions do not -# allow the exclusion of implied warranties, so the above exclusion may not apply to You. -# -# LIMITATION OF LIABILITY AND INDEMNIFICATION: AMD AND ITS LICENSORS WILL NOT, -# UNDER ANY CIRCUMSTANCES BE LIABLE TO YOU FOR ANY PUNITIVE, DIRECT, INCIDENTAL, -# INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES ARISING FROM USE OF THE SOFTWARE OR THIS -# AGREEMENT EVEN IF AMD AND ITS LICENSORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH -# DAMAGES. In no event shall AMD's total liability to You for all damages, losses, and -# causes of action (whether in contract, tort (including negligence) or otherwise) -# exceed the amount of $100 USD. You agree to defend, indemnify and hold harmless -# AMD and its licensors, and any of their directors, officers, employees, affiliates or -# agents from and against any and all loss, damage, liability and other expenses -# (including reasonable attorneys' fees), resulting from Your use of the Software or -# violation of the terms and conditions of this Agreement. -# -# U.S. GOVERNMENT RESTRICTED RIGHTS: The Materials are provided with "RESTRICTED RIGHTS." -# Use, duplication, or disclosure by the Government is subject to the restrictions as set -# forth in FAR 52.227-14 and DFAR252.227-7013, et seq., or its successor. Use of the -# Materials by the Government constitutes acknowledgement of AMD's proprietary rights in them. -# -# EXPORT RESTRICTIONS: The Materials may be subject to export restrictions as stated in the -# Software License Agreement. -# - -INPUTDIR=$1 -if [ -z $INPUTDIR ] ; then - INPUTDIR=$PWD -fi - -# These are the input files -AOT_PCIID2CODENAME="$INPUTDIR/amdgpu/pciid2codename.txt $INPUTDIR/nvidia/pciid2codename.txt" -AOT_CODENAME2OFFLOADARCH="$INPUTDIR/amdgpu/codename2offloadarch.txt $INPUTDIR/nvidia/codename2offloadarch.txt" -AOT_CODENAME2OFFLOADARCH_AMD="$INPUTDIR/amdgpu/codename2offloadarch.txt" - -# This is the output file which is always written to current dir -AOT_DOTH_FILE="$PWD/generated_offload_arch.h" - -function get_offloadarch_id_from_codename -{ - _codename=$1 - _entry=`grep -m1 "^$_codename" $AOT_CODENAME2OFFLOADARCH` - if [ $? == 0 ] ; then - _offloadarchid=`echo $_entry | awk '{print $2}'` - else - _offloadarchid="$_codename" - fi - echo $_offloadarchid -} - -function write_AOT_OFFLOADARCH() -{ - echo "typedef enum {" >> $AOT_DOTH_FILE - cat $AOT_CODENAME2OFFLOADARCH | cut -d" " -f2 | sort -u > $aot_tmpfile - while read -r line ; do - echo " AOT_${line^^}," >> $AOT_DOTH_FILE - done < $aot_tmpfile - echo "} AOT_OFFLOADARCH;" >> $AOT_DOTH_FILE -} - -function write_AOT_CODENAME() -{ - echo "typedef enum {" >> $AOT_DOTH_FILE - cat $AOT_CODENAME2OFFLOADARCH | while read -r line ; do - codename=`echo $line | cut -d" " -f1` - echo " AOT_CN_${codename^^}," >> $AOT_DOTH_FILE - done - echo "} AOT_CODENAME;" >> $AOT_DOTH_FILE -} -function write_AOT_CODENAMEID_TO_STRING() -{ - echo "extern const AOT_CODENAME_ID_TO_STRING AOT_CODENAMES[] = {" >>$AOT_DOTH_FILE - cat $AOT_CODENAME2OFFLOADARCH | while read -r line ; do - codename=`echo $line | cut -d" " -f1` - echo " {AOT_CN_${codename^^}, \"${codename}\"}," >> $AOT_DOTH_FILE - done - echo "};" >> $AOT_DOTH_FILE -} -function write_AOT_OFFLOADARCH_TO_STRING() -{ - echo "extern const AOT_OFFLOADARCH_TO_STRING AOT_OFFLOADARCHS[] = {" >>$AOT_DOTH_FILE - cat $AOT_CODENAME2OFFLOADARCH | cut -d" " -f2 | sort -u > $aot_tmpfile - while read -r line ; do - echo " {AOT_${line^^}, \"${line}\"}," >> $AOT_DOTH_FILE - done < $aot_tmpfile - echo "};" >> $AOT_DOTH_FILE -} - -function write_AOT_PROLOG() -{ -cat 2>&1 <<"EOF" > $aot_tmpfile -// This file is generated by make_generated_offload_arch_h.sh -// It is only included by OffloadArch.cpp -#include -#include -EOF -cat $aot_tmpfile >> $AOT_DOTH_FILE -} - -function write_AOT_STRUCTS() -{ -cat 2>&1 <<"EOF" > $aot_tmpfile - -struct AOT_CODENAME_ID_TO_STRING{ - AOT_CODENAME codename_id; - const char* codename; -}; - -struct AOT_OFFLOADARCH_TO_STRING{ - AOT_OFFLOADARCH offloadarch_id; - const char* offloadarch; -}; - -struct AOT_OFFLOADARCH_TO_CODENAME_ENTRY{ - const char* offloadarch; - const char* codename; -}; - -struct AOT_TABLE_ENTRY{ - uint16_t vendorid; - uint16_t devid; - AOT_CODENAME codename_id; - AOT_OFFLOADARCH offloadarch_id; -}; -EOF -cat $aot_tmpfile >> $AOT_DOTH_FILE -} - -function write_AMD_OFFLOADARCH_TO_CODENAME_TABLE() -{ - echo " " >> $AOT_DOTH_FILE - echo "extern const AOT_OFFLOADARCH_TO_CODENAME_ENTRY AOT_AMD_OFFLOADARCH_TO_CODENAME_TABLE[] = {" >> $AOT_DOTH_FILE - cat $AOT_CODENAME2OFFLOADARCH_AMD | sort -u -t" " -k2 > $aot_tmpfile - while read -r line ; do - echo $line - codename=`echo $line | cut -d " " -f1` - offloadarch=`echo $line | cut -d " " -f2` - echo "{ \"${offloadarch}\", \"${codename}\" }," >>$AOT_DOTH_FILE - done < $aot_tmpfile - echo "};" >> $AOT_DOTH_FILE - echo " " >> $AOT_DOTH_FILE -} - -function write_AOT_TABLE() -{ - echo "extern const AOT_TABLE_ENTRY AOT_TABLE[] = {" >>$AOT_DOTH_FILE - cat $AOT_PCIID2CODENAME | sort -u -t" " -k1 > $aot_tmpfile - while read -r line ; do - codename=`echo $line | cut -d" " -f4` - # only proceed if we know about this codename - grep -q "^$codename " $AOT_CODENAME2OFFLOADARCH - if [ $? == 0 ] ; then - vid=`echo $line | cut -d":" -f1` - devid=`echo $line | cut -d" " -f1 | cut -d":" -f2` - offloadarchid=$(get_offloadarch_id_from_codename $codename) - echo "{ 0x${vid}, 0x${devid}, AOT_CN_${codename^^}, AOT_${offloadarchid^^} }," >>$AOT_DOTH_FILE - fi - done < $aot_tmpfile - echo "};" >> $AOT_DOTH_FILE - echo " " >> $AOT_DOTH_FILE -} - -# =========== Main code starts here ====================== - -# we dont want to append to existing file -[ -f $AOT_DOTH_FILE ] && rm $AOT_DOTH_FILE -touch $AOT_DOTH_FILE - -aot_tmpfile="/tmp/zz$$" - -write_AOT_PROLOG -write_AOT_OFFLOADARCH -write_AOT_CODENAME -write_AOT_STRUCTS -write_AOT_CODENAMEID_TO_STRING -write_AOT_OFFLOADARCH_TO_STRING -write_AMD_OFFLOADARCH_TO_CODENAME_TABLE -write_AOT_TABLE - -rm $aot_tmpfile - -exit 0