|
| 1 | +# Copyright (c) Advanced Micro Devices, Inc. |
| 2 | +# SPDX-License-Identifier: MIT |
| 3 | + |
| 4 | +cmake_minimum_required(VERSION 3.21 FATAL_ERROR) |
| 5 | + |
| 6 | +if(ROCPROFSYS_DISABLE_EXAMPLES) |
| 7 | + get_filename_component(_DIR ${CMAKE_CURRENT_LIST_DIR} NAME) |
| 8 | + if( |
| 9 | + "rocprofiler-systems-shmem-examples" IN_LIST ROCPROFSYS_DISABLE_EXAMPLES |
| 10 | + OR ${_DIR} IN_LIST ROCPROFSYS_DISABLE_EXAMPLES |
| 11 | + ) |
| 12 | + return() |
| 13 | + endif() |
| 14 | +endif() |
| 15 | + |
| 16 | +# oshcc is the OpenSHMEM C compiler wrapper (e.g. from Open MPI); it provides |
| 17 | +# the correct include paths and libraries for shmem.h and OpenSHMEM runtime. |
| 18 | +# Prefer /usr/bin/oshcc (system package) to avoid version mismatch with oshrun. |
| 19 | +find_program(OSHCC_EXECUTABLE NAMES oshcc PATHS /usr/bin NO_DEFAULT_PATH) |
| 20 | +if(NOT OSHCC_EXECUTABLE) |
| 21 | + find_program(OSHCC_EXECUTABLE NAMES oshcc) |
| 22 | +endif() |
| 23 | +if(NOT OSHCC_EXECUTABLE) |
| 24 | + if("${CMAKE_PROJECT_NAME}" STREQUAL "rocprofiler-systems" AND "$ENV{ROCPROFSYS_CI}") |
| 25 | + set(_MSG_TYPE STATUS) # don't generate warnings during CI |
| 26 | + else() |
| 27 | + set(_MSG_TYPE AUTHOR_WARNING) |
| 28 | + endif() |
| 29 | + message( |
| 30 | + ${_MSG_TYPE} |
| 31 | + "oshcc not found. Skipping SHMEM examples (shmem_hello, shmem_pingpong)." |
| 32 | + ) |
| 33 | + return() |
| 34 | +else() |
| 35 | + message(STATUS "oshcc found: ${OSHCC_EXECUTABLE}") |
| 36 | +endif() |
| 37 | + |
| 38 | +# Build with oshcc so shmem.h and OpenSHMEM libs are found. Output to project build root. |
| 39 | +set(_SHMEM_BINDIR ${CMAKE_BINARY_DIR}) |
| 40 | +set(_SHMEM_SRCDIR ${CMAKE_CURRENT_SOURCE_DIR}) |
| 41 | +set(_SHMEM_HELLO_EXE ${_SHMEM_BINDIR}/shmem_hello${CMAKE_EXECUTABLE_SUFFIX}) |
| 42 | +set(_SHMEM_PINGPONG_EXE ${_SHMEM_BINDIR}/shmem_pingpong${CMAKE_EXECUTABLE_SUFFIX}) |
| 43 | + |
| 44 | +add_custom_command( |
| 45 | + OUTPUT ${_SHMEM_HELLO_EXE} |
| 46 | + COMMAND ${OSHCC_EXECUTABLE} ${_SHMEM_SRCDIR}/shmem_hello.c -o ${_SHMEM_HELLO_EXE} |
| 47 | + DEPENDS ${_SHMEM_SRCDIR}/shmem_hello.c |
| 48 | + COMMENT "Building shmem_hello with oshcc" |
| 49 | + VERBATIM |
| 50 | +) |
| 51 | +add_custom_target(shmem_hello ALL DEPENDS ${_SHMEM_HELLO_EXE}) |
| 52 | + |
| 53 | +add_custom_command( |
| 54 | + OUTPUT ${_SHMEM_PINGPONG_EXE} |
| 55 | + COMMAND |
| 56 | + ${OSHCC_EXECUTABLE} ${_SHMEM_SRCDIR}/shmem_pingpong.c -o ${_SHMEM_PINGPONG_EXE} |
| 57 | + DEPENDS ${_SHMEM_SRCDIR}/shmem_pingpong.c |
| 58 | + COMMENT "Building shmem_pingpong with oshcc" |
| 59 | + VERBATIM |
| 60 | +) |
| 61 | +add_custom_target(shmem_pingpong ALL DEPENDS ${_SHMEM_PINGPONG_EXE}) |
| 62 | + |
| 63 | +# Export paths for rocprof-sys-shmem-tests.cmake (same project) |
| 64 | +set(ROCPROFSYS_SHMEM_HELLO_EXE |
| 65 | + "${_SHMEM_HELLO_EXE}" |
| 66 | + CACHE INTERNAL |
| 67 | + "Path to shmem_hello executable" |
| 68 | +) |
| 69 | +set(ROCPROFSYS_SHMEM_PINGPONG_EXE |
| 70 | + "${_SHMEM_PINGPONG_EXE}" |
| 71 | + CACHE INTERNAL |
| 72 | + "Path to shmem_pingpong executable" |
| 73 | +) |
| 74 | + |
| 75 | +if(ROCPROFSYS_INSTALL_EXAMPLES) |
| 76 | + install( |
| 77 | + PROGRAMS ${_SHMEM_HELLO_EXE} ${_SHMEM_PINGPONG_EXE} |
| 78 | + DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/rocprofiler-systems/examples |
| 79 | + COMPONENT rocprofiler-systems-examples |
| 80 | + OPTIONAL |
| 81 | + ) |
| 82 | +endif() |
0 commit comments