Skip to content
Merged
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
1 change: 1 addition & 0 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ PointerAlignment: Left
UseTab: ForIndentation
IndentWidth: 4
TabWidth: 4
# ColumnLimit: 120
Cpp11BracedListStyle: true
AlwaysBreakTemplateDeclarations: Yes
AlwaysBreakAfterReturnType: All
Expand Down
9 changes: 7 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
cmake_minimum_required(VERSION 3.13)

project(Warthog
VERSION 0.2.1
VERSION 0.5.0
LANGUAGES CXX C)

set_property(GLOBAL PROPERTY WARTHOG_warthog-core ON)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)

option(WARTHOG_INT128 "Enable support for __int128 on gcc and clang" OFF)
option(WARTHOG_BMI "Enable support cpu BMI for WARTHOG_INTRIN_HAS(BMI)" OFF)
option(WARTHOG_BMI2 "Enable support cpu BMI2 for WARTHOG_INTRIN_HAS(BMI2), use for Zen 3+" OFF)
option(WARTHOG_INTRIN_ALL "Enable march=native and support x86 intrinsics if able (based on system), supersedes all manual instruction sets" OFF)

include(cmake/submodule.cmake)
include(cmake/warthog.cmake)

add_library(warthog_compile INTERFACE)
add_library(warthog::compile ALIAS warthog_compile)
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2024 Shortest Path Lab @ Monash University
Copyright (c) 2024-2025 Shortest Path Lab @ Monash University

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
105 changes: 92 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,104 @@ Requires `warthog-core` as a dependency.

# Using warthog

Warthog dependencies are setup using git-submodules, use commands below are used to initialise and update respectively:
git submodule init
git submodule update
It is recommended to use warthog not as a fork, but included in an external repo.
This setup support FetchContent, git submodule and git subtree.

All dependencies should be placed in `/extern`.
If not project forked, we suggest setting the project up as below:
## CMake

Setup a basic project using the following the commands:

git init
git remote add warthog-core https://github.com/ShortestPathLab/warthog-core.git
git fetch warthog-core
git checkout warthog-core/main cmake/warthog.cmake

Example `CMakeLists.txt`:

1. Copy `/cmake/submodule.cmake` to your repo
2. Submodule or subtree all your warthog dependencies and their dependencies into `/extern`
3. In `/CMakeLists.txt`, setup as below:
```
include(cmake/submodule.cmake)
warthog_submodule(warthog-[module]) # repeat for each [module]
cmake_minimum_required(VERSION 3.13)

project(App
VERSION 0.0.1
LANGUAGES CXX C)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)

# warthog modules
include(cmake/warthog.cmake)

warthog_module_declare(warthog-core v0.5.0) # is optional, remove for default of main
warthog_module(warthog-core)

add_executable(app main.cpp)
target_link_libraries(app PUBLIC warthog::core)
```

With (2) we flatten dependencies to top-level project.
With (3) `warthog_submodule` will add `add_subdirectoy` if your CMake is the top level config.
## Submodule

Commands for adding a module as a submodules for each repo are found below:

git submodule add https://github.com/ShortestPathLab/warthog-core.git extern/warthog-core
git submodule add https://github.com/ShortestPathLab/warthog-jps.git extern/warthog-jps

To update the version of warthog, for warthog module `$module`:

cd extern/$module
git fetch
git checkout|git switch
cd ..
git add $module

This will update the submodule to the checkout commit.
Initialise or update the submodule on other clones with
the following commands:

git submodule init # after clone
git submodule update # after pull

An informal project not designed to be a dependency does not require this, and can just `add_subdirectory` to all dependencies.
## Subtree

Subtree will make the module a part of your repo, allowing
for local editing without forking.

The setup for each module:

git subtree -P extern/warthog-core add https://github.com/ShortestPathLab/warthog-core.git main|branch|commit --squash
git subtree -P extern/warthog-jps add https://github.com/ShortestPathLab/warthog-jps.git main|branch|commit --squash

The update commands:

