Skip to content
Open

Ios #401

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
# To add more build types (Release, Debug, RelWithDebInfo, etc.) customize the build_type list.
matrix:

os: [ubuntu-latest]
os: [ubuntu-latest, macos-latest]
#os: [ubuntu-latest, windows-latest]
build_type: [Release]
#c_compiler: [gcc, clang, cl]
Expand All @@ -36,10 +36,14 @@ jobs:
- os: ubuntu-latest
c_compiler: gcc
cpp_compiler: g++
#- os: ubuntu-latest
# c_compiler: clang
# cpp_compiler: clang++
#exclude:
# macOS (Apple Silicon arm64 runner) with Apple Clang
- os: macos-latest
c_compiler: clang
cpp_compiler: clang++
exclude:
# the default gcc entry must not apply to the macOS runner
- os: macos-latest
c_compiler: gcc
#- os: windows-latest
# c_compiler: gcc
#- os: windows-latest
Expand All @@ -52,12 +56,18 @@ jobs:
with:
submodules: recursive

- name: Install system dependencies
- name: Install system dependencies (Linux)
if: runner.os == 'Linux'
run: |
sudo apt update
sudo apt-get update
sudo apt-get -y install libglm-dev fuse libfuse2 ocl-icd-opencl-dev pocl-opencl-icd libassimp-dev libopencv-dev libfftw3-dev libgsl-dev libspdlog-dev

- name: Install system dependencies (macOS)
if: runner.os == 'macOS'
run: |
brew install gsl assimp glm opencv libomp spdlog opencl-headers opencl-clhpp-headers

- name: Set reusable strings
# Turn repeated input strings (such as the build output directory) into step outputs. These step outputs can be used throughout the workflow file.
id: strings
Expand Down
3 changes: 2 additions & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
url = git@github.com:llohse/libnpy.git
[submodule "external/CLWrapper"]
path = external/CLWrapper
url = git@github.com:otto-link/CLWrapper.git
url = https://github.com/Leonhardmaster2/CLWrapper.git
branch = ios
[submodule "external/PointSampler"]
path = external/PointSampler
url = git@github.com:otto-link/PointSampler.git
Expand Down
144 changes: 136 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,33 @@ if(MSVC)

add_definitions(-DHMAP_MSVC)

add_compile_options(/W4 /Od)
# do NOT pass /Od here: add_compile_options lands after the per-config flags
# on the MSVC command line, where it overrides Release's /O2 (last flag wins),
# silently disabling optimization in every Release build
add_compile_options(/W4 "$<$<NOT:$<CONFIG:Debug>>:/fp:fast>")

add_compile_definitions(M_PI=3.14159265358979323846)

elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
# MATCHES so that AppleClang (macOS default compiler) is covered too:
# STREQUAL "Clang" silently skipped this branch on macOS, which left Apple
# Silicon builds without any optimization flags (same bug class as the MSVC
# /Od issue fixed in 7237678)
elseif(CMAKE_CXX_COMPILER_ID MATCHES "^(Clang|AppleClang)$")

message(STATUS "Compiler: Clang")
message(STATUS "Compiler: Clang (${CMAKE_CXX_COMPILER_ID})")

add_compile_options(
-Wall
-Wextra
-Wpedantic
-O3
-Ofast
-ffast-math
-pthread
-fPIC
# do NOT apply optimization flags for Debug builds; mirrors the MSVC
# branch ($<$<NOT:$<CONFIG:Debug>>:...>); on single-config generators
# without an explicit build type the flags apply by default; note that
# -Ofast is deprecated in recent clang, "-O3 -ffast-math" is equivalent
$<$<NOT:$<CONFIG:Debug>>:-O3>
$<$<NOT:$<CONFIG:Debug>>:-ffast-math>
-Wno-deprecated-enum-enum-conversion
-Wno-header-guard
-Wno-gnu-zero-variadic-macro-arguments)
Expand All @@ -78,6 +88,20 @@ elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")

endif()

# -----------------------------------------------------------------------------
# Architecture tuning
# -----------------------------------------------------------------------------

# Apple Silicon: target the M1 baseline so the compiler can exploit the full
# NEON/FMA instruction set available on every Apple Silicon chip (M1 and up)
if(APPLE AND CMAKE_SYSTEM_PROCESSOR MATCHES "arm64")

message(STATUS "CPU tuning: Apple Silicon (-mcpu=apple-m1)")

add_compile_options($<$<NOT:$<CONFIG:Debug>>:-mcpu=apple-m1>)

endif()

# -----------------------------------------------------------------------------
# Output
# -----------------------------------------------------------------------------
Expand All @@ -90,15 +114,119 @@ set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)

