Skip to content

Commit 9f6c155

Browse files
committed
Add rocAL examples
1 parent 7c39e36 commit 9f6c155

32 files changed

+2889
-0
lines changed

Libraries/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ if(
4545
add_subdirectory(hipSPARSE)
4646
add_subdirectory(hipSPARSELt)
4747
add_subdirectory(hipTensor)
48+
add_subdirectory(rocAL)
4849
add_subdirectory(rocALUTION)
4950
add_subdirectory(rocBLAS)
5051
add_subdirectory(rocFFT)

Libraries/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ ifneq ($(GPU_RUNTIME), CUDA)
3434
LIBRARIES += \
3535
hipBLASLt \
3636
hipTensor \
37+
rocAL \
3738
rocALUTION \
3839
rocBLAS \
3940
rocFFT \

Libraries/rocAL/CMakeLists.txt

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Copyright (c) 2025 Advanced Micro Devices, Inc. All rights reserved.
2+
#
3+
# Permission is hereby granted, free of charge, to any person obtaining a copy
4+
# of this software and associated documentation files (the "Software"), to deal
5+
# in the Software without restriction, including without limitation the rights
6+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
# copies of the Software, and to permit persons to whom the Software is
8+
# furnished to do so, subject to the following conditions:
9+
#
10+
# The above copyright notice and this permission notice shall be included in all
11+
# copies or substantial portions of the Software.
12+
#
13+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19+
# SOFTWARE.
20+
21+
cmake_minimum_required(VERSION 3.21 FATAL_ERROR)
22+
project(rocAL_examples LANGUAGES CXX)
23+
include(CTest)
24+
25+
file(RELATIVE_PATH folder_bin ${CMAKE_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR})
26+
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/${folder_bin})
27+
28+
if(CMAKE_SYSTEM_NAME MATCHES "Windows")
29+
message(STATUS "rocAL examples are only available on Linux")
30+
return()
31+
else()
32+
set(ROCM_ROOT
33+
"/opt/rocm"
34+
CACHE PATH
35+
"Root directory of the ROCm installation"
36+
)
37+
endif()
38+
39+
list(APPEND CMAKE_PREFIX_PATH "${ROCM_ROOT}")
40+
41+
find_library(ROCAL_LIBRARY
42+
NAMES rocal
43+
PATHS "${ROCM_ROOT}/lib"
44+
PATH_SUFFIXES lib lib64
45+
)
46+
47+
if(NOT ROCAL_LIBRARY)
48+
message(STATUS "rocAL could not be found, not building rocAL examples")
49+
return(1)
50+
endif()
51+
52+
add_subdirectory(basic)
53+
add_subdirectory(dataloader)
54+
add_subdirectory(image_augmentation)
55+
add_subdirectory(video)

Libraries/rocAL/Makefile

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# MIT License
2+
#
3+
# Copyright (c) 2025 Advanced Micro Devices, Inc. All rights reserved.
4+
#
5+
# Permission is hereby granted, free of charge, to any person obtaining a copy
6+
# of this software and associated documentation files (the "Software"), to deal
7+
# in the Software without restriction, including without limitation the rights
8+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
# copies of the Software, and to permit persons to whom the Software is
10+
# furnished to do so, subject to the following conditions:
11+
#
12+
# The above copyright notice and this permission notice shall be included in all
13+
# copies or substantial portions of the Software.
14+
#
15+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
# SOFTWARE.
22+
23+
EXAMPLES := \
24+
basic \
25+
dataloader \
26+
image_augmentation \
27+
video
28+
29+
all: $(EXAMPLES)
30+
31+
clean: TARGET=clean
32+
clean: all
33+
34+
$(EXAMPLES):
35+
$(MAKE) -C $@ $(TARGET)
36+
37+
.PHONY: all clean $(EXAMPLES)

