From 801fe9963637cb24cc7dff38f2d4f9c73009069c Mon Sep 17 00:00:00 2001 From: German Andryeyev Date: Fri, 14 Feb 2020 16:08:52 -0500 Subject: [PATCH] SWDEV-222307 - Add CMake support for PAL Remove dependency on COMGR headers from backends. Remove GFX103 PAL defines. Change-Id: I6ff76dca2a0c84bc191e8fc8b639f2f5872d2085 [ROCm/clr commit: 1be1e69f2a9d69dc83b1c1181d26772fcf71e0df] --- projects/clr/rocclr/device/devkernel.cpp | 6 +- projects/clr/rocclr/device/devkernel.hpp | 2 +- projects/clr/rocclr/device/devprogram.hpp | 8 +- projects/clr/rocclr/device/pal/CMakeLists.txt | 6 +- .../clr/rocclr/device/pal/palcounters.cpp | 5 +- projects/clr/rocclr/device/pal/paldevice.cpp | 2 +- projects/clr/rocclr/device/pal/palkernel.cpp | 7 +- .../clr/rocclr/device/pal/palresource.cpp | 10 +-- .../clr/rocclr/device/pal/palsettings.cpp | 1 - .../clr/rocclr/device/rocm/CMakeLists.txt | 88 +------------------ projects/clr/rocclr/device/rocm/rockernel.cpp | 8 +- 11 files changed, 25 insertions(+), 118 deletions(-) diff --git a/projects/clr/rocclr/device/devkernel.cpp b/projects/clr/rocclr/device/devkernel.cpp index 2a46d99d7c..f690e334ad 100644 --- a/projects/clr/rocclr/device/devkernel.cpp +++ b/projects/clr/rocclr/device/devkernel.cpp @@ -1123,7 +1123,11 @@ static inline cl_kernel_arg_type_qualifier GetOclTypeQualOCL(const aclArgData* a // ================================================================================================ #if defined(USE_COMGR_LIBRARY) -bool Kernel::GetAttrCodePropMetadata(const amd_comgr_metadata_node_t kernelMetaNode) { +bool Kernel::GetAttrCodePropMetadata() { + amd_comgr_metadata_node_t kernelMetaNode; + if (!prog().getKernelMetadata(name(), &kernelMetaNode)) { + return false; + } InitParameters(kernelMetaNode); diff --git a/projects/clr/rocclr/device/devkernel.hpp b/projects/clr/rocclr/device/devkernel.hpp index b9a26290e0..07ecf9b734 100644 --- a/projects/clr/rocclr/device/devkernel.hpp +++ b/projects/clr/rocclr/device/devkernel.hpp @@ -511,7 +511,7 @@ class Kernel : public amd::HeapObject { void InitParameters(const amd_comgr_metadata_node_t kernelMD); //! Retrieve kernel attribute and code properties metadata - bool GetAttrCodePropMetadata(const amd_comgr_metadata_node_t kernelMetaNode); + bool GetAttrCodePropMetadata(); //! Retrieve the available SGPRs and VGPRs bool SetAvailableSgprVgpr(const std::string& targetIdent); diff --git a/projects/clr/rocclr/device/devprogram.hpp b/projects/clr/rocclr/device/devprogram.hpp index 2f39234e8a..108a1aee0f 100644 --- a/projects/clr/rocclr/device/devprogram.hpp +++ b/projects/clr/rocclr/device/devprogram.hpp @@ -220,9 +220,13 @@ class Program : public amd::HeapObject { amd_comgr_metadata_node_t metadata() const { return metadata_; } //! Get the kernel metadata - const amd_comgr_metadata_node_t* getKernelMetadata(const std::string name) const { + const bool getKernelMetadata(const std::string name, amd_comgr_metadata_node_t* meta) const { auto it = kernelMetadataMap_.find(name); - return (it == kernelMetadataMap_.end()) ? nullptr : &(it->second); + if (it != kernelMetadataMap_.end()) { + *meta = it->second; + return true; + } + return false; } const uint32_t codeObjectVer() const { return codeObjectVer_; } diff --git a/projects/clr/rocclr/device/pal/CMakeLists.txt b/projects/clr/rocclr/device/pal/CMakeLists.txt index 1be0f548e1..71c9f43e39 100644 --- a/projects/clr/rocclr/device/pal/CMakeLists.txt +++ b/projects/clr/rocclr/device/pal/CMakeLists.txt @@ -72,17 +72,13 @@ target_compile_definitions(vdipal PRIVATE PAL_BUILD_RENOIR=1) # GFX10 targets target_compile_definitions(vdipal PRIVATE PAL_BUILD_GFX10=1) -target_compile_definitions(vdipal PRIVATE PAL_BUILD_GFX103=1) target_compile_definitions(vdipal PRIVATE PAL_BUILD_NAVI12=1) target_compile_definitions(vdipal PRIVATE PAL_BUILD_NAVI14=1) target_compile_definitions(vdipal PRIVATE OPENCL_MAINLINE=1) if(${USE_COMGR_LIBRARY} MATCHES "yes") - target_compile_definitions(vdipal PRIVATE USE_COMGR_LIBRARY -DCOMGR_DYN_DLL) - if (DEFINED COMGR_INCLUDES AND NOT ${COMGR_INCLUDES} STREQUAL "") - target_include_directories(${COMGR_INCLUDES}) - endif() # if (DEFINED COMGR_INCLUDES AND NOT ${COMGR_INCLUDES} STREQUAL "") + target_compile_definitions(vdipal PRIVATE USE_COMGR_LIBRARY) endif() target_include_directories(vdipal PRIVATE ${CMAKE_SOURCE_DIR}/compiler/sc/HSAIL/include) diff --git a/projects/clr/rocclr/device/pal/palcounters.cpp b/projects/clr/rocclr/device/pal/palcounters.cpp index e33d777b20..3d95bd84c9 100644 --- a/projects/clr/rocclr/device/pal/palcounters.cpp +++ b/projects/clr/rocclr/device/pal/palcounters.cpp @@ -154,7 +154,7 @@ bool PalCounterReference::finalize() { } } -static const std::array blockIdToIndexSelect = {{ +static const std::array blockIdToIndexSelect = {{ PCIndexSelect::None, // CPF PCIndexSelect::ShaderEngine, // IA PCIndexSelect::ShaderEngine, // VGT @@ -201,9 +201,11 @@ static const std::array blockIdToIndexSelect = {{ PCIndexSelect::None, // GCR PCIndexSelect::None, // PH PCIndexSelect::ShaderArray, // UTCL1 +#if 0 PCIndexSelect::None, // GeDist PCIndexSelect::ShaderEngine, // GeSe PCIndexSelect::None, // Df +#endif }}; static_assert(blockIdToIndexSelect.size() == static_cast(Pal::GpuBlock::Count), "size of blockIdToIndexSelect does not match GpuBlock::Count"); @@ -690,7 +692,6 @@ void PerfCounter::convertInfo() { } break; case Pal::GfxIpLevel::GfxIp10_1: - case Pal::GfxIpLevel::GfxIp10_3: if (info_.blockIndex_ < gfx10BlockIdPal.size()) { auto p = gfx10BlockIdPal[info_.blockIndex_]; info_.blockIndex_ = std::get<0>(p); diff --git a/projects/clr/rocclr/device/pal/paldevice.cpp b/projects/clr/rocclr/device/pal/paldevice.cpp index f3e705b8cd..1248c85bcf 100644 --- a/projects/clr/rocclr/device/pal/paldevice.cpp +++ b/projects/clr/rocclr/device/pal/paldevice.cpp @@ -197,7 +197,7 @@ bool NullDevice::init() { ShouldNotReachHere(); break; case 3: - ipLevel = Pal::GfxIpLevel::GfxIp10_3; + ShouldNotReachHere(); break; case 4: ShouldNotReachHere(); diff --git a/projects/clr/rocclr/device/pal/palkernel.cpp b/projects/clr/rocclr/device/pal/palkernel.cpp index 711a21df01..b0fdea8eff 100644 --- a/projects/clr/rocclr/device/pal/palkernel.cpp +++ b/projects/clr/rocclr/device/pal/palkernel.cpp @@ -426,12 +426,7 @@ bool LightningKernel::init() { flags_.internalKernel_ = (compileOptions_.find("-cl-internal-kernel") != std::string::npos) ? true : false; - const amd_comgr_metadata_node_t* kernelMetaNode = prog().getKernelMetadata(name()); - if (kernelMetaNode == nullptr) { - return false; - } - - if (!GetAttrCodePropMetadata(*kernelMetaNode)) { + if (!GetAttrCodePropMetadata()) { return false; } diff --git a/projects/clr/rocclr/device/pal/palresource.cpp b/projects/clr/rocclr/device/pal/palresource.cpp index 49b1dab84b..54ee21d515 100644 --- a/projects/clr/rocclr/device/pal/palresource.cpp +++ b/projects/clr/rocclr/device/pal/palresource.cpp @@ -472,10 +472,10 @@ void Resource::memTypeToHeap(Pal::GpuMemoryCreateInfo* createInfo) { switch (memoryType()) { case Local: case Scratch: - createInfo->mallPolicy = static_cast(dev().settings().mallPolicy_); +// createInfo->mallPolicy = static_cast(dev().settings().mallPolicy_); break; default: - createInfo->mallPolicy = Pal::GpuMemMallPolicy::Never; +// createInfo->mallPolicy = Pal::GpuMemMallPolicy::Never; break; } } @@ -1951,7 +1951,7 @@ bool MemorySubAllocator::CreateChunk(const Pal::IGpuMemory* reserved_va) { createInfo.heapCount = 1; createInfo.heaps[0] = Pal::GpuHeapInvisible; createInfo.flags.peerWritable = device_->P2PAccessAllowed(); - createInfo.mallPolicy = static_cast(device_->settings().mallPolicy_); +// createInfo.mallPolicy = static_cast(device_->settings().mallPolicy_); GpuMemoryReference* mem_ref = GpuMemoryReference::Create(*device_, createInfo); if (mem_ref != nullptr) { return InitAllocator(mem_ref); @@ -1971,7 +1971,7 @@ bool CoarseMemorySubAllocator::CreateChunk(const Pal::IGpuMemory* reserved_va) { createInfo.heapCount = 2; createInfo.heaps[0] = Pal::GpuHeapInvisible; createInfo.heaps[1] = Pal::GpuHeapLocal; - createInfo.mallPolicy = static_cast(device_->settings().mallPolicy_); +// createInfo.mallPolicy = static_cast(device_->settings().mallPolicy_); GpuMemoryReference* mem_ref = GpuMemoryReference::Create(*device_, createInfo); if (mem_ref != nullptr) { return InitAllocator(mem_ref); @@ -1987,7 +1987,7 @@ bool FineMemorySubAllocator::CreateChunk(const Pal::IGpuMemory* reserved_va) { createInfo.alignment = MaxGpuAlignment; createInfo.flags.useReservedGpuVa = (reserved_va != nullptr); createInfo.pReservedGpuVaOwner = reserved_va; - createInfo.mallPolicy = Pal::GpuMemMallPolicy::Never; +// createInfo.mallPolicy = Pal::GpuMemMallPolicy::Never; GpuMemoryReference* mem_ref = GpuMemoryReference::Create(*device_, createInfo); if ((mem_ref != nullptr) && InitAllocator(mem_ref)) { mem_ref->iMem()->Map(&mem_ref->cpuAddress_); diff --git a/projects/clr/rocclr/device/pal/palsettings.cpp b/projects/clr/rocclr/device/pal/palsettings.cpp index 29455fe5ba..b43d5b9916 100644 --- a/projects/clr/rocclr/device/pal/palsettings.cpp +++ b/projects/clr/rocclr/device/pal/palsettings.cpp @@ -493,7 +493,6 @@ bool Settings::create(const Pal::DeviceProperties& palProp, if (useLightning_) { switch (palProp.gfxLevel) { - case Pal::GfxIpLevel::GfxIp10_3: case Pal::GfxIpLevel::GfxIp10_1: case Pal::GfxIpLevel::GfxIp9: singleFpDenorm_ = true; diff --git a/projects/clr/rocclr/device/rocm/CMakeLists.txt b/projects/clr/rocclr/device/rocm/CMakeLists.txt index a7628cf575..30cc867cb5 100644 --- a/projects/clr/rocclr/device/rocm/CMakeLists.txt +++ b/projects/clr/rocclr/device/rocm/CMakeLists.txt @@ -1,16 +1,10 @@ -include(bc2h) - -set(INC_SUFFIX "amdgcn.inc") - include_directories(${CMAKE_SOURCE_DIR}/compiler/lib/loaders/elf/utils/common) include_directories(${CMAKE_SOURCE_DIR}/compiler/lib/loaders/elf/utils/libelf) include_directories(${CMAKE_CURRENT_BINARY_DIR}) include_directories(${ROCM_OCL_INCLUDES}) if(${USE_COMGR_LIBRARY} MATCHES "yes") - add_definitions(-DUSE_COMGR_LIBRARY -DCOMGR_DYN_DLL) - find_package(amd_comgr REQUIRED CONFIG) - include_directories("$") + add_definitions(-DUSE_COMGR_LIBRARY) endif() add_library(oclrocm OBJECT @@ -30,83 +24,3 @@ add_library(oclrocm OBJECT ) set_target_properties(oclrocm PROPERTIES POSITION_INDEPENDENT_CODE ON) -# FIXME: Remove following if block after enabling COMGR by default -if (${USE_COMGR_LIBRARY} STREQUAL "no") - # generating libraries.amdgcn.inc - file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/libraries.amdgcn.inc "// Automatically generated file; DO NOT EDIT.\n") - - foreach(AMDGCN_LIB_TARGET ${AMDGCN_LIB_TARGETS}) - get_target_property(lib_file ${AMDGCN_LIB_TARGET} OUTPUT_NAME) - get_target_property(lib_file_name ${AMDGCN_LIB_TARGET} ARCHIVE_OUTPUT_NAME) - get_target_property(lib_file_path ${AMDGCN_LIB_TARGET} ARCHIVE_OUTPUT_DIRECTORY) - set(bclib "${lib_file}") - set(header "${lib_file_name}.${INC_SUFFIX}") - set(symbol "${lib_file_name}_lib") - add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${header} - COMMAND bc2h ${bclib} ${CMAKE_CURRENT_BINARY_DIR}/${header} ${symbol} - DEPENDS bc2h ${AMDGCN_LIB_TARGET} - COMMENT "Generating ${header}" - ) - set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES ${CMAKE_CURRENT_BINARY_DIR}/${target}.inc) - - add_custom_target(${header}_target ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${header}) - add_dependencies(oclrocm ${header}_target) - - file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/libraries.amdgcn.inc "#include \"${header}\"\n") - endforeach() - - # Generate function to select libraries for a given GFXIP number. - file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/libraries.amdgcn.inc - "static inline std::tuple get_oclc_isa_version(uint gfxip) { \ - switch (gfxip) {\n") - foreach(AMDGCN_LIB_TARGET ${AMDGCN_LIB_TARGETS}) - if (${AMDGCN_LIB_TARGET} MATCHES "^oclc_isa_version_[0-9]+_lib$") - string(REGEX REPLACE "^oclc_isa_version_([0-9]+)_lib$" "\\1" gfxip ${AMDGCN_LIB_TARGET}) - file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/libraries.amdgcn.inc - "case ${gfxip}: return std::make_tuple( \"oclc_isa_version_${gfxip}_lib.bc\"," - " oclc_isa_version_${gfxip}_lib, oclc_isa_version_${gfxip}_lib_size); break;\n") - endif() - endforeach() - file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/libraries.amdgcn.inc - "default: return std::make_tuple(\"\",(const void*)0,(size_t)0); }\n}\n") - - foreach(AMDGCN_LIB_TARGET ${AMDGCN_LIB_TARGETS}) - if (${AMDGCN_LIB_TARGET} MATCHES "oclc_(.*)_on_lib") - string(REGEX REPLACE "oclc_(.*)_on_lib" "\\1" function ${AMDGCN_LIB_TARGET}) - file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/libraries.amdgcn.inc - "static inline std::tuple get_oclc_${function}(bool on)" - " { return std::make_tuple( on ? \"oclc_${function}_on_lib.bc\" : \"oclc_${function}_off_lib.bc\"," - " (const void*)(on ? oclc_${function}_on_lib : oclc_${function}_off_lib)," - " on ? oclc_${function}_on_lib_size : oclc_${function}_off_lib_size); }\n") - endif() - endforeach() - - # generating opencl*.inc files - add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/opencl1.2-c.amdgcn.pch - COMMAND clang -cc1 -x cl-header -triple amdgcn-amd-amdhsa -Werror -O3 -DNDEBUG -cl-std=CL1.2 -emit-pch -o ${CMAKE_CURRENT_BINARY_DIR}/opencl1.2-c.amdgcn.pch < ${CMAKE_SOURCE_DIR}/compiler/llvm/tools/clang/lib/Headers/opencl-c.h - DEPENDS clang ${CMAKE_SOURCE_DIR}/compiler/llvm/tools/clang/lib/Headers/opencl-c.h - COMMENT "Generating opencl1.2-c.amdgcn.pch" - ) - add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/opencl1.2-c.amdgcn.inc - COMMAND bc2h ${CMAKE_CURRENT_BINARY_DIR}/opencl1.2-c.amdgcn.pch ${CMAKE_CURRENT_BINARY_DIR}/opencl1.2-c.amdgcn.inc opencl1_2_c - DEPENDS bc2h ${CMAKE_CURRENT_BINARY_DIR}/opencl1.2-c.amdgcn.pch - COMMENT "Generating opencl1.2-c.amdgcn.inc" - ) - set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES ${CMAKE_CURRENT_BINARY_DIR}/opencl1.2-c.amdgcn.inc ${CMAKE_CURRENT_BINARY_DIR}/opencl1.2-c.amdgcn.pch) - add_custom_target(opencl1.2-c.amdgcn.inc_target ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/opencl1.2-c.amdgcn.inc) - add_dependencies(oclrocm opencl1.2-c.amdgcn.inc_target) - - add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/opencl2.0-c.amdgcn.pch - COMMAND clang -cc1 -x cl-header -triple amdgcn-amd-amdhsa -Werror -O3 -DNDEBUG -cl-std=CL2.0 -emit-pch -o ${CMAKE_CURRENT_BINARY_DIR}/opencl2.0-c.amdgcn.pch < ${CMAKE_SOURCE_DIR}/compiler/llvm/tools/clang/lib/Headers/opencl-c.h - DEPENDS clang ${CMAKE_SOURCE_DIR}/compiler/llvm/tools/clang/lib/Headers/opencl-c.h - COMMENT "Generating opencl2.0-c.amdgcn.pch" - ) - add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/opencl2.0-c.amdgcn.inc - COMMAND bc2h ${CMAKE_CURRENT_BINARY_DIR}/opencl2.0-c.amdgcn.pch ${CMAKE_CURRENT_BINARY_DIR}/opencl2.0-c.amdgcn.inc opencl2_0_c - DEPENDS bc2h ${CMAKE_CURRENT_BINARY_DIR}/opencl2.0-c.amdgcn.pch - COMMENT "Generating opencl2.0-c.amdgcn.inc" - ) - set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES ${CMAKE_CURRENT_BINARY_DIR}/opencl2.0-c.amdgcn.inc ${CMAKE_CURRENT_BINARY_DIR}/opencl2.0-c.amdgcn.pch) - add_custom_target(opencl2.0-c.amdgcn.inc_target ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/opencl2.0-c.amdgcn.inc) - add_dependencies(oclrocm opencl2.0-c.amdgcn.inc_target) -endif() # if (${USE_COMGR_LIBRARY} STREQUAL "no") diff --git a/projects/clr/rocclr/device/rocm/rockernel.cpp b/projects/clr/rocclr/device/rocm/rockernel.cpp index 2ac7196211..893966c441 100644 --- a/projects/clr/rocclr/device/rocm/rockernel.cpp +++ b/projects/clr/rocclr/device/rocm/rockernel.cpp @@ -48,13 +48,7 @@ bool LightningKernel::init() { hsa_agent_t hsaDevice = program()->hsaDevice(); - const amd_comgr_metadata_node_t* kernelMetaNode = - static_cast(program())->getKernelMetadata(name()); - if (kernelMetaNode == nullptr) { - return false; - } - - if (!GetAttrCodePropMetadata(*kernelMetaNode)) { + if (!GetAttrCodePropMetadata()) { return false; }