find_package(GSL REQUIRED COMPONENTS gsl gslcblas)
find_package(assimp REQUIRED)

# Homebrew assimp may embed an absolute libz.tbd path pointing at a
# CommandLineTools SDK that no longer exists; rebind ZLIB::ZLIB (and the
# assimp target link libraries) to the zlib from the active SDK when that
# happens (macOS only)
if(APPLE)
find_library(
HMAP_SDK_ZLIB z
PATHS "${CMAKE_OSX_SYSROOT}/usr/lib"
NO_DEFAULT_PATH)

if(HMAP_SDK_ZLIB AND TARGET ZLIB::ZLIB)
get_target_property(_zlib_loc ZLIB::ZLIB IMPORTED_LOCATION)

if(_zlib_loc AND NOT EXISTS "${_zlib_loc}")
set_target_properties(ZLIB::ZLIB PROPERTIES IMPORTED_LOCATION
"${HMAP_SDK_ZLIB}")
endif()
endif()

if(HMAP_SDK_ZLIB AND TARGET assimp::assimp)
get_target_property(_assimp_libs assimp::assimp INTERFACE_LINK_LIBRARIES)
set(_assimp_libs_fixed "")

foreach(_lib ${_assimp_libs})
if(_lib MATCHES "CommandLineTools/.*libz\\.tbd" AND NOT EXISTS
"${_lib}")
list(APPEND _assimp_libs_fixed "${HMAP_SDK_ZLIB}")
else()
list(APPEND _assimp_libs_fixed "${_lib}")
endif()
endforeach()

set_target_properties(assimp::assimp PROPERTIES INTERFACE_LINK_LIBRARIES
"${_assimp_libs_fixed}")
endif()
endif()
find_package(glm REQUIRED)
find_package(OpenMP REQUIRED)
find_package(OpenCV REQUIRED)
find_package(OpenCL REQUIRED)

# On macOS the OpenCL C/C++ headers come from keg-only Homebrew packages
# (brew install opencl-headers opencl-clhpp-headers) which are not linked
# into the default include path: point the compiler at them
if(APPLE)
if(NOT DEFINED HOMEBREW_PREFIX)
execute_process(
COMMAND brew --prefix
OUTPUT_VARIABLE HOMEBREW_PREFIX
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET)
endif()

foreach(_keg opencl-headers opencl-clhpp-headers)
if(EXISTS "${HOMEBREW_PREFIX}/opt/${_keg}/include")
include_directories("${HOMEBREW_PREFIX}/opt/${_keg}/include")
endif()
endforeach()
endif()

include_directories(${OpenCV_INCLUDE_DIRS})

# OpenMP
add_compile_options(${OpenMP_CXX_FLAGS})
#
# Apple Clang does not ship OpenMP; on macOS it is provided by the Homebrew
# `libomp` keg (brew install libomp). Point FindOpenMP at it when present.
if(APPLE AND CMAKE_CXX_COMPILER_ID MATCHES "Clang")
if(NOT DEFINED HOMEBREW_PREFIX)
execute_process(
COMMAND brew --prefix
OUTPUT_VARIABLE HOMEBREW_PREFIX
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET)
endif()

if(EXISTS "${HOMEBREW_PREFIX}/opt/libomp")
set(OpenMP_C_FLAGS
"-Xpreprocessor -fopenmp -I${HOMEBREW_PREFIX}/opt/libomp/include")
set(OpenMP_CXX_FLAGS
"-Xpreprocessor -fopenmp -I${HOMEBREW_PREFIX}/opt/libomp/include")
set(OpenMP_C_LIB_NAMES libomp)
set(OpenMP_CXX_LIB_NAMES libomp)
set(OpenMP_libomp_LIBRARY
"${HOMEBREW_PREFIX}/opt/libomp/lib/libomp.dylib")
endif()
endif()

find_package(OpenMP QUIET)

if(NOT OpenMP_CXX_FOUND)
if(APPLE)
# Only a few kernels use OpenMP (flow accumulation, drainage basins,
# local metrics); tile-based threading keeps working without it
message(
WARNING
"OpenMP not found: `brew install libomp` to enable it. Building "
"without OpenMP support.")
# without -fopenmp, clang ignores `#pragma omp` directives: silence the
# associated warnings
add_compile_options(-Wno-unknown-pragmas)
else()
message(FATAL_ERROR "OpenMP is required on this platform")
endif()
endif()

