Merged
[Feat][sk/aot]support dav-2201 and dav-3510 builds for sk_entry and sk_scope #430
sjtulxhAdd on May 21
[Feat][sk/aot]support dav-2201 and dav-3510 builds for sk_entry and sk_scope #430
Merged
Merged fromsjtulxh/graph-autofusionmasterintocann/graph-autofusionmaster
Total: 7 files changed+198-63
| @@ -62,7 +62,7 @@ target_include_directories(ascendsk PUBLIC | |||
| 62 | ${CMAKE_CURRENT_SOURCE_DIR}/src/aot | 62 | ${CMAKE_CURRENT_SOURCE_DIR}/src/aot |
| 63 | ) | 63 | ) |
| 64 | target_link_libraries(ascendsk PRIVATE c_sec_headers runtime_headers) | 64 | target_link_libraries(ascendsk PRIVATE c_sec_headers runtime_headers) |
| 65 | -target_link_libraries(ascendsk PUBLIC sk_scope acl_rt acl_rtc ascendcl ascend_dump runtime error_manager c_sec unified_dlog ascendc_runtime profapi profimpl msprofiler json) | 65 | +target_link_libraries(ascendsk PUBLIC sk_scope_dav_2201 sk_scope_dav_3510 acl_rt acl_rtc ascendcl ascend_dump runtime error_manager c_sec unified_dlog ascendc_runtime profapi profimpl msprofiler json) |
| 66 | target_link_directories(ascendsk PUBLIC | 66 | target_link_directories(ascendsk PUBLIC |
| 67 | $ENV{ASCEND_HOME_PATH}/lib64 | 67 | $ENV{ASCEND_HOME_PATH}/lib64 |
| 68 | ) | 68 | ) |
| @@ -7,27 +7,41 @@ | |||
| 7 | # See LICENSE in the root of the software repository for the full text of the License. | 7 | # See LICENSE in the root of the software repository for the full text of the License. |
| 8 | # ====================================================================================================================== | 8 | # ====================================================================================================================== |
| 9 | 9 | ||
| 10 | -ascendc_fatbin_library(sk_entry sk_entry.asc) | 10 | +set(SK_KERNEL_ARCHS dav-2201 dav-3510) |
| 11 | -target_compile_options(sk_entry PRIVATE | 11 | +set(SK_ENTRY_STUB_INPUTS) |
| 12 | - $<$<COMPILE_LANGUAGE:ASC>:--npu-arch=dav-2201> | 12 | +set(SK_ENTRY_OBJECTS) |
| 13 | - $<$<COMPILE_LANGUAGE:ASC>:-D__ASCENDC_SUPERKERNEL_EARLY_START_V2> | 13 | +set(SK_ENTRY_TARGETS) |
| 14 | -) | ||
| 15 | 14 | ||
| 16 | -target_include_directories(sk_entry PRIVATE | 15 | +foreach(SK_KERNEL_ARCH IN LISTS SK_KERNEL_ARCHS) |
| 17 | - $<$<COMPILE_LANGUAGE:ASC>:${CMAKE_CURRENT_SOURCE_DIR}/../src/aot/> | 16 | + string(REPLACE "-" "_" SK_KERNEL_ARCH_SUFFIX ${SK_KERNEL_ARCH}) |
| 18 | -) | 17 | + set(SK_ENTRY_TARGET sk_entry_${SK_KERNEL_ARCH_SUFFIX}) |
| 19 | 18 | ||
| 20 | -set(SK_ENTRY_OBJECT ${CMAKE_CURRENT_BINARY_DIR}/sk_entry.o) | 19 | + ascendc_fatbin_library(${SK_ENTRY_TARGET} sk_entry.asc) |
| 20 | + target_compile_options(${SK_ENTRY_TARGET} PRIVATE | ||
| 21 | + $<$<COMPILE_LANGUAGE:ASC>:--npu-arch=${SK_KERNEL_ARCH}> | ||
| 22 | + $<$<COMPILE_LANGUAGE:ASC>:-D__ASCENDC_SUPERKERNEL_EARLY_START_V2> | ||
| 23 | + ) | ||
| 24 | + | ||
| 25 | + target_include_directories(${SK_ENTRY_TARGET} PRIVATE | ||
| 26 | + $<$<COMPILE_LANGUAGE:ASC>:${CMAKE_CURRENT_SOURCE_DIR}/../src/aot/> | ||
| 27 | + ) | ||
| 28 | + | ||
| 29 | + set(SK_ENTRY_OBJECT ${CMAKE_CURRENT_BINARY_DIR}/${SK_ENTRY_TARGET}.o) | ||
| 30 | + list(APPEND SK_ENTRY_STUB_INPUTS ${SK_KERNEL_ARCH}=${SK_ENTRY_OBJECT}) | ||
| 31 | + list(APPEND SK_ENTRY_OBJECTS ${SK_ENTRY_OBJECT}) | ||
| 32 | + list(APPEND SK_ENTRY_TARGETS ${SK_ENTRY_TARGET}) | ||
| 33 | +endforeach() | ||
| 21 | 34 | ||
| 22 | add_custom_command( | 35 | add_custom_command( |
| 23 | OUTPUT ${GENERATED_SK_ENTRY_STUB_CPP} | 36 | OUTPUT ${GENERATED_SK_ENTRY_STUB_CPP} |
| 24 | COMMAND python3 ${CMAKE_CURRENT_SOURCE_DIR}/../scripts/gen_sk_entry_stub.py | 37 | COMMAND python3 ${CMAKE_CURRENT_SOURCE_DIR}/../scripts/gen_sk_entry_stub.py |
| 25 | - ${SK_ENTRY_OBJECT} | ||
| 26 | ${GENERATED_SK_ENTRY_STUB_CPP} | 38 | ${GENERATED_SK_ENTRY_STUB_CPP} |
| 39 | + ${SK_ENTRY_STUB_INPUTS} | ||
| 27 | DEPENDS | 40 | DEPENDS |
| 28 | - sk_entry | 41 | + ${SK_ENTRY_TARGETS} |
| 42 | + ${SK_ENTRY_OBJECTS} | ||
| 29 | ${CMAKE_CURRENT_SOURCE_DIR}/../scripts/gen_sk_entry_stub.py | 43 | ${CMAKE_CURRENT_SOURCE_DIR}/../scripts/gen_sk_entry_stub.py |
| 30 | - COMMENT "Generating sk_entry stub cpp from sk_entry.o" | 44 | + COMMENT "Generating sk_entry stub cpp from sk_entry objects" |
| 31 | VERBATIM | 45 | VERBATIM |
| 32 | ) | 46 | ) |
| 33 | 47 | ||
| @@ -35,14 +49,25 @@ add_custom_target(generate_entry_stub | |||
| 35 | DEPENDS ${GENERATED_SK_ENTRY_STUB_CPP} | 49 | DEPENDS ${GENERATED_SK_ENTRY_STUB_CPP} |
| 36 | ) | 50 | ) |
| 37 | 51 | ||
| 38 | -add_library(sk_scope STATIC | 52 | +foreach(SK_KERNEL_ARCH IN LISTS SK_KERNEL_ARCHS) |
| 39 | - sk_scope_kernel.asc | 53 | + string(REPLACE "-" "_" SK_KERNEL_ARCH_SUFFIX ${SK_KERNEL_ARCH}) |
| 40 | -) | 54 | + set(SK_SCOPE_TARGET sk_scope_${SK_KERNEL_ARCH_SUFFIX}) |
| 41 | 55 | ||
| 42 | -target_compile_options(sk_scope PRIVATE | 56 | + add_library(${SK_SCOPE_TARGET} STATIC |
| 43 | - $<$<COMPILE_LANGUAGE:ASC>:--npu-arch=dav-2201> | 57 | + sk_scope_kernel.asc |
| 44 | -) | 58 | + ) |
| 45 | 59 | ||
| 46 | -target_include_directories(sk_scope PRIVATE | 60 | + target_compile_options(${SK_SCOPE_TARGET} PRIVATE |
| 47 | - ${CMAKE_CURRENT_SOURCE_DIR}/../src/aot/ | 61 | + $<$<COMPILE_LANGUAGE:ASC>:--npu-arch=${SK_KERNEL_ARCH}> |
| 48 | -) | 62 | + ) |
| 63 | + | ||
| 64 | + if(NOT SK_KERNEL_ARCH STREQUAL "dav-2201") | ||
| 65 | + target_compile_definitions(${SK_SCOPE_TARGET} PRIVATE | ||
| 66 | + $<$<COMPILE_LANGUAGE:ASC>:SK_SCOPE_SYMBOL_SUFFIX=_${SK_KERNEL_ARCH_SUFFIX}> | ||
| 67 | + ) | ||
| 68 | + endif() | ||
| 69 | + | ||
| 70 | + target_include_directories(${SK_SCOPE_TARGET} PRIVATE | ||
| 71 | + ${CMAKE_CURRENT_SOURCE_DIR}/../src/aot/ | ||
| 72 | + ) | ||
| 73 | +endforeach() | ||
| @@ -140,43 +140,43 @@ __aicore__ inline void AutoCoreSyncImpl(SkCoreSyncType sync_type) { | |||
| 140 | switch (sync_type) { | 140 | switch (sync_type) { |
| 141 | case SkCoreSyncType::CROSS_SYNC_AIC_TO_AIC: | 141 | case SkCoreSyncType::CROSS_SYNC_AIC_TO_AIC: |
| 142 | if ASCEND_IS_AIC { | 142 | if ASCEND_IS_AIC { |
| 143 | - ffts_cross_core_sync(PIPE_FIX, AscendC::GetffstMsg(0x0, AscendC::SYNC_AIC_FLAG)); | 143 | + CrossCoreSetFlag<0x0, PIPE_FIX>(AscendC::SYNC_AIC_FLAG); |
| 144 | - wait_flag_dev(AscendC::SYNC_AIC_FLAG); | 144 | + CrossCoreWaitFlag(AscendC::SYNC_AIC_FLAG); |
| 145 | } | 145 | } |
| 146 | return; | 146 | return; |
| 147 | case SkCoreSyncType::CROSS_SYNC_AIV_TO_AIV: | 147 | case SkCoreSyncType::CROSS_SYNC_AIV_TO_AIV: |
| 148 | if ASCEND_IS_AIV { | 148 | if ASCEND_IS_AIV { |
| 149 | - ffts_cross_core_sync(PIPE_MTE3, AscendC::GetffstMsg(0x0, AscendC::SYNC_AIV_ONLY_ALL)); | 149 | + CrossCoreSetFlag<0x0, PIPE_MTE3>(AscendC::SYNC_AIV_ONLY_ALL); |
| 150 | - wait_flag_dev(AscendC::SYNC_AIV_ONLY_ALL); | 150 | + CrossCoreWaitFlag(AscendC::SYNC_AIV_ONLY_ALL); |
| 151 | } | 151 | } |
| 152 | return; | 152 | return; |
| 153 | case SkCoreSyncType::INTER_SYNC_SET_AIC_TO_AIV: | 153 | case SkCoreSyncType::INTER_SYNC_SET_AIC_TO_AIV: |
| 154 | if ASCEND_IS_AIC { | 154 | if ASCEND_IS_AIC { |
| 155 | - ffts_cross_core_sync(PIPE_MTE3, AscendC::GetffstMsg(0x02, AscendC::SYNC_AIC_AIV_FLAG)); | 155 | + CrossCoreSetFlag<0x02, PIPE_MTE3>(AscendC::SYNC_AIC_AIV_FLAG); |
| 156 | } | 156 | } |
| 157 | return; | 157 | return; |
| 158 | case SkCoreSyncType::INTER_SYNC_SET_AIV_TO_AIC: | 158 | case SkCoreSyncType::INTER_SYNC_SET_AIV_TO_AIC: |
| 159 | if ASCEND_IS_AIV { | 159 | if ASCEND_IS_AIV { |
| 160 | - ffts_cross_core_sync(PIPE_MTE3, AscendC::GetffstMsg(0x02, AscendC::SYNC_AIV_FLAG)); | 160 | + CrossCoreSetFlag<0x02, PIPE_MTE3>(AscendC::SYNC_AIV_FLAG); |
| 161 | } | 161 | } |
| 162 | return; | 162 | return; |
| 163 | case SkCoreSyncType::INTER_SYNC_WAIT_AIC_TO_AIV: | 163 | case SkCoreSyncType::INTER_SYNC_WAIT_AIC_TO_AIV: |
| 164 | if ASCEND_IS_AIV { | 164 | if ASCEND_IS_AIV { |
| 165 | - wait_flag_dev(AscendC::SYNC_AIC_AIV_FLAG); | 165 | + CrossCoreWaitFlag(AscendC::SYNC_AIC_AIV_FLAG); |
| 166 | } | 166 | } |
| 167 | return; | 167 | return; |
| 168 | case SkCoreSyncType::INTER_SYNC_WAIT_AIV_TO_AIC: | 168 | case SkCoreSyncType::INTER_SYNC_WAIT_AIV_TO_AIC: |
| 169 | if ASCEND_IS_AIC { | 169 | if ASCEND_IS_AIC { |
| 170 | - wait_flag_dev(AscendC::SYNC_AIV_FLAG); | 170 | + CrossCoreWaitFlag(AscendC::SYNC_AIV_FLAG); |
| 171 | } | 171 | } |
| 172 | return; | 172 | return; |
| 173 | default: | 173 | default: |
| 174 | if constexpr (aic == 1 && aiv == 0) { | 174 | if constexpr (aic == 1 && aiv == 0) { |
| 175 | - ffts_cross_core_sync(PIPE_FIX, AscendC::GetffstMsg(0x0, AscendC::SYNC_AIC_FLAG)); | 175 | + CrossCoreSetFlag<0x0, PIPE_FIX>(AscendC::SYNC_AIC_FLAG); |
| 176 | - wait_flag_dev(AscendC::SYNC_AIC_FLAG); | 176 | + CrossCoreWaitFlag(AscendC::SYNC_AIC_FLAG); |
| 177 | } else if constexpr (aic == 0 && aiv==1) { | 177 | } else if constexpr (aic == 0 && aiv==1) { |
| 178 | - ffts_cross_core_sync(PIPE_MTE3, AscendC::GetffstMsg(0x0, AscendC::SYNC_AIV_ONLY_ALL)); | 178 | + CrossCoreSetFlag<0x0, PIPE_MTE3>(AscendC::SYNC_AIV_ONLY_ALL); |
| 179 | - wait_flag_dev(AscendC::SYNC_AIV_ONLY_ALL); | 179 | + CrossCoreWaitFlag(AscendC::SYNC_AIV_ONLY_ALL); |
| 180 | } else { | 180 | } else { |
| 181 | AscendC::SyncAll<false>(); | 181 | AscendC::SyncAll<false>(); |
| 182 | } | 182 | } |
| @@ -342,11 +342,11 @@ __aicore__ inline void spk_entry_impl(GM_ADDR skDevArgs) { | |||
| 342 | if constexpr(enable_debug) { | 342 | if constexpr(enable_debug) { |
| 343 | if ((task->debugOptions & 0x2) != 0) { | 343 | if ((task->debugOptions & 0x2) != 0) { |
| 344 | if constexpr (aic == 1 && aiv == 0) { | 344 | if constexpr (aic == 1 && aiv == 0) { |
| 345 | - ffts_cross_core_sync(PIPE_FIX, AscendC::GetffstMsg(0x0, AscendC::SYNC_AIC_FLAG)); | 345 | + AscendC::CrossCoreSetFlag<0x0, PIPE_FIX>(AscendC::SYNC_AIC_FLAG); |
| 346 | - wait_flag_dev(AscendC::SYNC_AIC_FLAG); | 346 | + AscendC::CrossCoreWaitFlag(AscendC::SYNC_AIC_FLAG); |
| 347 | } else if constexpr (aic == 0 && aiv==1) { | 347 | } else if constexpr (aic == 0 && aiv==1) { |
| 348 | - ffts_cross_core_sync(PIPE_MTE3, AscendC::GetffstMsg(0x0, AscendC::SYNC_AIV_ONLY_ALL)); | 348 | + AscendC::CrossCoreSetFlag<0x0, PIPE_MTE3>(AscendC::SYNC_AIV_ONLY_ALL); |
| 349 | - wait_flag_dev(AscendC::SYNC_AIV_ONLY_ALL); | 349 | + AscendC::CrossCoreWaitFlag(AscendC::SYNC_AIV_ONLY_ALL); |
| 350 | } else { | 350 | } else { |
| 351 | AscendC::SyncAll<false>(); | 351 | AscendC::SyncAll<false>(); |
| 352 | } | 352 | } |
| @@ -16,26 +16,35 @@ | |||
| 16 | #include "kernel_operator.h" | 16 | #include "kernel_operator.h" |
| 17 | #include "sk_scope_kernel_types.h" | 17 | #include "sk_scope_kernel_types.h" |
| 18 | 18 | ||
| 19 | -extern "C" __global__ __vector__ void sk_scope_kernel_begin(ScopeKernelArgs args) { | 19 | +#define SK_SCOPE_CONCAT_INNER(a, b) a##b |
| 20 | +#define SK_SCOPE_CONCAT(a, b) SK_SCOPE_CONCAT_INNER(a, b) | ||
| 21 | + | ||
| 22 | +#ifdef SK_SCOPE_SYMBOL_SUFFIX | ||
| 23 | +#define SK_SCOPE_SYMBOL(name) SK_SCOPE_CONCAT(name, SK_SCOPE_SYMBOL_SUFFIX) | ||
| 24 | +#else | ||
| 25 | +#define SK_SCOPE_SYMBOL(name) name | ||
| 26 | +#endif | ||
| 27 | + | ||
| 28 | +extern "C" __global__ __vector__ void SK_SCOPE_SYMBOL(sk_scope_kernel_begin)(ScopeKernelArgs args) { | ||
| 20 | } | 29 | } |
| 21 | 30 | ||
| 22 | -extern "C" __global__ __vector__ void sk_scope_kernel_end(ScopeKernelArgs args) { | 31 | +extern "C" __global__ __vector__ void SK_SCOPE_SYMBOL(sk_scope_kernel_end)(ScopeKernelArgs args) { |
| 23 | } | 32 | } |
| 24 | 33 | ||
| 25 | -extern "C" __global__ __vector__ void sk_placeholder_kernel(ScopeKernelArgs args) { | 34 | +extern "C" __global__ __vector__ void SK_SCOPE_SYMBOL(sk_placeholder_kernel)(ScopeKernelArgs args) { |
| 26 | } | 35 | } |
| 27 | 36 | ||
| 28 | -extern "C" void sk_scope_kernel_begin_do(void* stream, ScopeKernelArgs args) | 37 | +extern "C" void SK_SCOPE_SYMBOL(sk_scope_kernel_begin_do)(void* stream, ScopeKernelArgs args) |
| 29 | { | 38 | { |
| 30 | - sk_scope_kernel_begin<<<1, nullptr, stream>>>(args); | 39 | + SK_SCOPE_SYMBOL(sk_scope_kernel_begin)<<<1, nullptr, stream>>>(args); |
| 31 | } | 40 | } |
| 32 | 41 | ||
| 33 | -extern "C" void sk_scope_kernel_end_do(void* stream, ScopeKernelArgs args) | 42 | +extern "C" void SK_SCOPE_SYMBOL(sk_scope_kernel_end_do)(void* stream, ScopeKernelArgs args) |
| 34 | { | 43 | { |
| 35 | - sk_scope_kernel_end<<<1, nullptr, stream>>>(args); | 44 | + SK_SCOPE_SYMBOL(sk_scope_kernel_end)<<<1, nullptr, stream>>>(args); |
| 36 | } | 45 | } |
| 37 | 46 | ||
| 38 | -extern "C" void sk_placeholder_kernel_do(void* stream, ScopeKernelArgs args) | 47 | +extern "C" void SK_SCOPE_SYMBOL(sk_placeholder_kernel_do)(void* stream, ScopeKernelArgs args) |
| 39 | { | 48 | { |
| 40 | - sk_placeholder_kernel<<<1, nullptr, stream>>>(args); | 49 | + SK_SCOPE_SYMBOL(sk_placeholder_kernel)<<<1, nullptr, stream>>>(args); |
| 41 | } | 50 | } |
| @@ -31,7 +31,7 @@ def get_file_content(file): | |||
| 31 | return data | 31 | return data |
| 32 | 32 | ||
| 33 | 33 | ||
| 34 | -def gen_code(bin_file, src): | 34 | +def gen_buffer_code(bin_file, symbol): |
| 35 | file_size = os.path.getsize(bin_file) | 35 | file_size = os.path.getsize(bin_file) |
| 36 | if file_size % 8 != 0: | 36 | if file_size % 8 != 0: |
| 37 | raise ValueError(f"Binary file {bin_file} (size: {file_size}) must be 8-byte aligned.") | 37 | raise ValueError(f"Binary file {bin_file} (size: {file_size}) must be 8-byte aligned.") |
| @@ -41,7 +41,22 @@ def gen_code(bin_file, src): | |||
| 41 | for i in range(0, len(data), 8) | 41 | for i in range(0, len(data), 8) |
| 42 | ] | 42 | ] |
| 43 | data_lines = ",\n".join(formatted_data) | 43 | data_lines = ",\n".join(formatted_data) |
| 44 | + return f'''static const uint64_t {symbol}[{len(data)}] __attribute__ ((section (".sk.kernel"))) = {{ | ||
| 45 | +{data_lines} | ||
| 46 | +}}; | ||
| 47 | +''', len(data) | ||
| 44 | 48 | ||
| 49 | + | ||
| 50 | +def gen_code(bin_files, src): | ||
| 51 | + buffer_defs = [] | ||
| 52 | + bin_entries = [] | ||
| 53 | + for arch, bin_file in bin_files: | ||
| 54 | + symbol = "__aicore_file_buf_" + arch.replace("-", "_") | ||
| 55 | + buffer_code, data_len = gen_buffer_code(bin_file, symbol) | ||
| 56 | + buffer_defs.append(buffer_code) | ||
| 57 | + bin_entries.append(f' {{"{arch}", {symbol}, sizeof({symbol})}}') | ||
| 58 | + bin_entry_lines = ",\n".join(bin_entries) | ||
| 59 | + handle_init = ", ".join(["nullptr"] * len(bin_files)) | ||
| 45 | code = f'''#include <acl/acl.h> | 60 | code = f'''#include <acl/acl.h> |
| 46 | #include <cstdint> | 61 | #include <cstdint> |
| 47 | #include <cstdlib> | 62 | #include <cstdlib> |
| @@ -71,17 +86,52 @@ static aclrtBinHandle AscendLoadBinaryFromBuffer(const uint64_t *aicoreFileBuf, | |||
| 71 | return bhdl; | 86 | return bhdl; |
| 72 | }} | 87 | }} |
| 73 | 88 | ||
| 74 | -static const uint64_t __aicore_file_buf__[{len(data)}] __attribute__ ((section (".sk.kernel"))) = {{ | 89 | +struct SkEntryBinary {{ |
| 75 | -{data_lines} | 90 | + const char *arch; |
| 91 | + const uint64_t *data; | ||
| 92 | + size_t size; | ||
| 76 | }}; | 93 | }}; |
| 77 | 94 | ||
| 95 | +{os.linesep.join(buffer_defs)} | ||
| 96 | + | ||
| 97 | +static const SkEntryBinary g_sk_entry_bins[] = {{ | ||
| 98 | +{bin_entry_lines} | ||
| 99 | +}}; | ||
| 100 | + | ||
| 101 | +static const char *GetSkEntryArch() | ||
| 102 | +{{ | ||
| 103 | + const char *socName = aclrtGetSocName(); | ||
| 104 | + if (socName != nullptr && strstr(socName, "Ascend950") != nullptr) {{ | ||
| 105 | + return "dav-3510"; | ||
| 106 | + }} | ||
| 107 | + return "dav-2201"; | ||
| 108 | +}} | ||
| 109 | + | ||
| 110 | +static size_t GetSkEntryBinIndex() | ||
| 111 | +{{ | ||
| 112 | + const char *targetArch = GetSkEntryArch(); | ||
| 113 | + constexpr size_t binCount = sizeof(g_sk_entry_bins) / sizeof(g_sk_entry_bins[0]); | ||
| 114 | + for (size_t i = 0; i < binCount; ++i) {{ | ||
| 115 | + if (strcmp(g_sk_entry_bins[i].arch, targetArch) == 0) {{ | ||
| 116 | + return i; | ||
| 117 | + }} | ||
| 118 | + }} | ||
| 119 | + SK_LOGW("No sk_entry binary for arch %s, fallback to %s", targetArch, g_sk_entry_bins[0].arch); | ||
| 120 | + return 0; | ||
| 121 | +}} | ||
| 122 | + | ||
| 78 | aclrtBinHandle AscendGetEntryBinHandle() | 123 | aclrtBinHandle AscendGetEntryBinHandle() |
| 79 | {{ | 124 | {{ |
| 80 | - static thread_local aclrtBinHandle __sk_bin_handle__ = nullptr; | 125 | + static thread_local aclrtBinHandle __sk_bin_handles__[{len(bin_files)}] = {{{handle_init}}}; |
| 81 | - if (__sk_bin_handle__ == nullptr) {{ | 126 | + size_t binIndex = GetSkEntryBinIndex(); |
| 82 | - __sk_bin_handle__ = AscendLoadBinaryFromBuffer(__aicore_file_buf__, sizeof(__aicore_file_buf__)); | 127 | + if (binIndex >= sizeof(g_sk_entry_bins) / sizeof(g_sk_entry_bins[0])) {{ |
| 128 | + binIndex = 0; | ||
| 83 | }} | 129 | }} |
| 84 | - return __sk_bin_handle__; | 130 | + if (__sk_bin_handles__[binIndex] == nullptr) {{ |
| 131 | + const SkEntryBinary &bin = g_sk_entry_bins[binIndex]; | ||
| 132 | + __sk_bin_handles__[binIndex] = AscendLoadBinaryFromBuffer(bin.data, bin.size); | ||
| 133 | + }} | ||
| 134 | + return __sk_bin_handles__[binIndex]; | ||
| 85 | }} | 135 | }} |
| 86 | 136 | ||
| 87 | #ifdef __cplusplus | 137 | #ifdef __cplusplus |
| @@ -97,6 +147,14 @@ aclrtBinHandle AscendGetEntryBinHandle() | |||
| 97 | 147 | ||
| 98 | 148 | ||
| 99 | if __name__ == '__main__': | 149 | if __name__ == '__main__': |
| 100 | - bin_file = sys.argv[1] | 150 | + if len(sys.argv) == 3: |
| 101 | - src_file = sys.argv[2] | 151 | + bin_file = sys.argv[1] |
| 102 | - gen_code(bin_file, src_file) | 152 | + src_file = sys.argv[2] |
| 153 | + gen_code([("dav-2201", bin_file)], src_file) | ||
| 154 | + else: | ||
| 155 | + src_file = sys.argv[1] | ||
| 156 | + bin_files = [] | ||
| 157 | + for arg in sys.argv[2:]: | ||
| 158 | + arch, bin_file = arg.split('=', 1) | ||
| 159 | + bin_files.append((arch, bin_file)) | ||
| 160 | + gen_code(bin_files, src_file) | ||
| @@ -24,11 +24,35 @@ | |||
| 24 | extern "C" void sk_scope_kernel_begin_do(void* stream, ScopeKernelArgs args); | 24 | extern "C" void sk_scope_kernel_begin_do(void* stream, ScopeKernelArgs args); |
| 25 | extern "C" void sk_scope_kernel_end_do(void* stream, ScopeKernelArgs args); | 25 | extern "C" void sk_scope_kernel_end_do(void* stream, ScopeKernelArgs args); |
| 26 | extern "C" void sk_placeholder_kernel_do(void* stream, ScopeKernelArgs args); | 26 | extern "C" void sk_placeholder_kernel_do(void* stream, ScopeKernelArgs args); |
| 27 | +extern "C" void sk_scope_kernel_begin_do_dav_3510(void* stream, ScopeKernelArgs args); | ||
| 28 | +extern "C" void sk_scope_kernel_end_do_dav_3510(void* stream, ScopeKernelArgs args); | ||
| 29 | +extern "C" void sk_placeholder_kernel_do_dav_3510(void* stream, ScopeKernelArgs args); | ||
| 27 | 30 | ||
| 28 | typedef void (*ScopeFuncImpl)(void*, ScopeKernelArgs); | 31 | typedef void (*ScopeFuncImpl)(void*, ScopeKernelArgs); |
| 29 | 32 | ||
| 30 | namespace { | 33 | namespace { |
| 31 | 34 | ||
| 35 | +struct ScopeKernelImpls { | ||
| 36 | + ScopeFuncImpl begin; | ||
| 37 | + ScopeFuncImpl end; | ||
| 38 | + ScopeFuncImpl placeholder; | ||
| 39 | +}; | ||
| 40 | + | ||
| 41 | +bool IsDav3510Soc() | ||
| 42 | +{ | ||
| 43 | + const char* socName = aclrtGetSocName(); | ||
| 44 | + return socName != nullptr && strstr(socName, "Ascend950") != nullptr; | ||
| 45 | +} | ||
| 46 | + | ||
| 47 | +ScopeKernelImpls GetScopeKernelImpls() | ||
| 48 | +{ | ||
| 49 | + if (IsDav3510Soc()) { | ||
| 50 | + return {sk_scope_kernel_begin_do_dav_3510, sk_scope_kernel_end_do_dav_3510, | ||
| 51 | + sk_placeholder_kernel_do_dav_3510}; | ||
| 52 | + } | ||
| 53 | + return {sk_scope_kernel_begin_do, sk_scope_kernel_end_do, sk_placeholder_kernel_do}; | ||
| 54 | +} | ||
| 55 | + | ||
| 32 | aclError LaunchScopeKernelImpl(const char* scopeName, aclrtStream stream, ScopeFuncImpl scopeKernelImpl) { | 56 | aclError LaunchScopeKernelImpl(const char* scopeName, aclrtStream stream, ScopeFuncImpl scopeKernelImpl) { |
| 33 | ScopeKernelArgs args; | 57 | ScopeKernelArgs args; |
| 34 | if (scopeName == nullptr) { | 58 | if (scopeName == nullptr) { |
| @@ -55,19 +79,20 @@ aclError LaunchScopeKernelImpl(const char* scopeName, aclrtStream stream, ScopeF | |||
| 55 | 79 | ||
| 56 | aclError LaunchScopeKernel(const char* scopeName, aclrtStream stream, bool isBegin) | 80 | aclError LaunchScopeKernel(const char* scopeName, aclrtStream stream, bool isBegin) |
| 57 | { | 81 | { |
| 82 | + ScopeKernelImpls impls = GetScopeKernelImpls(); | ||
| 58 | if (isBegin) { | 83 | if (isBegin) { |
| 59 | SK_LOGI("aclskScopeBegin kernel and placeholder kernel launch start!"); | 84 | SK_LOGI("aclskScopeBegin kernel and placeholder kernel launch start!"); |
| 60 | - aclError ret = LaunchScopeKernelImpl(scopeName, stream, sk_scope_kernel_begin_do); | 85 | + aclError ret = LaunchScopeKernelImpl(scopeName, stream, impls.begin); |
| 61 | if (ret != ACL_SUCCESS) { | 86 | if (ret != ACL_SUCCESS) { |
| 62 | SK_LOGE("LaunchScopeKernelImpl failed, scopeBegin kernel launch failed, ret: %d", ret); | 87 | SK_LOGE("LaunchScopeKernelImpl failed, scopeBegin kernel launch failed, ret: %d", ret); |
| 63 | return ret; | 88 | return ret; |
| 64 | } | 89 | } |
| 65 | - ret = LaunchScopeKernelImpl(scopeName, stream, sk_placeholder_kernel_do); | 90 | + ret = LaunchScopeKernelImpl(scopeName, stream, impls.placeholder); |
| 66 | if (ret != ACL_SUCCESS) { | 91 | if (ret != ACL_SUCCESS) { |
| 67 | SK_LOGE("LaunchScopeKernelImpl failed, placeholder kernel launch failed, ret: %d", ret); | 92 | SK_LOGE("LaunchScopeKernelImpl failed, placeholder kernel launch failed, ret: %d", ret); |
| 68 | return ret; | 93 | return ret; |
| 69 | } | 94 | } |
| 70 | - ret = LaunchScopeKernelImpl(scopeName, stream, sk_placeholder_kernel_do); | 95 | + ret = LaunchScopeKernelImpl(scopeName, stream, impls.placeholder); |
| 71 | if (ret != ACL_SUCCESS) { | 96 | if (ret != ACL_SUCCESS) { |
| 72 | SK_LOGE("LaunchScopeKernelImpl failed, placeholder kernel launch failed, ret: %d", ret); | 97 | SK_LOGE("LaunchScopeKernelImpl failed, placeholder kernel launch failed, ret: %d", ret); |
| 73 | return ret; | 98 | return ret; |
| @@ -76,17 +101,17 @@ aclError LaunchScopeKernel(const char* scopeName, aclrtStream stream, bool isBeg | |||
| 76 | return ret; | 101 | return ret; |
| 77 | } else { | 102 | } else { |
| 78 | SK_LOGI("aclskScopeEnd kernel and placeholder kernel launch start! "); | 103 | SK_LOGI("aclskScopeEnd kernel and placeholder kernel launch start! "); |
| 79 | - aclError ret = LaunchScopeKernelImpl(scopeName, stream, sk_placeholder_kernel_do); | 104 | + aclError ret = LaunchScopeKernelImpl(scopeName, stream, impls.placeholder); |
| 80 | if (ret != ACL_SUCCESS) { | 105 | if (ret != ACL_SUCCESS) { |
| 81 | SK_LOGE("LaunchScopeKernelImpl failed, placeholder kernel launch failed, ret: %d", ret); | 106 | SK_LOGE("LaunchScopeKernelImpl failed, placeholder kernel launch failed, ret: %d", ret); |
| 82 | return ret; | 107 | return ret; |
| 83 | } | 108 | } |
| 84 | - ret = LaunchScopeKernelImpl(scopeName, stream, sk_placeholder_kernel_do); | 109 | + ret = LaunchScopeKernelImpl(scopeName, stream, impls.placeholder); |
| 85 | if (ret != ACL_SUCCESS) { | 110 | if (ret != ACL_SUCCESS) { |
| 86 | SK_LOGE("LaunchScopeKernelImpl failed, placeholder kernel launch failed, ret: %d", ret); | 111 | SK_LOGE("LaunchScopeKernelImpl failed, placeholder kernel launch failed, ret: %d", ret); |
| 87 | return ret; | 112 | return ret; |
| 88 | } | 113 | } |
| 89 | - ret = LaunchScopeKernelImpl(scopeName, stream, sk_scope_kernel_end_do); | 114 | + ret = LaunchScopeKernelImpl(scopeName, stream, impls.end); |
| 90 | if (ret != ACL_SUCCESS) { | 115 | if (ret != ACL_SUCCESS) { |
| 91 | SK_LOGE("LaunchScopeKernelImpl failed, scopeEnd kernel launch failed, ret: %d", ret); | 116 | SK_LOGE("LaunchScopeKernelImpl failed, scopeEnd kernel launch failed, ret: %d", ret); |
| 92 | return ret; | 117 | return ret; |
| @@ -418,4 +418,22 @@ void sk_placeholder_kernel_do(void* stream, ScopeKernelArgs args) | |||
| 418 | (void)args; | 418 | (void)args; |
| 419 | } | 419 | } |
| 420 | 420 | ||
| 421 | +void sk_scope_kernel_begin_do_dav_3510(void* stream, ScopeKernelArgs args) | ||
| 422 | +{ | ||
| 423 | + (void)stream; | ||
| 424 | + (void)args; | ||
| 425 | +} | ||
| 426 | + | ||
| 427 | +void sk_scope_kernel_end_do_dav_3510(void* stream, ScopeKernelArgs args) | ||
| 428 | +{ | ||
| 429 | + (void)stream; | ||
| 430 | + (void)args; | ||
| 431 | +} | ||
| 432 | + | ||
| 433 | +void sk_placeholder_kernel_do_dav_3510(void* stream, ScopeKernelArgs args) | ||
| 434 | +{ | ||
| 435 | + (void)stream; | ||
| 436 | + (void)args; | ||
| 437 | +} | ||
| 438 | + | ||
| 421 | } // extern "C" | 439 | } // extern "C" |
🟡 Medium Priority
GetSkEntryBinIndex() 硬编码返回 1(匹配 "Ascend950")或 0(默认),假设 bin_files[0] 始终是 dav-2201、bin_files[1] 始终是 dav-3510。g_sk_entry_bins[].arch 字段已存储架构名但从未用于匹配。若构建系统传入的顺序与假设不符,运行时将加载错误的二进制文件且无任何报错。