WIP: Linux Support for HIP-RT #121050

Draft
Sahar A. Kashi wants to merge 5 commits from salipour/AMD_HIPRT:HIPRT_OPEN_SOURCE into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
Member

HIP-RT was originally closed source and that created issue with distribution of HIP-RT runtime and kernel binaries. The changes add support for Linux but more importantly HIP-RT kernel binaries are generated during the build process, simplifying the distribution process, and unifying the compiler across all the components (BVH builder, traversal library and Cycles kernels).

In the current change list, the assumptions is that HIP-RT SDK is available under third party lib folder, and the folder structure is
top folder lib/hiprt
include files: hiprt/hiprt
dynamic library: hiprt/bin
dependency (headers only): hiprt/orochi

HIP-RT was originally closed source and that created issue with distribution of HIP-RT runtime and kernel binaries. The changes add support for Linux but more importantly HIP-RT kernel binaries are generated during the build process, simplifying the distribution process, and unifying the compiler across all the components (BVH builder, traversal library and Cycles kernels). In the current change list, the assumptions is that HIP-RT SDK is available under third party lib folder, and the folder structure is top folder lib/hiprt include files: hiprt/hiprt dynamic library: hiprt/bin dependency (headers only): hiprt/orochi
Sahar A. Kashi added 4 commits 2024-04-24 22:27:39 +02:00
1e1a3aae07 1. Fix for Cycles Crash on deleting/hiding all mesh objects with HIP RT (#112983)
2. Update for hip path to also include ROCm 6 driver

# Conflicts:
#	intern/cycles/device/hiprt/device_impl.cpp
6b47bb74a3 Switching to HIPRT 2.2
# Conflicts/Rebase main (3/26/24):
#	extern/hipew/src/hipew.c
Sahar A. Kashi requested review from Brecht Van Lommel 2024-04-24 22:31:09 +02:00
Member

info_cfg_option(WITH_CYCLES_DEVICE_HIPRT) inside CmakeLists.txt should be inside the if (NOT APPLE) check above it.

`info_cfg_option(WITH_CYCLES_DEVICE_HIPRT)` inside `CmakeLists.txt` should be inside the `if (NOT APPLE)` check above it.

Generally we try to make things work with old and new versions of a library, to make coordination of landing updates easier. But in this case it looks not so simple, and not worth doing.

So I think when the time comes to land this, we either disable WITH_CYCLES_DEVICE_HIPRT for a little bit, or coordinate with @LazyDodo to land precompiled libraries at the same time.

Generally we try to make things work with old and new versions of a library, to make coordination of landing updates easier. But in this case it looks not so simple, and not worth doing. So I think when the time comes to land this, we either disable `WITH_CYCLES_DEVICE_HIPRT` for a little bit, or coordinate with @LazyDodo to land precompiled libraries at the same time.
Brecht Van Lommel requested changes 2024-04-25 18:41:35 +02:00
Brecht Van Lommel left a comment
Owner

I wasn't able to actually test the make deps integration because the version doesn't seem to exist. But some comments from reading through the changes.

I wasn't able to actually test the `make deps` integration because the version doesn't seem to exist. But some comments from reading through the changes.
CMakeLists.txt Outdated
@ -699,3 +697,1 @@
option(WITH_CYCLES_DEVICE_HIPRT "Enable Cycles AMD HIPRT support" OFF)
mark_as_advanced(WITH_CYCLES_DEVICE_HIPRT)
endif()
option(WITH_CYCLES_DEVICE_HIPRT "Enable Cycles AMD HIPRT support" ON)

This should still default to OFF.

It's build_files/cmake/config/blender_release.cmake that enables it by default for releases. Though we should still not enable it for Linux there, until after the precompiled libraries for that platform have landed.

This should still default to OFF. It's `build_files/cmake/config/blender_release.cmake` that enables it by default for releases. Though we should still not enable it for Linux there, until after the precompiled libraries for that platform have landed.
@ -0,0 +8,4 @@
set(HIPRT_CMAKE_FLAGS ${DEFAULT_CMAKE_FLAGS})
set(HIPRT_EXTRA_ARGS
--DHIPRT_EXPORTS=ON

Should be -D instead of --D?

Should be `-D` instead of `--D`?
@ -0,0 +39,4 @@
)
if(WIN32)
if(BUILD_MODE STREQUAL Release)

For Linux, there will need to be additions in build_files/build_environment/cmake/harvest.cmake to install things.

I guess something like this, not sure if we want to just install all files or only a subset.

  harvest(hiprt/include hiprt/include "*")
  harvest(hiprt/lib hiprt/lib "*")
For Linux, there will need to be additions in `build_files/build_environment/cmake/harvest.cmake` to install things. I guess something like this, not sure if we want to just install all files or only a subset. ``` harvest(hiprt/include hiprt/include "*") harvest(hiprt/lib hiprt/lib "*") ```
@ -0,0 +54,4 @@
ExternalProject_Add_Step(external_hiprt after_install
COMMAND ${CMAKE_COMMAND} -E copy
${LIBDIR}/hiprt/dist/bin/Release/hiprt64.dll
${HARVEST_TARGET}/hiprt/bin/hiprt64.dll

I think hiprt64_d.dll should be used here.

I think `hiprt64_d.dll` should be used here.
@ -856,2 +856,4 @@
set(PYBIND11_HASH_TYPE MD5)
set(PYBIND11_FILE pybind-v${PYBIND11_VERSION}.tar.gz)
set(HIPRT_VERSION 2.3.7df94af)

This version doesn't seem to exist?
https://github.com/GPUOpen-LibrariesAndSDKs/HIPRTSDK/releases

Not sure if we need to wait for it to be released, or if another version should be used.

This version doesn't seem to exist? https://github.com/GPUOpen-LibrariesAndSDKs/HIPRTSDK/releases Not sure if we need to wait for it to be released, or if another version should be used.
Member
URI is wrong, it's over at https://github.com/GPUOpen-LibrariesAndSDKs/HIPRT/releases/tag/2.3.7df94af

Ah ok, so it's:

set(HIPRT_URI https://github.com/GPUOpen-LibrariesAndSDKs/HIPRT/archive/refs/tags/${HIPRT_VERSION}.zip)
set(HIPRT_HASH eeb4053fd7e5ada2e2dff838dff41ca1)
Ah ok, so it's: ``` set(HIPRT_URI https://github.com/GPUOpen-LibrariesAndSDKs/HIPRT/archive/refs/tags/${HIPRT_VERSION}.zip) set(HIPRT_HASH eeb4053fd7e5ada2e2dff838dff41ca1) ```
Member

probably? I haven't gotten around to building this yet i'll try to schedule some time for this over the weekend.

probably? I haven't gotten around to building this yet i'll try to schedule some time for this over the weekend.

Ok, thanks. For reference, this PR is heavily WIP and will need many more changes to get it to actually build.

I asked to just add the code so we get an idea of how things should fit together, what the build options should be, etc. But not to actually test if it works, since it's not so easy to build the libs on Windows.

Ok, thanks. For reference, this PR is heavily WIP and will need many more changes to get it to actually build. I asked to just add the code so we get an idea of how things should fit together, what the build options should be, etc. But not to actually test if it works, since it's not so easy to build the libs on Windows.
@ -51,0 +44,4 @@
if(WIN32)
set(HIPRT_DYNAMIC_LIB hiprt${HIPRT_VERSION}64.dll)
else()
set(HIPRT_DYNAMIC_LIB hiprt${HIPRT_VERSION}64.so)

Is ${HIPRT_VERSION} supposed to be in the name? It's not in hiprt.cmake.

Is `${HIPRT_VERSION}` supposed to be in the name? It's not in `hiprt.cmake`.
Author
Member

I updated the name in hiprt.cmake file.

I updated the name in hiprt.cmake file.
@ -53,0 +57,4 @@
)
if(HIPRT_LIB_DIR)
set(HIPRT_DYNAMIC_LIB_PATH

This seems to be unused currently. I guess the idea is still to dynamically load the hiprt library rather than Blender linking to it? If so I guess this variable can be removed.

To install the shared libraries along with Blender, this will need to be added in build_files/cmake/platform/platform_unix.cmake, which will copy all .so files into the bundled lib directory.

add_bundled_libraries(hiprt/lib)

For Windows this is done in source/creator/CMakeLists.txt, something like:

 if(WITH_CYCLES_DEVICE_HIPRT)
    windows_install_shared_manifest(
      FILES ${LIBDIR}/hiprt/bin/hiprt64.dll
      ALL
    )
  endif()

Unless there are separate release and debug libraries, in which case:

  if(EXISTS ${LIBDIR}/hiprt/bin/hiprt64.dll)
    windows_install_shared_manifest(
      FILES
        ${LIBDIR}/hiprt/bin/hiprt64.dll
      RELEASE
    )   
    windows_install_shared_manifest(
      FILES
        ${LIBDIR}/hiprt/bin/hiprt64_d.dll
      DEBUG
    )
  endif()
This seems to be unused currently. I guess the idea is still to dynamically load the hiprt library rather than Blender linking to it? If so I guess this variable can be removed. To install the shared libraries along with Blender, this will need to be added in `build_files/cmake/platform/platform_unix.cmake`, which will copy all `.so` files into the bundled lib directory. ``` add_bundled_libraries(hiprt/lib) ``` For Windows this is done in `source/creator/CMakeLists.txt`, something like: ``` if(WITH_CYCLES_DEVICE_HIPRT) windows_install_shared_manifest( FILES ${LIBDIR}/hiprt/bin/hiprt64.dll ALL ) endif() ``` Unless there are separate release and debug libraries, in which case: ``` if(EXISTS ${LIBDIR}/hiprt/bin/hiprt64.dll) windows_install_shared_manifest( FILES ${LIBDIR}/hiprt/bin/hiprt64.dll RELEASE ) windows_install_shared_manifest( FILES ${LIBDIR}/hiprt/bin/hiprt64_d.dll DEBUG ) endif() ```
Author
Member

The main intention was to check if the dynamic library for hiprt exists before enabling it.

The main intention was to check if the dynamic library for hiprt exists before enabling it.
@ -732,0 +797,4 @@
COMMAND ${hiprt_compile_command} ${hiprt_compile_flags_sdk_bc}
DEPENDS ${HIPRT_INCLUDE_DIR}/hiprt/impl/hiprt_kernels_bitcode.h)

Nitpick: use 1 instead of 2 empty lines.

Nitpick: use 1 instead of 2 empty lines.
lib/windows_x64 Outdated
@ -1 +1 @@
Subproject commit a5521c85e03bfd1556ff1e63bf7163235c401497
Subproject commit 19b2b87f5ef0d8caa39e0882fbf832052974b785

This change to the submodule hash should be left out.

This change to the submodule hash should be left out.
Author
Member

Happened accidentally. How can I roll it back?

Happened accidentally. How can I roll it back?

Like this:

cd lib/windows_x64
git checkout a5521c85e03bfd1556ff1e63bf7163235c401497
cd ../..
git commit lib/windows_x64
Like this: ``` cd lib/windows_x64 git checkout a5521c85e03bfd1556ff1e63bf7163235c401497 cd ../.. git commit lib/windows_x64 ```
Sahar A. Kashi added 1 commit 2024-05-02 02:53:07 +02:00
This pull request is marked as a work in progress.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u HIPRT_OPEN_SOURCE:salipour-HIPRT_OPEN_SOURCE
git checkout salipour-HIPRT_OPEN_SOURCE
Sign in to join this conversation.
No reviewers
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
4 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#121050
No description provided.