git subtree -P extern/warthog-core pull https://github.com/ShortestPathLab/warthog-core.git main|branch|commit --squash
git subtree -P extern/warthog-jps pull https://github.com/ShortestPathLab/warthog-jps.git main|branch|commit --squash

## Advance Module Details

File `/cmake/warthog.cmake` from warthog core should be copied to user repo and `include` in CMake.
Calling `warthog_submodule(warthog-core)` will then add `warthog-core` to your CMake in the following order:
1. `add_subdirectory(/extern/warthog-core)` if `/extern/warthog-core/CMakeLists.txt` exists (submodule/subtree)
2. `FetchContent_Declare` then `FetchContent_MakeAvailable(warthog-core)` otherwise
3. Error if cannot find `warthog-core` content

The `warthog_module` call only adds a module once, the following calls will be ignored.
The submodule/subtree version only works if called in the top level project by default;
if this method is preferred, then it should be added to the top level `/extern/`, can be overridden
with code `warthog_module(warthog-core ON)`.

Declare of warthog-core can be done using the following code:
```
warthog_module_declare(warthog-core [main|branch|tag|commit])
```
or:
```
FetchContent_Declare(warthog-core
GIT_REPOSITORY https://github.com/ShortestPathLab/warthog-core.git
GIT_TAG [main|branch|tag|commit])
```
This will declare what warthog-core version to fetched.
The `warthog_module_declare` version makes it simple, although it only supports known warthog libraries.
The optional second parameter sets the version to pull, by default is `main` branch.
This system only support warthog 0.5 or greater.

# Resources

Expand Down
3 changes: 3 additions & 0 deletions cmake/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,8 @@
#define WARTHOG_VERSION_REVISON @CMAKE_PROJECT_VERSION_PATCH@

#cmakedefine WARTHOG_INT128
#cmakedefine WARTHOG_INTRIN_ALL
#cmakedefine WARTHOG_BMI
#cmakedefine WARTHOG_BMI2

#endif // WARTHOG_APP_CONFIG_H
3 changes: 3 additions & 0 deletions cmake/headers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/include/warthog/config.h
# use `find include/warthog/*/ -type f -name '*.h' | sort`
target_sources(warthog_core PUBLIC
include/warthog/constants.h
include/warthog/defines.h
include/warthog/forward.h
include/warthog/limits.h

Expand Down Expand Up @@ -54,10 +55,12 @@ include/warthog/util/experiment.h
include/warthog/util/file_utils.h
include/warthog/util/gm_parser.h
include/warthog/util/helpers.h
include/warthog/util/intrin.h
include/warthog/util/log.h
include/warthog/util/macros.h
include/warthog/util/pqueue.h
include/warthog/util/scenario_manager.h
include/warthog/util/template.h
include/warthog/util/timer.h
include/warthog/util/vec_io.h
)
35 changes: 0 additions & 35 deletions cmake/submodule.cmake

This file was deleted.

76 changes: 76 additions & 0 deletions cmake/warthog.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
cmake_minimum_required(VERSION 3.13)

# include this file to check submodule include

# set here as only
set(warthog_https_warthog-core "https://github.com/ShortestPathLab/warthog-core.git" CACHE INTERNAL "")
set(warthog_https_warthog-jps "https://github.com/ShortestPathLab/warthog-jps.git" CACHE INTERNAL "")

if(COMMAND warthog_module)
return() # do not redefine
endif()

include(FetchContent)

set(WARTHOG_MODULE_ROOT_ONLY ON CACHE BOOL "add submodule if present only allowed for root project")

function(warthog_top_level)
set(_is_top OFF)
if(${CMAKE_VERSION} VERSION_GREATER_EQUAL 3.21)
if(${PROJECT_IS_TOP_LEVEL})
set(_is_top ON)
endif()
else()
if(${CMAKE_SOURCE_DIR} STREQUAL ${PROJECT_SOURCE_DIR})
set(_is_top ON)
endif()
endif()
set(_warthog_is_top ${_is_top} PARENT_SCOPE)
endfunction()

