Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ build
.vscode
.envrc
.DS_Store
build/
.ipynb_checkpoints/
ext/
rocm.gpg
54 changes: 54 additions & 0 deletions init_env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/bin/bash

echo ">>> 1. Odblokowanie systemu i czyszczenie błędów (Opcja Nuklearna)..."
# Usuwamy problematyczne skrypty postinst, które blokowały dpkg brakiem py3compile
sudo rm -f /var/lib/dpkg/info/python3-yaml.postinst
sudo rm -f /var/lib/dpkg/info/python3-pygments.postinst
sudo rm -f /var/lib/dpkg/info/libboost-mpi-python1.83.0.postinst

# Wymuszamy naprawę systemu i usunięcie zepsutych pakietów
sudo dpkg --configure -a
sudo apt-get install -f -y

echo ">>> 2. Instalacja bezpiecznych zależności (minimalny zestaw)..."
sudo apt-get update
sudo apt-get install -y \
build-essential \
cmake \
git \
wget \
pkg-config \
clang \
llvm-dev \
libboost-dev \
libboost-filesystem-dev \
libboost-thread-dev \
libboost-system-dev \
libopenexr-dev \
libopenimageio-dev \
libpugixml-dev \
libtbb-dev \
zlib1g-dev \
python3-minimal

echo ">>> 3. Konfiguracja AMD ROCm..."
if [ ! -f /etc/apt/keyrings/rocm.gpg ]; then
sudo mkdir -p /etc/apt/keyrings
wget -qO - https://repo.radeon.com/rocm/rocm.gpg.key | gpg --dearmor | sudo tee /etc/apt/keyrings/rocm.gpg > /dev/null
fi

echo "deb [arch=amd64 signed-by=/etc/apt/keyrings/rocm.gpg] https://repo.radeon.com/rocm/apt/latest/ noble main" | sudo tee /etc/apt/sources.list.d/rocm.list

sudo apt-get update
sudo apt-get install -y rocm-hip-sdk hipcc

echo ">>> 4. Eksportowanie zmiennych środowiskowych..."
export ROCM_PATH=/opt/rocm
export HIP_PATH=/opt/rocm/hip
export PATH=$PATH:$ROCM_PATH/bin:$HIP_PATH/bin

sudo apt-get update
sudo apt-get install -y pybind11-dev
sudo apt-get install -y bison flex
sudo apt-get install -y libclang-18-dev libclang-dev
echo "--- Środowisko gotowe do kompilacji ---"
8 changes: 8 additions & 0 deletions src/include/OSL/llvm_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -1031,6 +1031,12 @@ class OSLEXECPUBLIC LLVM_Util {
bool ptx_compile_group(llvm::Module* lib_module, const std::string& name,
std::string& out);


// NEW
llvm::TargetMachine* amdgpu_target_machine(const std::string& gpu_arch);
bool amdgpu_compile_group(llvm::Module* module, const std::string& name, std::string& out_code, const std::string& arch);


/// Convert all functions in module's bitcode to a string.
std::string bitcode_string(llvm::Module* module);

Expand Down Expand Up @@ -1076,6 +1082,8 @@ class OSLEXECPUBLIC LLVM_Util {
llvm::ExecutionEngine* m_llvm_exec;
TargetISA m_target_isa = TargetISA::UNKNOWN;
llvm::TargetMachine* m_nvptx_target_machine;
// NEW
llvm::TargetMachine* m_amdgpu_target_machine = nullptr;

std::vector<llvm::BasicBlock*> m_return_block; // stack for func call
std::vector<llvm::BasicBlock*> m_loop_after_block; // stack for break
Expand Down
36 changes: 35 additions & 1 deletion src/liboslexec/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,41 @@ file (GLOB exec_headers "*.h")
file (GLOB compiler_headers "../liboslcomp/*.h")

FLEX_BISON ( osolex.l osogram.y oso lib_src exec_headers )
# NEW - KB
set(OSL_AMDGPU_TARGET_ARCH "" CACHE STRING "Target AMD GPU architecture (e.g. gfx900, gfx1030)")
if(OSL_AMDGPU_TARGET_ARCH)
message(STATUS "====> AMDGPU CROSS-COMPILATION: Forced target architecture -> ${OSL_AMDGPU_TARGET_ARCH}")
add_definitions(-DOSL_AMDGPU_TARGET_ARCH="${OSL_AMDGPU_TARGET_ARCH}")
endif()

set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS" )

# NEW - Ka
if (LLVM_CONFIG AND EXISTS ${LLVM_CONFIG})
execute_process(COMMAND ${LLVM_CONFIG} --targets-built
OUTPUT_VARIABLE LLVM_TARGETS
OUTPUT_STRIP_TRAILING_WHITESPACE)

if (LLVM_TARGETS MATCHES "AMDGPU")
message(STATUS "AMDGPU Backend: Supported target found in LLVM.")
add_definitions(-DOSL_ENABLE_AMDGPU=1)

# W LLVM komponenty podaje się bez prefiksów.
# Nazwa 'amdgpu' jest nadrzędna i zazwyczaj wystarcza.
# Jeśli OSL nie widzi llvm_map_components_to_libnames,
# używamy bezpośredniego zapytania do llvm-config:
execute_process(COMMAND ${LLVM_CONFIG} --libfiles amdgpu codegen asmparser
OUTPUT_VARIABLE AMDGPU_LLVM_LIBS
OUTPUT_STRIP_TRAILING_WHITESPACE)

# Konwersja tekstu z llvm-config na listę CMake
string(REPLACE " " ";" AMDGPU_LLVM_LIBS "${AMDGPU_LLVM_LIBS}")
string(REPLACE "\n" ";" AMDGPU_LLVM_LIBS "${AMDGPU_LLVM_LIBS}")

message(STATUS "AMDGPU Backend: Linked libraries: ${AMDGPU_LLVM_LIBS}")
else()
message(STATUS "AMDGPU Backend: Not supported by your LLVM installation.")
endif()
endif()

macro ( REQUIRE_INF_NAN SRC )
if (CMAKE_COMPILER_IS_INTELCLANG)
Expand Down Expand Up @@ -581,6 +613,8 @@ target_link_libraries (${local_lib}
pugixml::pugixml
${CMAKE_DL_LIBS}
${LLVM_LIBRARIES} ${LLVM_LDFLAGS} ${LLVM_SYSTEM_LIBRARIES}
${AMDGPU_LLVM_LIBS} # NEW - Ka

)

target_compile_features (${local_lib}
Expand Down
Loading