# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.20)
project(holoscan_gpu_resident_input LANGUAGES CXX CUDA)

# Finds the package holoscan
find_package(holoscan REQUIRED CONFIG
             PATHS "/opt/nvidia/holoscan" "/workspace/holoscan-sdk/install")

add_executable(gpu_resident_input
  gpu_resident_input.cpp
  add_kernel.cu
)

target_link_libraries(gpu_resident_input
  PRIVATE
  holoscan::core
)

# Set CUDA architectures for the target
set_property(TARGET gpu_resident_input PROPERTY CUDA_ARCHITECTURES "native")

# Testing
if(BUILD_TESTING)
  find_package(Python3 REQUIRED COMPONENTS Interpreter)

  add_test(NAME EXAMPLE_CPP_GPU_RESIDENT_INPUT_TEST
    COMMAND bash -c
      "${CMAKE_CURRENT_BINARY_DIR}/gpu_resident_input 2>&1 | \
      ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/../../bin/test_pattern_validation.py \
        --pass-pattern 'verification complete' \
        --pass-pattern 'GPU Resident Performance Metrics' \
        --pass-pattern 'Average execution time:  [0-9]+\\.[0-9]+ us' \
        --pass-pattern 'Saved GPU-resident performance results as CSV to file' \
        --fail-pattern 'ERROR at index' \
        --fail-pattern 'Execution times are not available' \
        --fail-pattern 'Failed to open file'"
    WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
  )
endif()