Libraries/rocAL/README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# rocAL Examples
2+
3+
## Summary
4+
5+
The examples in this subdirectory showcase the functionality of the [rocAL](https://github.com/ROCm/rocAL) library. The examples build only on Linux for the ROCm (AMD GPU) backend.
6+
7+
## Prerequisites
8+
9+
### Linux
10+
11+
- [CMake](https://cmake.org/download/) (at least version 3.21).
12+
- Or GNU Make - available via the distribution's package manager.
13+
- [ROCm](https://rocm.docs.amd.com/projects/HIP/en/latest/install/install.html) (at least version 7.x.x).
14+
- [rocAL](https://github.com/ROCm/rocAL): `rocal-dev` package available from [repo.radeon.com](https://repo.radeon.com/rocm/). The repository is added during the standard ROCm [install procedure](https://rocm.docs.amd.com/projects/HIP/en/latest/install/install.html).
15+
16+
### Windows
17+
18+
Support for Windows will be included in the future.
19+
20+
## Building
21+
22+
### Linux
23+
24+
Ensure the dependencies are installed, or use the [provided Dockerfiles](../../Dockerfiles/) to build and run the examples in a containerized environment that has all prerequisites installed.
25+
26+
#### Using CMake
27+
28+
All examples in the `rocAL` subdirectory can either be built by a single CMake project or be built independently.
29+
30+
- `$ cd Libraries/rocAL`
31+
- `$ cmake -S . -B build`
32+
- `$ cmake --build build`
33+
34+
#### Using Make
35+
36+
All examples can be built by a single invocation to Make or be built independently.
37+
38+
- `$ cd Libraries/rocAL`
39+
- `$ make`

Libraries/rocAL/basic/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rocal_basic
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# MIT License
2+
#
3+
# Copyright (c) 2025 Advanced Micro Devices, Inc. All rights reserved.
4+
#
5+
# Permission is hereby granted, free of charge, to any person obtaining a copy
6+
# of this software and associated documentation files (the "Software"), to deal
7+
# in the Software without restriction, including without limitation the rights
8+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
# copies of the Software, and to permit persons to whom the Software is
10+
# furnished to do so, subject to the following conditions:
11+
#
12+
# The above copyright notice and this permission notice shall be included in all
13+
# copies or substantial portions of the Software.
14+
#
15+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
# SOFTWARE.
22+
23+
set(example_name rocal_basic)
24+
25+
cmake_minimum_required(VERSION 3.21 FATAL_ERROR)
26+
project(${example_name} LANGUAGES CXX)
27+
28+
if(GPU_RUNTIME STREQUAL "CUDA")
29+
message(STATUS "rocAL examples do not support the CUDA runtime")
30+
return()
31+
endif()
32+
33+
set(CMAKE_CXX_STANDARD 17)
34+
set(CMAKE_CXX_EXTENSIONS OFF)
35+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
36+
37+
if(CMAKE_SYSTEM_NAME MATCHES "Windows")
38+
message(STATUS "rocAL examples are only available on Linux")
39+
return()
40+
else()
41+
set(ROCM_ROOT
42+
"/opt/rocm"
43+
CACHE PATH
44+
"Root directory of the ROCm installation"
45+
)
46+
endif()
47+
48+
list(APPEND CMAKE_PREFIX_PATH "${ROCM_ROOT}")
49+
50+
find_library(ROCAL_LIBRARY
51+
NAMES rocal
52+
PATHS"${ROCM_ROOT}/lib"
53+
PATH_SUFFIXES lib lib64
54+
REQUIRED
55+
)
56+
57+
find_package(OpenCV REQUIRED)
58+
59+
add_executable(${example_name} main.cpp)
60+
# Make example runnable using ctest
61+
add_test(NAME ${example_name} COMMAND ${example_name})
62+
63+
# Link to rocAL library
64+
target_link_libraries(${example_name} PRIVATE ${ROCAL_LIBRARY} ${OpenCV_LIBS})
65+
66+
# Include directories
67+
target_include_directories(
68+
${example_name}
69+
PRIVATE "../../../External" ${ROCM_ROOT}/include ${ROCM_ROOT}/include/rocal ${OpenCV_INCLUDE_DIRS}
70+
)
71+
72+
# Set example data directory as compile definition
73+
target_compile_definitions(
74+
${example_name}
75+
PRIVATE EXAMPLE_DATA_DIR="${CMAKE_CURRENT_SOURCE_DIR}/../data"
76+
)
77+
78+
install(TARGETS ${example_name})

Libraries/rocAL/basic/Makefile

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# MIT License
2+
#
3+
# Copyright (c) 2025 Advanced Micro Devices, Inc. All rights reserved.
4+
#
5+
# Permission is hereby granted, free of charge, to any person obtaining a copy
6+
# of this software and associated documentation files (the "Software"), to deal
7+
# in the Software without restriction, including without limitation the rights
8+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
# copies of the Software, and to permit persons to whom the Software is
10+
# furnished to do so, subject to the following conditions:
11+
#
12+
# The above copyright notice and this permission notice shall be included in all
13+
# copies or substantial portions of the Software.
14+
#
15+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
# SOFTWARE.
22+
23+
EXAMPLE := rocal_basic
24+
EXTERNAL_DIR := ../../../External
25+
GPU_RUNTIME := HIP
26+
27+
# HIP variables
28+
ROCM_INSTALL_DIR := /opt/rocm
29+
30+
HIP_INCLUDE_DIR := $(ROCM_INSTALL_DIR)/include
31+
ROCAL_INCLUDE_DIR := $(HIP_INCLUDE_DIR)/rocal
32+
OPENCV_INCLUDE_DIR := /usr/include/opencv4
33+
34+
CXX ?= g++
35+
36+
# Common variables and flags
37+
CXX_STD := c++17
38+
ICXXFLAGS := -std=$(CXX_STD)
39+
ICPPFLAGS := -isystem $(HIP_INCLUDE_DIR) -isystem $(ROCAL_INCLUDE_DIR) -isystem $(OPENCV_INCLUDE_DIR) -I $(EXTERNAL_DIR)
40+
ILDFLAGS := -L $(ROCM_INSTALL_DIR)/lib
41+
ILDLIBS := -lrocal -lopencv_core -lopencv_imgproc -lopencv_imgcodecs -lopencv_highgui
42+
43+
ifeq ($(GPU_RUNTIME), HIP)
44+
CXXFLAGS ?= -Wall -Wextra
45+
CPPFLAGS += -D__HIP_PLATFORM_AMD__
46+
COMPILER := $(CXX)
47+
else
48+
$(error GPU_RUNTIME is set to "$(GPU_RUNTIME)". GPU_RUNTIME must be HIP)
49+
endif
50+
51+
ICXXFLAGS += $(CXXFLAGS)
52+
ICPPFLAGS += $(CPPFLAGS) -DEXAMPLE_DATA_DIR=\"$(CURDIR)/../data\"
53+
ILDFLAGS += $(LDFLAGS)
54+
ILDLIBS += $(LDLIBS)
55+
56+
$(EXAMPLE): main.cpp
57+
$(COMPILER) $(ICXXFLAGS) $(ICPPFLAGS) $(ILDFLAGS) -o $@ $< $(ILDLIBS)
58+
59+
clean:
60+
$(RM) $(EXAMPLE)
61+
62+
.PHONY: clean

0 commit comments

Comments
 (0)