Skip to content

Commit

Permalink
Squashed 'externals/nitro/' changes from 732538e80..ff335eeaf
Browse files Browse the repository at this point in the history
ff335eeaf Merge commit 'eab6b6c35439c1eb7fa22fb042aae4a61a936d66' into cpp17
eab6b6c35 Squashed 'externals/coda-oss/' changes from 14f0b1545c..70a006d8a4
5648a0267 Merge branch 'main' into cpp17
b26e15318 latest from CODA-OSS (#583)
0db9bdb29 fix ASAN diagnostics (#582)

git-subtree-dir: externals/nitro
git-subtree-split: ff335eeaf8071f45a0e15cbba70ffdf7bcb8a15f
  • Loading branch information
Dan Smith committed Oct 2, 2023
1 parent 542c149 commit 34a50a6
Show file tree
Hide file tree
Showing 29 changed files with 308 additions and 69 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 @@ -134,14 +135,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);
)
4 changes: 2 additions & 2 deletions externals/coda-oss/modules/c++/cli/source/ArgumentParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#include <algorithm>
#include <iterator>
#include <std/span>

#include <import/str.h>
#include <import/mem.h>
Expand Down Expand Up @@ -533,8 +534,7 @@ std::unique_ptr<cli::Results> cli::ArgumentParser::parse(const std::string& prog
break;
}
}
if (maxArgs >= 0 &&
v->size() >= static_cast<size_t>(maxArgs))
if (maxArgs >= 0 && std::ssize(*v) >= maxArgs)
{
// it's another positional argument, so we break out
break;
Expand Down
37 changes: 28 additions & 9 deletions externals/coda-oss/modules/c++/cli/unittests/test_cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,16 @@
*
*/

#include <stdio.h>

#include <sstream>
#include <fstream>
#include <std/span>

#include <import/cli.h>
#include <import/mem.h>

#include "TestCase.h"
#include <sstream>
#include <fstream>
#include <stdio.h>

TEST_CASE(testValue)
{
Expand All @@ -50,15 +54,15 @@ TEST_CASE(testValue)
{
TEST_ASSERT_ALMOST_EQ(v.at<float>(i), 10.0f * i);
}
TEST_ASSERT_EQ(v.size(), static_cast<size_t>(10));
TEST_ASSERT_EQ(std::ssize(v), 10);

// strings
v.setContainer(strings);
for(int i = 0; i < 10; ++i)
{
TEST_ASSERT_EQ(v.at<std::string>(i), str::toString(i));
}
TEST_ASSERT_EQ(v.size(), static_cast<size_t>(10));
TEST_ASSERT_EQ(std::ssize(v), 10);
}

TEST_CASE(testChoices)
Expand Down Expand Up @@ -158,7 +162,7 @@ TEST_CASE(testIterate)
std::vector<std::string> keys;
for(cli::Results::const_iterator it = results->begin(); it != results->end(); ++it)
keys.push_back(it->first);
TEST_ASSERT_EQ(keys.size(), static_cast<size_t>(2));
TEST_ASSERT_EQ(std::ssize(keys), 2);
// std::map returns keys in alphabetical order...
TEST_ASSERT_EQ(keys[0], "config");
TEST_ASSERT_EQ(keys[1], "verbose");
Expand All @@ -168,16 +172,30 @@ TEST_CASE(testRequired)
{
cli::ArgumentParser parser;
parser.setProgram("tester");
parser.addArgument("-v --verbose", "Toggle verbose", cli::STORE_TRUE);
parser.addArgument("-c --config", "Specify a config file", cli::STORE)->setRequired(true);

const std::string program(testName);
TEST_EXCEPTION(parser.parse(program, str::split("")));
TEST_EXCEPTION(parser.parse(program, str::split("-c")));
const auto results = parser.parse(program, str::split("-c configFile"));
TEST_ASSERT_EQ(results->get<std::string>("config"), "configFile");
}

TEST_CASE(testRequiredThrows)
{
cli::ArgumentParser parser;
parser.setProgram("tester");
parser.addArgument("-c --config", "Specify a config file", cli::STORE)
->setRequired(true);

// The exceptions leak memory which causes an ASAN diagnostic on Linux.
#if CODA_OSS_POSIX_SOURCE && __SANITIZE_ADDRESS__
TEST_SUCCESS;
#else
const std::string program(testName);
TEST_EXCEPTION(parser.parse(program, str::split("")));
TEST_EXCEPTION(parser.parse(program, str::split("-c")));
#endif
}

TEST_CASE(testUnknownArgumentsOptions)
{
std::ostringstream outStream;
Expand Down Expand Up @@ -254,6 +272,7 @@ TEST_MAIN(
TEST_CHECK( testSubOptions);
TEST_CHECK( testIterate);
TEST_CHECK( testRequired);
TEST_CHECK( testRequiredThrows);
TEST_CHECK( testUnknownArgumentsOptions);
)

28 changes: 28 additions & 0 deletions externals/coda-oss/modules/c++/coda_oss/include/coda_oss/span.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
#ifndef CODA_OSS_coda_oss_span_h_INCLUDED_
#define CODA_OSS_coda_oss_span_h_INCLUDED_

#include <stdint.h>
#include <stdlib.h>
#include<stddef.h>

#include <cstddef>
#include <type_traits>

#include "coda_oss/CPlusPlus.h"
Expand Down Expand Up @@ -90,6 +95,29 @@ inline span<byte> as_writable_bytes(span<T> s) noexcept
return span<byte>(p, s.size_bytes());
}

// https://en.cppreference.com/w/cpp/iterator/size
template <typename C>
constexpr size_t size(const C& c)
{
return c.size();
}
template <typename C>
constexpr ptrdiff_t ssize(const C& c)
{
return gsl::narrow<ptrdiff_t>(c.size());
}

template <typename T, size_t N>
constexpr size_t size(const T (&)[N]) noexcept
{
return N;
}
template <typename T, ptrdiff_t N>
constexpr ptrdiff_t ssize(const T (&)[N]) noexcept
{
return N;
}

}

