diff --git a/projects/rocshmem/CMakeLists.txt b/projects/rocshmem/CMakeLists.txt index f9c3d83d10..5ff7ba6b6d 100644 --- a/projects/rocshmem/CMakeLists.txt +++ b/projects/rocshmem/CMakeLists.txt @@ -199,6 +199,7 @@ set_target_properties( add_subdirectory(src) add_subdirectory(docs) add_subdirectory(tests) +add_subdirectory(examples) ############################################################################### # HIP diff --git a/projects/rocshmem/examples/CMakeLists.txt b/projects/rocshmem/examples/CMakeLists.txt new file mode 100644 index 0000000000..b12a468883 --- /dev/null +++ b/projects/rocshmem/examples/CMakeLists.txt @@ -0,0 +1,53 @@ +############################################################################### +# Copyright (c) 2024 Advanced Micro Devices, Inc. All rights reserved. +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. +############################################################################### + +############################################################################### +# SOURCES +############################################################################### +set(EXAMPLE_SOURCES + rocshmem_allreduce_test.cc + rocshmem_alltoall_test.cc + rocshmem_broadcast_test.cc + rocshmem_getmem_test.cc +) + +foreach(SOURCE_FILE IN LISTS EXAMPLE_SOURCES) + get_filename_component(EXECUTABLE_NAME ${SOURCE_FILE} NAME_WE) + + add_executable(${EXECUTABLE_NAME} ${SOURCE_FILE}) + + target_include_directories( + ${EXECUTABLE_NAME} + PRIVATE + rocshmem::rocshmem + ) + + target_link_libraries( + ${EXECUTABLE_NAME} + PRIVATE + rocshmem::rocshmem + -fgpu-rdc + # xnack allows address translation fault recovery + # required option for managed heap configs + # -mxnack + ) +endforeach() diff --git a/projects/rocshmem/examples/rocshmem_allreduce_test.cc b/projects/rocshmem/examples/rocshmem_allreduce_test.cc index e925a51b05..671130d1f7 100644 --- a/projects/rocshmem/examples/rocshmem_allreduce_test.cc +++ b/projects/rocshmem/examples/rocshmem_allreduce_test.cc @@ -1,19 +1,23 @@ /* -** hipcc -c -fgpu-rdc -x hip rocshmem_allreduce_test.cc -I/opt/rocm/include -** -I$ROCHSMEM_INSTALL_DIR/include -I$OPENMPI_UCX_INSTALL_DIR/include/ -** hipcc -fgpu-rdc --hip-link rocshmem_allreduce_test.o -o rocshmem_allreduce_test -** $ROCHSMEM_INSTALL_DIR/lib/librocshmem.a $OPENMPI_UCX_INSTALL_DIR/lib/libmpi.so -** -L/opt/rocm/lib -lamdhip64 -lhsa-runtime64 -** -** ROC_SHMEM_MAX_NUM_CONTEXTS=2 mpirun -np 8 ./rocshmem_allreduce_test +hipcc -c -fgpu-rdc -x hip rocshmem_allreduce_test.cc \ + -I/opt/rocm/include \ + -I$ROCSHMEM_SRC_DIR/include \ + -I$ROCHSMEM_INSTALL_DIR/include \ + -I$OPENMPI_UCX_INSTALL_DIR/include/ + +hipcc -fgpu-rdc --hip-link rocshmem_allreduce_test.o -o rocshmem_allreduce_test \ + $ROCHSMEM_INSTALL_DIR/lib/librocshmem.a \ + $OPENMPI_UCX_INSTALL_DIR/lib/libmpi.so \ + -L/opt/rocm/lib -lamdhip64 -lhsa-runtime64 + +ROC_SHMEM_MAX_NUM_CONTEXTS=2 mpirun -np 8 ./rocshmem_allreduce_test */ #include -#define __HIP_PLATFORM_AMD__ #include #include -#include +#include #define CHECK_HIP(condition) { \ hipError_t error = condition; \ @@ -92,6 +96,8 @@ int main (int argc, char **argv) int *dest = (int *)roc_shmem_malloc(nelem * sizeof(int)); if (NULL == source || NULL == dest) { std::cout << "Error allocating memory from symmetric heap" << std::endl; + std::cout << "source: " << source << ", dest: " << dest << ", size: " + << sizeof(int) * nelem << std::endl; roc_shmem_global_exit(1); } diff --git a/projects/rocshmem/examples/rocshmem_alltoall_test.cc b/projects/rocshmem/examples/rocshmem_alltoall_test.cc index e1ee85e60f..6f48f07653 100644 --- a/projects/rocshmem/examples/rocshmem_alltoall_test.cc +++ b/projects/rocshmem/examples/rocshmem_alltoall_test.cc @@ -1,19 +1,23 @@ /* -** hipcc -c -fgpu-rdc -x hip rocshmem_alltoall_test.cc -I/opt/rocm/include -** -I$ROCHSMEM_INSTALL_DIR/include -I$OPENMPI_UCX_INSTALL_DIR/include/ -** hipcc -fgpu-rdc --hip-link rocshmem_alltoall_test.o -o rocshmem_alltoall_test -** $ROCHSMEM_INSTALL_DIR/lib/librocshmem.a $OPENMPI_UCX_INSTALL_DIR/lib/libmpi.so -** -L/opt/rocm/lib -lamdhip64 -lhsa-runtime64 -** -** ROC_SHMEM_MAX_NUM_CONTEXTS=2 mpirun -np 8 ./rocshmem_allreduce_test +hipcc -c -fgpu-rdc -x hip rocshmem_alltoall_test.cc \ + -I/opt/rocm/include \ + -I$ROCSHMEM_SRC_DIR/include \ + -I$ROCHSMEM_INSTALL_DIR/include \ + -I$OPENMPI_UCX_INSTALL_DIR/include/ + +hipcc -fgpu-rdc --hip-link rocshmem_alltoall_test.o -o rocshmem_alltoall_test \ + $ROCHSMEM_INSTALL_DIR/lib/librocshmem.a \ + $OPENMPI_UCX_INSTALL_DIR/lib/libmpi.so \ + -L/opt/rocm/lib -lamdhip64 -lhsa-runtime64 + +ROC_SHMEM_MAX_NUM_CONTEXTS=2 mpirun -np 8 ./rocshmem_alltoall_test */ #include -#define __HIP_PLATFORM_AMD__ #include #include -#include +#include #define CHECK_HIP(condition) { \ hipError_t error = condition; \ @@ -97,6 +101,8 @@ int main (int argc, char **argv) int *dest = (int *)roc_shmem_malloc(nelem * npes * sizeof(int)); if (NULL == source || NULL == dest) { std::cout << "Error allocating memory from symmetric heap" << std::endl; + std::cout << "source: " << source << ", dest: " << dest << ", size: " + << sizeof(int) * nelem * npes << std::endl; roc_shmem_global_exit(1); } diff --git a/projects/rocshmem/examples/rocshmem_broadcast_test.cc b/projects/rocshmem/examples/rocshmem_broadcast_test.cc index 48deea1393..c66eca48f7 100644 --- a/projects/rocshmem/examples/rocshmem_broadcast_test.cc +++ b/projects/rocshmem/examples/rocshmem_broadcast_test.cc @@ -1,19 +1,23 @@ /* -** hipcc -c -fgpu-rdc -x hip rocshmem_broadcast_test.cc -I/opt/rocm/include -** -I$ROCHSMEM_INSTALL_DIR/include -I$OPENMPI_UCX_INSTALL_DIR/include/ -** hipcc -fgpu-rdc --hip-link rocshmem_broadcast_test.o -o rocshmem_broadcast_test -** $ROCHSMEM_INSTALL_DIR/lib/librocshmem.a $OPENMPI_UCX_INSTALL_DIR/lib/libmpi.so -** -L/opt/rocm/lib -lamdhip64 -lhsa-runtime64 -** -** ROC_SHMEM_MAX_NUM_CONTEXTS=2 mpirun -np 8 ./rocshmem_broadcast_test +hipcc -c -fgpu-rdc -x hip rocshmem_broadcast_test.cc \ + -I/opt/rocm/include \ + -I$ROCSHMEM_SRC_DIR/include \ + -I$ROCHSMEM_INSTALL_DIR/include \ + -I$OPENMPI_UCX_INSTALL_DIR/include/ + +hipcc -fgpu-rdc --hip-link rocshmem_broadcast_test.o -o rocshmem_broadcast_test \ + $ROCHSMEM_INSTALL_DIR/lib/librocshmem.a \ + $OPENMPI_UCX_INSTALL_DIR/lib/libmpi.so \ + -L/opt/rocm/lib -lamdhip64 -lhsa-runtime64 + +ROC_SHMEM_MAX_NUM_CONTEXTS=2 mpirun -np 8 ./rocshmem_broadcast_test */ #include -#define __HIP_PLATFORM_AMD__ #include #include -#include +#include #define CHECK_HIP(condition) { \ hipError_t error = condition; \ @@ -90,6 +94,8 @@ int main(int argc, char **argv) int *dest = (int *)roc_shmem_malloc(nelem * sizeof(int)); if (NULL == source || NULL == dest) { std::cout << "Error allocating memory from symmetric heap" << std::endl; + std::cout << "source: " << source << ", dest: " << dest << ", size: " + << sizeof(int) * nelem << std::endl; roc_shmem_global_exit(1); } diff --git a/projects/rocshmem/examples/rocshmem_getmem_test.cc b/projects/rocshmem/examples/rocshmem_getmem_test.cc index 48664aa048..e041520c01 100644 --- a/projects/rocshmem/examples/rocshmem_getmem_test.cc +++ b/projects/rocshmem/examples/rocshmem_getmem_test.cc @@ -1,19 +1,23 @@ /* -** hipcc -c -fgpu-rdc -x hip rocshmem_getmem_test.cc -I/opt/rocm/include -** -I$ROCHSMEM_INSTALL_DIR/include -I$OPENMPI_UCX_INSTALL_DIR/include/ -** hipcc -fgpu-rdc --hip-link rocshmem_getmem_test.o -o rocshmem_getmem_test -** $ROCHSMEM_INSTALL_DIR/lib/librocshmem.a $OPENMPI_UCX_INSTALL_DIR/lib/libmpi.so -** -L/opt/rocm/lib -lamdhip64 -lhsa-runtime64 -** -** ROC_SHMEM_MAX_NUM_CONTEXTS=2 mpirun -np 2 ./rocshmem_getmem_test +hipcc -c -fgpu-rdc -x hip rocshmem_getmem_test.cc \ + -I/opt/rocm/include \ + -I$ROCSHMEM_SRC_DIR/include \ + -I$ROCHSMEM_INSTALL_DIR/include \ + -I$OPENMPI_UCX_INSTALL_DIR/include/ + +hipcc -fgpu-rdc --hip-link rocshmem_getmem_test.o -o rocshmem_getmem_test \ + $ROCHSMEM_INSTALL_DIR/lib/librocshmem.a \ + $OPENMPI_UCX_INSTALL_DIR/lib/libmpi.so \ + -L/opt/rocm/lib -lamdhip64 -lhsa-runtime64 + +ROC_SHMEM_MAX_NUM_CONTEXTS=2 mpirun -np 2 ./rocshmem_getmem_test */ #include -#define __HIP_PLATFORM_AMD__ #include #include -#include +#include #define CHECK_HIP(condition) { \ hipError_t error = condition; \ @@ -62,6 +66,8 @@ int main (int argc, char **argv) int *dst = (int *)roc_shmem_malloc(nelem * sizeof(int)); if (NULL == src || NULL == dst) { std::cout << "Error allocating memory from symmetric heap" << std::endl; + std::cout << "source: " << src << ", dest: " << dst << ", size: " + << sizeof(int) * nelem << std::endl; roc_shmem_global_exit(1); }