# warthog_module module [override_top]
# adds a module to warthog
# has checks to insure module is only added once
# if called from the top level project (or optional variable override_top is true)
# then if extern/${module}/CMakeLists.txt exists, adds that version instead
# intended for use with git module/subtree.
# otherwise, fetchcontent ${module} is made available
# user must add FetchContent_Declare
function(warthog_module module)
get_property(_module_added GLOBAL PROPERTY WARTHOG_${module} SET)
if(${_module_added}) # module already added
return()
endif()
if((${ARGC} GREATER 1) AND (${ARGV1}))
set(is_top_level ON)
else()
warthog_top_level()
set(is_top_level ${_warthog_is_top})
endif()
if(${is_top_level})
if(EXISTS "${PROJECT_SOURCE_DIR}/extern/${module}/CMakeLists.txt")
# module or subtree, include and exit
add_subdirectory("${PROJECT_SOURCE_DIR}/extern/${module}")
set_property(GLOBAL PROPERTY WARTHOG_${module} ON)
return()
endif()
endif()
# failed to add module, fetch if able
warthog_module_declare(${module})
FetchContent_MakeAvailable(${module})
set_property(GLOBAL PROPERTY WARTHOG_${module} ON)
endfunction()

function(warthog_module_declare module)
if(NOT DEFINED warthog_https_${module})
return()
endif()
if((${ARGC} GREATER 1))
set(git_tag ${ARGV1})
else()
set(git_tag "main")
endif()
FetchContent_Declare(${module}
GIT_REPOSITORY ${warthog_https_${module}}
GIT_TAG ${git_tag})
endfunction()
29 changes: 19 additions & 10 deletions include/warthog/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@ struct identity_base
return id == other.id;
}

template<typename Tag2, typename IdType2>
requires(!std::same_as<identity_base, identity_base<Tag2, IdType2>>)
constexpr explicit
operator identity_base<Tag2, IdType2>() const noexcept
{
auto alt = identity_base<Tag2, IdType2>(static_cast<IdType2>(id));
assert(id == alt.id || (is_none() && alt.is_none()));
return alt;
}
constexpr explicit
operator uint64_t() const noexcept
{
Expand Down Expand Up @@ -94,8 +103,8 @@ struct identity_base
};
template<class T>
constexpr bool is_identity_v = std::false_type{};
template<template<class, class> class T, class Tag, class IdType>
constexpr bool is_identity_v<T<Tag, IdType>> = std::true_type{};
template<class Tag, class IdType>
constexpr bool is_identity_v<identity_base<Tag, IdType>> = std::true_type{};
template<class T>
concept Identity = is_identity_v<T>;

Expand All @@ -121,14 +130,14 @@ constexpr uint32_t LOG2_DBWORD_BITS = std::popcount(DBWORD_BITS_MASK);
// search and sort constants
constexpr double DBL_ONE = 1.0;
constexpr double DBL_TWO = 2.0;
constexpr double DBL_ROOT_TWO
= 1.414213562373095048801688724209698078569671875;
constexpr double DBL_ONE_OVER_TWO = 0.5;
constexpr double DBL_ONE_OVER_ROOT_TWO
= 0.70710678118654752440084436210484903928483593768847403658833986;
constexpr double DBL_ROOT_TWO_OVER_FOUR
= 0.35355339059327376220042218105242451964241796884423701829416993;
constexpr int32_t ONE = 100000;
// Truncate to allow for equality testing.
// Has around ~7 decimal places allowing up to 500k integer value before
// overflowing (6 hex digits = 24bits).
constexpr double DBL_ROOT_TWO = 0x1.6a09e6p0;
constexpr double DBL_ONE_OVER_TWO = 0.5;
constexpr double DBL_ONE_OVER_ROOT_TWO = 0x0.b504f3p0;
constexpr double DBL_ROOT_TWO_OVER_FOUR = DBL_ONE_OVER_TWO / 4;
constexpr int32_t ONE = 100000;

constexpr uint32_t INF32
= std::numeric_limits<uint32_t>::max(); // indicates uninitialised or
Expand Down
Loading