1 //===--- amdgpu/impl/interop_hsa.cpp ------------------------------ C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 #include "interop_hsa.h" 9 #include "internal.h" 10 11 hsa_status_t interop_hsa_get_symbol_info( 12 const std::map<std::string, atl_symbol_info_t> &SymbolInfoTable, 13 int DeviceId, const char *symbol, void **var_addr, unsigned int *var_size) { 14 /* 15 // Typical usage: 16 void *var_addr; 17 size_t var_size; 18 interop_hsa_get_symbol_addr(gpu_place, "symbol_name", &var_addr, 19 &var_size); 20 impl_memcpy(signal, host_add, var_addr, var_size); 21 */ 22 23 if (!symbol || !var_addr || !var_size) 24 return HSA_STATUS_ERROR; 25 26 // get the symbol info 27 std::string symbolStr = std::string(symbol); 28 auto It = SymbolInfoTable.find(symbolStr); 29 if (It != SymbolInfoTable.end()) { 30 atl_symbol_info_t info = It->second; 31 *var_addr = reinterpret_cast<void *>(info.addr); 32 *var_size = info.size; 33 return HSA_STATUS_SUCCESS; 34 } else { 35 *var_addr = NULL; 36 *var_size = 0; 37 return HSA_STATUS_ERROR; 38 } 39 } 40 41 hsa_status_t interop_hsa_get_kernel_info( 42 const std::map<std::string, atl_kernel_info_t> &KernelInfoTable, 43 int DeviceId, const char *kernel_name, 44 hsa_executable_symbol_info_t kernel_info, uint32_t *value) { 45 /* 46 // Typical usage: 47 uint32_t value; 48 interop_hsa_get_kernel_addr(gpu_place, "kernel_name", 49 HSA_EXECUTABLE_SYMBOL_INFO_KERNEL_KERNARG_SEGMENT_SIZE, 50 &val); 51 */ 52 53 if (!kernel_name || !value) 54 return HSA_STATUS_ERROR; 55 56 hsa_status_t status = HSA_STATUS_SUCCESS; 57 // get the kernel info 58 std::string kernelStr = std::string(kernel_name); 59 auto It = KernelInfoTable.find(kernelStr); 60 if (It != KernelInfoTable.end()) { 61 atl_kernel_info_t info = It->second; 62 switch (kernel_info) { 63 case HSA_EXECUTABLE_SYMBOL_INFO_KERNEL_GROUP_SEGMENT_SIZE: 64 *value = info.group_segment_size; 65 break; 66 case HSA_EXECUTABLE_SYMBOL_INFO_KERNEL_PRIVATE_SEGMENT_SIZE: 67 *value = info.private_segment_size; 68 break; 69 case HSA_EXECUTABLE_SYMBOL_INFO_KERNEL_KERNARG_SEGMENT_SIZE: 70 // return the size for non-implicit args 71 *value = info.kernel_segment_size - sizeof(impl_implicit_args_t); 72 break; 73 default: 74 *value = 0; 75 status = HSA_STATUS_ERROR; 76 break; 77 } 78 } else { 79 *value = 0; 80 status = HSA_STATUS_ERROR; 81 } 82 83 return status; 84 } 85