Skip to content

Commit

Permalink
Squashed 'externals/nitro/' changes from e418beceb..edfa0f7ce
Browse files Browse the repository at this point in the history
edfa0f7ce latest from CODA-OSS (#585)
b26e15318 latest from CODA-OSS (#583)
0db9bdb29 fix ASAN diagnostics (#582)

git-subtree-dir: externals/nitro
git-subtree-split: edfa0f7ce5951b09967bb92ec4aba4820d50561f
  • Loading branch information
Dan Smith committed Oct 9, 2023
1 parent 8041684 commit 41ea3de
Show file tree
Hide file tree
Showing 60 changed files with 519 additions and 270 deletions.
10 changes: 6 additions & 4 deletions externals/coda-oss/.github/workflows/build_unittest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ jobs:
os: [windows-latest]
platform: [x64]
configuration: [Debug] # Debug turns on more compiler warnings
name: ${{ matrix.os }}-msbuild
avx: [AVX2, AVX512F]
name: ${{ matrix.os }}-${{ matrix.avx }}-msbuild
runs-on: ${{ matrix.os }}

steps:
Expand All @@ -68,7 +69,7 @@ jobs:
ls env:
mkdir out
cd out
cmake .. -DCMAKE_INSTALL_PREFIX=install\${{ matrix.platform }}-${{ matrix.configuration }} -DENABLE_PYTHON=OFF
cmake .. -DCMAKE_INSTALL_PREFIX=install\${{ matrix.platform }}-${{ matrix.configuration }} -DENABLE_PYTHON=OFF -DENABLE_${{ matrix.avx }}=ON
- name: build
run: |
cd out
Expand Down Expand Up @@ -131,14 +132,15 @@ jobs:
matrix:
os: [ubuntu-latest]
configuration: [Debug, Release]
name: ${{ matrix.os }}-${{ matrix.configuration }}-CMake
avx: [AVX2, AVX512F]
name: ${{ matrix.os }}-${{ matrix.configuration }}-${{ matrix.avx }}-CMake
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- name: configure
run: |
mkdir out && cd out
cmake .. -DENABLE_PYTHON=OFF
cmake .. -DENABLE_PYTHON=OFF -DENABLE_ASAN=ON -DENABLE_${{ matrix.avx }}=ON
- name: build
run: |
cd out
Expand Down
11 changes: 0 additions & 11 deletions externals/coda-oss/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,8 @@ if (${CMAKE_PROJECT_NAME} STREQUAL coda-oss)
if (MSVC)
add_compile_options(/WX) # warnings as errors
add_compile_options(/MP) # multi-processor compile

if (ENABLE_ASAN)
# https://docs.microsoft.com/en-us/cpp/sanitizers/asan?view=msvc-160
add_compile_options(/fsanitize=address)
endif()
elseif (UNIX)
add_compile_options(-Werror) # warnings as errors

if (ENABLE_ASAN)
# https://gcc.gnu.org/onlinedocs/gcc/Instrumentation-Options.html
add_compile_options(-fsanitize=address)
add_link_options(-fsanitize=address)
endif()
endif()

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
Expand Down
37 changes: 37 additions & 0 deletions externals/coda-oss/cmake/CodaBuild.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,22 @@ macro(coda_initialize_build)
# This should probably be replaced by GenerateExportHeader
#set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
set(CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD TRUE)

if (ENABLE_ASAN)
# https://docs.microsoft.com/en-us/cpp/sanitizers/asan?view=msvc-160
add_compile_options(/fsanitize=address)
endif()

# Note SSE2 is implicitly enabled for x64 builds.
if (ENABLE_AVX2 AND (NOT ENABLE_AVX512F))
# https://learn.microsoft.com/en-us/cpp/build/reference/arch-x86?view=msvc-170
add_compile_options(/arch:AVX2)
endif()
if (ENABLE_AVX512F)
# https://learn.microsoft.com/en-us/cpp/build/reference/arch-x86?view=msvc-170
add_compile_options(/arch:AVX512)
endif()

endif()

# Unix/Linux specific options
Expand All @@ -173,6 +189,27 @@ macro(coda_initialize_build)
-D_LARGEFILE_SOURCE
-D_FILE_OFFSET_BITS=64
)

if (ENABLE_ASAN)
# https://gcc.gnu.org/onlinedocs/gcc/Instrumentation-Options.html
add_compile_options(-fsanitize=address)
add_link_options(-fsanitize=address)
endif()

# Note SSE2 is implicitly enabled for x64 builds.
if (ENABLE_AVX2 AND (NOT ENABLE_AVX512F))
# https://gcc.gnu.org/onlinedocs/gcc/x86-Options.html
# It doesn't look like GCC has a specific option for AVX2;
# other projects use "haswell"
add_compile_options(-march=haswell)
endif()
if (ENABLE_AVX512F)
# https://gcc.gnu.org/onlinedocs/gcc/x86-Options.html
# It doesn't look like GCC has a specific option for AVX512F;
# other projects use "native" which isn't quite correct.'
add_compile_options(-march=native)
endif()

endif()

# all targets should be installed using this export set
Expand Down
44 changes: 44 additions & 0 deletions externals/coda-oss/modules/c++/avx/unittests/test_m256.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
#include <std/cstddef>

#include <sys/Conf.h>
#include <sys/AbstractOS.h>
#include <avx/extractf.h>
#include <config/compiler_extensions.h>

TEST_CASE(extractf)
{
Expand All @@ -49,8 +51,50 @@ TEST_CASE(extractf)
*/
TEST_SUCCESS;
}

TEST_CASE(test_getSIMDInstructionSet)
{
// This is the reverse of getSIMDInstructionSet(): it uses the macros to generate a value.
constexpr auto simdInstructionSet = sys::getSIMDInstructionSet();
#if __AVX512F__
static_assert(simdInstructionSet == sys::SIMDInstructionSet::AVX512F, "getSIMDInstructionSet()");
#elif __AVX2__
static_assert(simdInstructionSet == sys::SIMDInstructionSet::AVX2, "getSIMDInstructionSet()");
#else
static_assert(simdInstructionSet == sys::SIMDInstructionSet::SSE2, "getSIMDInstructionSet()");
#endif

CODA_OSS_disable_warning_push
#if _MSC_VER
#pragma warning(disable: 4127) // conditional expression is constant
#endif

switch (sys::getSIMDInstructionSet()) // run-time value
{
case sys::SIMDInstructionSet::SSE2:
{
TEST_ASSERT(simdInstructionSet == sys::SIMDInstructionSet::SSE2);
break;
}
case sys::SIMDInstructionSet::AVX2:
{
TEST_ASSERT(simdInstructionSet == sys::SIMDInstructionSet::AVX2);
break;
}
case sys::SIMDInstructionSet::AVX512F:
{
TEST_ASSERT(simdInstructionSet == sys::SIMDInstructionSet::AVX512F);
break;
}
default:
{
TEST_FAIL;
}
}
CODA_OSS_disable_warning_pop
}

TEST_MAIN(
TEST_CHECK(extractf);
TEST_CHECK(test_getSIMDInstructionSet);
)
70 changes: 43 additions & 27 deletions externals/coda-oss/modules/c++/cli/include/cli/Results.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
#define CODA_OSS_cli_Results_h_INCLUDED_

#include <map>
#include <memory>
#include <utility>
#include <stdexcept>

#include "sys/Conf.h"

Expand All @@ -33,24 +36,25 @@
namespace cli
{

class Results
class Results final
{
protected:
typedef std::map<std::string, cli::Value*> ValueStorage_T;
typedef std::map<std::string, std::unique_ptr<cli::Value>> ValueStorage_T;
typedef ValueStorage_T::iterator ValueIter_T;
typedef ValueStorage_T::const_iterator ConstValueIter_T;
typedef std::map<std::string, cli::Results*> ResultsStorage_T;
typedef ResultsStorage_T::iterator ResultsIter_T;
typedef ResultsStorage_T::const_iterator ConstResultsIter_T;

public:
Results()
{
}
Results() = default;
~Results()
{
destroy();
}
Results(const Results&) = delete;
Results& operator=(const Results&) = delete;
Results(Results&&) = default;
Results& operator=(Results&&) = default;

bool hasValue(const std::string& key) const
{
Expand All @@ -62,20 +66,30 @@ class Results
return mResults.find(key) != mResults.end();
}

cli::Value* operator[](const std::string& key) const
const cli::Value* operator[](const std::string& key) const
{
return getValue(key);
}

cli::Value* getValue(const std::string& key) const
const cli::Value* getValue(const std::string& key) const
{
ConstValueIter_T p = mValues.find(key);
auto const p = mValues.find(key);
if (p == mValues.end())
{
const std::string errorMessage = "No argument named " + key;
throw except::NoSuchKeyException(Ctxt(errorMessage));
}
return p->second;
return p->second.get();
}
cli::Value* getValue(const std::string& key)
{
auto const p = mValues.find(key);
if (p == mValues.end())
{
const std::string errorMessage = "No argument named " + key;
throw except::NoSuchKeyException(Ctxt(errorMessage));
}
return p->second.get();
}

template<typename T>
Expand All @@ -100,15 +114,22 @@ class Results
return p->second;
}

void put(const std::string& key, cli::Value *value)
void put(const std::string& key, std::unique_ptr<cli::Value> value)
{
if (hasValue(key) && (getValue(key) == value.get()))
{
return;
}
mValues[key] = std::move(value);
}
void put(const std::string& key, cli::Value* value)
{
if (hasValue(key))
cli::Value* pExistingValue = hasValue(key) ? getValue(key) : nullptr;
if ((pExistingValue == nullptr) || (pExistingValue != value))
{
cli::Value* existing = getValue(key);
if (existing != value)
delete getValue(key);
// Either 1) we didn't already have a value or 2) the existing value is different
put(key, std::unique_ptr<cli::Value>(value));
}
mValues[key] = value;
}

void put(const std::string& key, cli::Results *args)
Expand All @@ -122,26 +143,21 @@ class Results
mResults[key] = args;
}

typedef ValueStorage_T::iterator iterator;
typedef ValueStorage_T::const_iterator const_iterator;
auto begin() { return mValues.begin(); }
auto begin() const { return mValues.begin(); }
auto end() { return mValues.end(); }
auto end() const { return mValues.end(); }

iterator begin() { return mValues.begin(); }
const_iterator begin() const { return mValues.begin(); }
iterator end() { return mValues.end(); }
const_iterator end() const { return mValues.end(); }

protected:
private:
ValueStorage_T mValues;
ResultsStorage_T mResults;

void destroy()
{
for (ValueIter_T it = mValues.begin(), end = mValues.end(); it != end; ++it)
delete it->second;
mValues.clear();
for (ResultsIter_T it = mResults.begin(), end = mResults.end(); it
!= end; ++it)
delete it->second;
mValues.clear();
mResults.clear();
}
};
Expand Down
27 changes: 4 additions & 23 deletions externals/coda-oss/modules/c++/cli/include/cli/Value.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

#include <string>
#include <iterator>
#include <memory>

#include <import/str.h>
#include "sys/Conf.h"
Expand All @@ -38,12 +39,9 @@ namespace cli
* The Value class provides access to one or more actual values.
* It provides index-based access to parameters.
*/
class CODA_OSS_API Value
struct CODA_OSS_API Value final
{
public:
Value()
{
}
Value() = default;

template<typename T>
explicit Value(std::vector<T> value)
Expand All @@ -57,12 +55,6 @@ class CODA_OSS_API Value
set<T>(value);
}

template<typename T>
Value(T* value, size_t size, bool own = false)
{
set<T>(value, size, own);
}

~Value()
{
cleanup();
Expand All @@ -75,17 +67,6 @@ class CODA_OSS_API Value
mValues.push_back(str::toString(value));
}

template<typename T>
void set(T* value, size_t size, bool own = false)
{
cleanup();
mValues.reserve(size);
for (size_t i = 0; i < size; ++i)
add(value[i]);
if (own)
delete[] value;
}

template<typename T>
void setContainer(const std::vector<T>& c)
{
Expand All @@ -106,7 +87,7 @@ class CODA_OSS_API Value
{
if (index >= mValues.size())
throw except::IndexOutOfRangeException(
Ctxt(FmtX("Invalid index: %d", index)));
Ctxt(str::Format("Invalid index: %d", index)));
return str::toType<T>(mValues[index]);
}

Expand Down
2 changes: 1 addition & 1 deletion externals/coda-oss/modules/c++/cli/source/Argument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ cli::Argument::~Argument()
cli::Argument* cli::Argument::addFlag(const std::string& flag)
{
char p = mParser->mPrefixChar;
std::string p2 = FmtX("%c%c", p, p);
std::string p2 = str::Format("%c%c", p, p);
if (flag.size() > 2 && str::startsWith(flag, p2) && flag[2] != p)
mLongFlags.push_back(validateFlag(flag.substr(2)));
else if (flag.size() > 1 && flag[0] == p && flag[1] != p)
Expand Down
Loading

0 comments on commit 41ea3de

Please sign in to comment.