Skip to content

Commit

Permalink
SPIR-V is an official target, no need to edit scripts/compile-triton.…
Browse files Browse the repository at this point in the history
…sh and CMakeLists.txt
  • Loading branch information
VyacheslavLevytskyy committed Jan 31, 2025
1 parent b411a51 commit f554c4f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 41 deletions.
3 changes: 1 addition & 2 deletions scripts/compile-triton.sh
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,7 @@ build_llvm() {
-DCMAKE_BUILD_TYPE=Release \
-DLLVM_ENABLE_ASSERTIONS=true \
-DLLVM_ENABLE_PROJECTS="mlir" \
-DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=SPIRV \
-DLLVM_TARGETS_TO_BUILD="X86;NVPTX;AMDGPU" \
-DLLVM_TARGETS_TO_BUILD="X86;NVPTX;AMDGPU;SPIRV" \
-DLLVM_INSTALL_UTILS=true \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
-DCMAKE_INSTALL_PREFIX=$PACKAGES_DIR/llvm \
Expand Down
45 changes: 13 additions & 32 deletions third_party/intel/lib/Target/SPIRV/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,38 +1,19 @@
# SPIRV-LLVM-Translator is required.
find_package(SPIRVToLLVMTranslator)

# Check if there is the LLVM SPIR-V backend.
is_llvm_target_library("SPIRV" spirv_present_result INCLUDED_TARGETS)

if(spirv_present_result)
message(STATUS "Found SPIR-V Backend")
add_compile_definitions(LLVM_SPIRV_BACKEND_TARGET_PRESENT)
add_mlir_translation_library(TritonSPIRV
SPIRVTranslation.cpp

LINK_COMPONENTS
Core
# spirv backend
SPIRVCodeGen

LINK_LIBS PUBLIC
TritonLLVMIR
# spirv tools
LLVMSPIRVLib
)
else()
add_mlir_translation_library(TritonSPIRV
SPIRVTranslation.cpp

LINK_COMPONENTS
Core

LINK_LIBS PUBLIC
TritonLLVMIR
# spirv tools
LLVMSPIRVLib
)
endif()
add_mlir_translation_library(TritonSPIRV
SPIRVTranslation.cpp

LINK_COMPONENTS
Core
# spirv backend
SPIRVCodeGen

LINK_LIBS PUBLIC
TritonLLVMIR
# spirv tools
LLVMSPIRVLib
)

# Add SPIRV-LLVM-Translator include directory.
target_include_directories(TritonSPIRV PRIVATE ${SPIRVToLLVMTranslator_INCLUDE_DIR})
Expand Down
7 changes: 0 additions & 7 deletions third_party/intel/lib/Target/SPIRV/SPIRVTranslation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include "llvm/Target/TargetMachine.h"
#include "llvm/TargetParser/Triple.h"

#if defined(LLVM_SPIRV_BACKEND_TARGET_PRESENT)
namespace llvm {

using namespace llvm;
Expand Down Expand Up @@ -102,8 +101,6 @@ bool runSpirvBackend(Module *M, std::ostream &OS, std::string &ErrMsg,

} // namespace llvm

#endif // LLVM_SPIRV_BACKEND_TARGET_PRESENT

namespace triton {

class SmallVectorBuffer : public std::streambuf {
Expand Down Expand Up @@ -156,16 +153,12 @@ std::string translateLLVMIRToSPIRV(llvm::Module &module) {
SPIRVOpts.setPreserveAuxData(false);
SPIRVOpts.setSPIRVAllowUnknownIntrinsics({"llvm.genx.GenISA."});

#if defined(LLVM_SPIRV_BACKEND_TARGET_PRESENT)
int SpvTranslateMode = 0;
if (const char *EnvIsBackend = std::getenv("TRITON_USE_SPIRV_BACKEND"))
llvm::StringRef(EnvIsBackend).getAsInteger(10, SpvTranslateMode);
auto success = SpvTranslateMode
? llvm::runSpirvBackend(&module, OS, Err, SPIRVOpts)
: llvm::writeSpirv(&module, SPIRVOpts, OS, Err);
#else
auto success = llvm::writeSpirv(&module, SPIRVOpts, OS, Err);
#endif // LLVM_SPIRV_BACKEND_TARGET_PRESENT

if (!success) {
llvm::errs() << "SPIRVTranslation: SPIRV translation failed with"
Expand Down

0 comments on commit f554c4f

Please sign in to comment.