#endif // CODA_OSS_coda_oss_span_h_INCLUDED_
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ TEST_MAIN(
TEST_CHECK(test_highfive_info_nested);

TEST_CHECK(test_highfive_dump);
//TEST_CHECK(test_highfive_write);
TEST_CHECK(test_highfive_write);

TEST_CHECK(test_highfive_getDataType);
TEST_CHECK(test_highfive_getAttribute);
Expand Down
9 changes: 6 additions & 3 deletions externals/coda-oss/modules/c++/io/include/io/ByteStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,13 @@ struct CODA_OSS_API ByteStream : public SeekableInputStream, public SeekableOutp
return mData.empty() ? nullptr : &mData[0];
}

sys::Size_T
getSize()
auto size() const
{
return mData.size();
return mData.size();
}
auto getSize() const
{
return size();
}

protected:
Expand Down
12 changes: 7 additions & 5 deletions externals/coda-oss/modules/c++/io/source/ByteStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
*
*/

#include <std/span>

#include "io/ByteStream.h"

sys::Off_T io::ByteStream::seek(sys::Off_T offset, Whence whence)
Expand All @@ -33,13 +35,13 @@ sys::Off_T io::ByteStream::seek(sys::Off_T offset, Whence whence)
mPosition = offset;
break;
case END:
if (offset > static_cast<sys::Off_T>(mData.size()))
if (offset > std::ssize(mData))
{
mPosition = 0;
}
else
{
mPosition = static_cast<sys::Off_T>(mData.size() - offset);
mPosition = std::ssize(mData) - offset;
}
break;
case CURRENT:
Expand All @@ -48,7 +50,7 @@ sys::Off_T io::ByteStream::seek(sys::Off_T offset, Whence whence)
break;
}

if (mPosition > static_cast<sys::Off_T>(mData.size()))
if (mPosition > std::ssize(mData))
mPosition = -1;
return tell();
}
Expand All @@ -59,7 +61,7 @@ sys::Off_T io::ByteStream::available()
throw except::Exception(Ctxt("Invalid available bytes on eof"));

sys::Off_T where = mPosition;
sys::Off_T until = static_cast<sys::Off_T>(mData.size());
sys::Off_T until = std::ssize(mData);
sys::Off_T diff = until - where;
return (diff < 0) ? 0 : diff;
}
Expand All @@ -78,7 +80,7 @@ void io::ByteStream::write(const void* buffer, sys::Size_T size)
mData.resize(newPos);

const auto bufferPtr = static_cast<const sys::ubyte*>(buffer);
std::copy(bufferPtr, bufferPtr + size, &mData[static_cast<size_t>(mPosition)]);
std::copy(bufferPtr, bufferPtr + size, &mData[gsl::narrow<size_t>(mPosition)]);
mPosition = static_cast<sys::Off_T>(newPos);
}
}
Expand Down
Loading

0 comments on commit 34a50a6

Please sign in to comment.