# OpenMP
if(OpenMP_CXX_FOUND)
# OpenMP_CXX_FLAGS is a space-separated string: split it so that
# add_compile_options receives individual tokens (matters for the macOS
# libomp hint "-Xpreprocessor -fopenmp -I...")
separate_arguments(_openmp_cxx_flags UNIX_COMMAND "${OpenMP_CXX_FLAGS}")
add_compile_options(${_openmp_cxx_flags})
endif()

# OpenCL
add_compile_definitions(CL_HPP_MINIMUM_OPENCL_VERSION=120
Expand Down
6 changes: 5 additions & 1 deletion HighMap/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,12 @@ target_link_libraries(
nn-c::nn-c
NoiseLib
terrain-descriptors
OpenMP::OpenMP_CXX
${OpenCV_LIBS}
point_sampler
clwrapper
${OpenCL_LIBRARIES})

# OpenMP is optional on macOS (see root CMakeLists)
if(OpenMP_CXX_FOUND)
target_link_libraries(${PROJECT_NAME} OpenMP::OpenMP_CXX)
endif()
46 changes: 23 additions & 23 deletions HighMap/include/highmap/erosion.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -849,33 +849,33 @@ void hydraulic_particle(Array &z,
float angle_bias = 30.f);

/**
* @brief Particle-based hydraulic erosion with flow-field coupling
* (McDonald's model): persistent per-cell discharge and momentum fields,
* exponentially filtered across iterations, couple particles through the
* mean local flow, producing coherent drainage networks; a bank-stability
* debris flow runs in the same solver loop against a separate sediment
* layer. Clean-room port of erosiv/soillib (LGPL-3, Nicholas McDonald),
* @brief Particle-based hydraulic erosion with flow-field coupling (McDonald's
* model): persistent per-cell discharge and momentum fields, exponentially
* filtered across iterations, couple particles through the mean local flow,
* producing coherent drainage networks; a bank-stability debris flow runs in
* the same solver loop against a separate sediment layer. Clean-room port of
* erosiv/soillib (LGPL-3, Nicholas McDonald),
* https://github.com/erosiv/soillib.
*
* Parameters are physical: the terrain is interpreted as a
* world_extent_km x world_extent_km domain with height range z_scale_km.
* This makes behavior consistent across resolutions.
* Parameters are physical: the terrain is interpreted as a world_extent_km x
* world_extent_km domain with height range z_scale_km. This makes behavior
* consistent across resolutions.
*
* @warning Single-resolution runs numerically diverge at high resolutions
* (>= 1024^2) beyond a few hundred steps with default parameters — use
* @warning Single-resolution runs numerically diverge at high resolutions (>=
* 1024^2) beyond a few hundred steps with default parameters — use
* hydraulic_mcdonald_multiscale for high-resolution terrain.
*
* Results are reproducible up to atomic scheduling order (particles read
* fields that other particles concurrently modify via atomic adds — a
* property shared with the reference implementation).
* Results are reproducible up to atomic scheduling order (particles read fields
* that other particles concurrently modify via atomic adds — a property shared
* with the reference implementation).
*
* @param z Input/output heightmap. In: bedrock. Out: bedrock
* plus sediment (total surface).
* @param z Input/output heightmap. In: bedrock. Out: bedrock plus
* sediment (total surface).
* @param steps Number of erosion iterations.
* @param seed Random seed number.
* @param p_sediment_map Optional output: final sediment layer.
* @param p_discharge_map Optional output: water discharge field (usable as
* a river / water mask).
* @param p_discharge_map Optional output: water discharge field (usable as a
* river / water mask).
* @param world_extent_km Physical domain edge length [km].
* @param z_scale_km Physical height range of z's [0, 1] span [km].
* @param samples Particles per iteration.
Expand Down Expand Up @@ -927,11 +927,11 @@ void hydraulic_mcdonald(Array &z,

/**
* @brief Multiscale driver for hydraulic_mcdonald: erodes on a halving
* resolution ladder derived from z.shape (coarsest first), resampling the
* full model state (bedrock, sediment, discharge, momentum) between levels.
* The numerically stable route to high-resolution erosion with this model.
* {512, 256, 128} on a 1024^2 input runs 256^2 (512 steps), 512^2 (256),
* then 1024^2 (128). See hydraulic_mcdonald for the model and parameters.
* resolution ladder derived from z.shape (coarsest first), resampling the full
* model state (bedrock, sediment, discharge, momentum) between levels. The
* numerically stable route to high-resolution erosion with this model.
* {512, 256, 128} on a 1024^2 input runs 256^2 (512 steps), 512^2 (256), then
* 1024^2 (128). See hydraulic_mcdonald for the model and parameters.
*
* **Example**
* @include ex_hydraulic_mcdonald.cpp
Expand Down
Loading
Loading