Skip to content

Commit 2cd587e

Browse files
committed
refactor: categorize examples/ directory and update scripts/run_examples.py (#42)
* docs: remove the `examples/` structure diagram * docs: update `README.md` to reflect the new file structure of `examples/` * style: ruff format `scripts/run_examples.py` * refactor: change the directory structure of `examples/` to categorize different types of examples and update `scripts/run_examples.py` - restructure the `examples/` to categorize different types of examples - update `scripts/run_examples.py` to accommodate this change and be able to specify an example directory, specific examples, or fuzzy example names
1 parent c86bad8 commit 2cd587e

12 files changed

Lines changed: 135 additions & 46 deletions

File tree

‎README.md‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,18 +173,20 @@ After having a successful build and a complete `cluster.yaml`, we are ready for
173173
### 1. Run Internal Examples
174174

175175
#### 1.1. Run a Single Example
176-
To run an internal example program (e.g., `examples/all_reduce.cc`), just run:
176+
The repository organizes example suites by collective paradigm layout under `examples/`.
177+
178+
To run an internal example program (e.g., `examples/mpi/all_reduce.cc`), just run:
177179

178180
```bash
179181
# Build and run the executable across the cluster based on the config specified in your `cluster.yaml`
180-
icclrun --config [path-to-your-cluster.yaml] --build all_reduce [program args]
182+
icclrun --config [path-to-your-cluster.yaml] --build mpi/all_reduce [program args]
181183
```
182184

183185
- `--config / -c` : Path to the cluster YAML file.
184186
- `--build` : Instructs `icclrun` to compile the library on each node before execution. If omitted, `icclrun` assumes the library is already installed at a consistent location.
185187
- `--launcher` : Specify the backend launcher to be used. Default to `ompi`.
186188

187-
The executable (e.g., `all_reduce`) and its arguments follow the options.
189+
The executable (e.g., `mpi/all_reduce`) and its arguments follow the options.
188190

189191
For more details, run:
190192

@@ -207,7 +209,7 @@ chmod +x ./scripts/run_examples.sh
207209
For all the options of the script, see:
208210

209211
```bash
210-
./run_examples --help
212+
./scripts/run_examples.py --help
211213
```
212214

213215
### 2. Run a Custom User Program

‎examples/CMakeLists.txt‎

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,61 @@
11
file(GLOB_RECURSE EXAMPLE_SOURCES "*.cc")
22

33
foreach(source_file ${EXAMPLE_SOURCES})
4-
get_filename_component(example_name ${source_file} NAME_WE)
4+
file(RELATIVE_PATH rel_file "${CMAKE_CURRENT_SOURCE_DIR}" "${source_file}")
55

6-
add_executable(${example_name} ${source_file})
6+
get_filename_component(file_dir ${rel_file} DIRECTORY)
7+
get_filename_component(file_we ${rel_file} NAME_WE)
78

8-
target_link_libraries(${example_name} PRIVATE infiniccl)
9+
if(file_dir)
10+
string(REPLACE "/" "_" target_name "${file_dir}_${file_we}")
11+
else()
12+
set(target_name ${file_we})
13+
endif()
14+
15+
add_executable(${target_name} ${source_file})
16+
17+
set_target_properties(${target_name} PROPERTIES
18+
OUTPUT_NAME "${file_we}"
19+
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${file_dir}"
20+
)
21+
22+
target_link_libraries(${target_name} PRIVATE infiniccl)
923

1024
# Add runtime and backend dependencies for direct runtime/backend usage.
1125
if(WITH_NVIDIA)
12-
target_link_libraries(${example_name} PRIVATE CUDA::cudart)
26+
target_link_libraries(${target_name} PRIVATE CUDA::cudart)
1327
endif()
1428

1529
if(WITH_ILUVATAR)
1630
set_source_files_properties(${source_file} PROPERTIES LANGUAGE CXX)
17-
set_target_properties(${example_name} PROPERTIES
31+
set_target_properties(${target_name} PROPERTIES
1832
RULE_LAUNCH_COMPILE "${ILUVATAR_CUDA_COMPILER} "
1933
)
20-
target_compile_options(${example_name} PRIVATE ${ILUVATAR_CUDA_FLAGS} "-Wno-unused-command-line-argument")
21-
target_link_libraries(${example_name} PRIVATE CUDA::cudart CUDA::cuda_driver)
34+
target_compile_options(${target_name} PRIVATE ${ILUVATAR_CUDA_FLAGS} "-Wno-unused-command-line-argument")
35+
target_link_libraries(${target_name} PRIVATE CUDA::cudart CUDA::cuda_driver)
2236
endif()
2337

2438
if(WITH_METAX)
25-
target_link_libraries(${example_name} PRIVATE ${MACA_RUNTIME_LIB})
26-
target_compile_options(${example_name} PRIVATE "-x" "maca")
39+
target_link_libraries(${target_name} PRIVATE ${MACA_RUNTIME_LIB})
40+
target_compile_options(${target_name} PRIVATE "-x" "maca")
2741
endif()
2842

2943
if(WITH_MOORE)
30-
target_link_libraries(${example_name} PRIVATE ${MUSART_LIB})
31-
target_compile_options(${example_name} PRIVATE "-x" "musa")
44+
target_link_libraries(${target_name} PRIVATE ${MUSART_LIB})
45+
target_compile_options(${target_name} PRIVATE "-x" "musa")
3246
endif()
3347

3448
if(WITH_CAMBRICON)
35-
target_link_libraries(${example_name} PRIVATE ${CAMBRICON_RUNTIME_LIB})
49+
target_link_libraries(${target_name} PRIVATE ${CAMBRICON_RUNTIME_LIB})
3650
endif()
3751

3852
if(WITH_OMPI OR WITH_MPICH)
39-
target_link_libraries(${example_name} PRIVATE MPI::MPI_CXX)
53+
target_link_libraries(${target_name} PRIVATE MPI::MPI_CXX)
4054
endif()
4155

4256
# Explicitly allow examples to "peek" into the internal `src` and binary dirs.
4357
# This is necessary because these were marked `PRIVATE` in the library's CMake.
44-
target_include_directories(${example_name} PRIVATE
58+
target_include_directories(${target_name} PRIVATE
4559
${CMAKE_CURRENT_SOURCE_DIR}
4660
"${PROJECT_SOURCE_DIR}/src" # For internal templates like `runtime.h`.
4761
"${CMAKE_BINARY_DIR}/src" # For the generated `backend_manifest.h`.

0 commit comments

Comments
 (0)