Skip to content

Commit

Permalink
update cmake option, throw if invalid access, rm string_parser
Browse files Browse the repository at this point in the history
Co-authored-by: Marcel Koch <marcel.koch@kit.edu>
Co-authored-by: Tobias Ribizel <ribizel@kit.edu>
  • Loading branch information
3 people committed Mar 25, 2024
1 parent 567d5e6 commit eb934d6
Show file tree
Hide file tree
Showing 12 changed files with 128 additions and 331 deletions.
4 changes: 2 additions & 2 deletions .gitlab/scripts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
-DGINKGO_BUILD_HWLOC=${BUILD_HWLOC}
-DGINKGO_BUILD_PAPI_SDE=${BUILD_PAPI_SDE}
-DGINKGO_BUILD_TESTS=ON -DGINKGO_BUILD_EXAMPLES=ON
-DGINKGO_BUILD_EXTENSION=${BUILD_EXTENSION}
-DGINKGO_BUILD_CONFIG_PARSER=${BUILD_CONFIG_PARSER}
-DGINKGO_FAST_TESTS=${FAST_TESTS}
-DGINKGO_TEST_NONDEFAULT_STREAM=${NONDEFAULT_STREAM}
-DGINKGO_MIXED_PRECISION=${MIXED_PRECISION}
Expand Down Expand Up @@ -91,7 +91,7 @@
-DGINKGO_BUILD_HWLOC=${BUILD_HWLOC}
-DGINKGO_BUILD_PAPI_SDE=${BUILD_PAPI_SDE}
-DGINKGO_BUILD_TESTS=ON -DGINKGO_BUILD_EXAMPLES=ON
-DGINKGO_BUILD_EXTENSION=${BUILD_EXTENSION}
-DGINKGO_BUILD_CONFIG_PARSER=${BUILD_CONFIG_PARSER}
-DGINKGO_FAST_TESTS=${FAST_TESTS}
-DGINKGO_MIXED_PRECISION=${MIXED_PRECISION}
-DGINKGO_CONFIG_LOG_DETAILED=${CONFIG_LOG}
Expand Down
2 changes: 1 addition & 1 deletion .gitlab/variables.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
BUILD_HWLOC: "ON"
BUILD_PAPI_SDE: "OFF"
BUILD_MPI: "OFF"
BUILD_EXTENSION: "OFF"
BUILD_CONFIG_PARSER: "OFF"
MPI_AS_ROOT: "OFF"
FAST_TESTS: "OFF"
NONDEFAULT_STREAM: "OFF"
Expand Down
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ option(GINKGO_BUILD_SYCL
option(GINKGO_BUILD_CUDA "Compile kernels for NVIDIA GPUs" ${GINKGO_HAS_CUDA})
option(GINKGO_BUILD_HIP "Compile kernels for AMD or NVIDIA GPUs" ${GINKGO_HAS_HIP})
option(GINKGO_BUILD_DOC "Generate documentation" OFF)
option(GINKGO_BUILD_EXTENSION "Build Ginkgo's extension" OFF)
option(GINKGO_BUILD_CONFIG_PARSER "Build Ginkgo's config parser" OFF)
option(GINKGO_FAST_TESTS "Reduces the input size for a few tests known to be time-intensive" OFF)
option(GINKGO_TEST_NONDEFAULT_STREAM "Uses non-default streams in CUDA and HIP tests" OFF)
option(GINKGO_MIXED_PRECISION "Instantiate true mixed-precision kernels (otherwise they will be conversion-based using implicit temporary storage)" OFF)
Expand Down Expand Up @@ -331,7 +331,7 @@ if(GINKGO_BUILD_BENCHMARKS)
add_subdirectory(benchmark)
endif()

if(GINKGO_BUILD_EXTENSION)
if(GINKGO_BUILD_CONFIG_PARSER)
add_subdirectory(extension)
endif()

Expand Down
31 changes: 30 additions & 1 deletion core/config/property_tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,41 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#include <ginkgo/core/config/property_tree.hpp>

#include <ginkgo/core/base/exception_helpers.hpp>


namespace gko {
namespace config {


const pnode pnode::empty_pn = pnode{};
void pnode::throw_if_not_contain(status_t status, bool allow_empty) const
{
static auto str_status = [](status_t status) -> std::string {
if (status == status_t::empty) {
return "empty";
} else if (status == status_t::array) {
return "array";
} else if (status == status_t::map) {
return "map";
} else if (status == status_t::data) {
return "data";
} else {
return "unknown";
}
};
bool is_valid =
(status_ == status || (allow_empty && status_ == status_t::empty));
std::string msg = "Contains " + str_status(status_) + ", but try to get " +
str_status(status);
GKO_THROW_IF_INVALID(is_valid, msg);
}


const pnode& pnode::empty_node()
{
static pnode empty_pn{};
return empty_pn;
}


} // namespace config
Expand Down
42 changes: 41 additions & 1 deletion core/test/config/property_tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


#include <gtest/gtest.h>
#include <ginkgo/core/base/exception.hpp>


#include "core/test/config/utils.hpp"
Expand Down Expand Up @@ -170,7 +171,7 @@ TEST(PropertyTree, CreateArrayByGettingArray)
}


TEST(PropertyTree, print)
TEST(PropertyTree, Print)
{
pnode root;
root = pnode{{{"p0", pnode{1.23}}, {"p1", pnode{1ll}}}};
Expand All @@ -192,3 +193,42 @@ TEST(PropertyTree, print)

ASSERT_EQ(oss.str(), iss.str());
}


TEST(PropertyTree, UpdateEmpty)
{
pnode empty_for_array;
pnode empty_for_map;

ASSERT_NO_THROW(empty_for_array.get_array());
ASSERT_TRUE(empty_for_array.is(pnode::status_t::array));
ASSERT_NO_THROW(empty_for_map.get_map());
ASSERT_TRUE(empty_for_map.is(pnode::status_t::map));
}


TEST(PropertyTree, ThrowIfInvalidAccess)
{
pnode root;
root.get_map()["p0"] = pnode{1.23};
root.get_map()["p2"] = pnode{{pnode{1}, pnode{2}, pnode{}}};

// root is map
ASSERT_THROW(root.get_array(), gko::InvalidStateError);
ASSERT_THROW(root.get_data(), gko::InvalidStateError);
ASSERT_THROW(root.at(0), gko::InvalidStateError);
ASSERT_NO_THROW(root.get_map());
ASSERT_NO_THROW(root.at("p0"));
// p0 is data
ASSERT_THROW(root.at("p0").get_map(), gko::InvalidStateError);
ASSERT_THROW(root.at("p0").get_array(), gko::InvalidStateError);
ASSERT_THROW(root.at("p0").at(0), gko::InvalidStateError);
ASSERT_THROW(root.at("p0").at("p0"), gko::InvalidStateError);
ASSERT_NO_THROW(root.at("p0").get_data());
// p2 is vector
ASSERT_THROW(root.at("p2").get_data(), gko::InvalidStateError);
ASSERT_THROW(root.at("p2").get_map(), gko::InvalidStateError);
ASSERT_THROW(root.at("p2").at("p0"), gko::InvalidStateError);
ASSERT_NO_THROW(root.at("p2").get_array());
ASSERT_NO_THROW(root.at("p2").at(0));
}
5 changes: 4 additions & 1 deletion extension/property_tree/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@ if(GINKGO_BUILD_TESTS)
endif()

## Install step
# ginkgo_install_header_only_library(property_tree Ginkgo)
install(DIRECTORY "include/property_tree"
DESTINATION "${CMAKE_INSTALL_FULL_INCLUDEDIR}/ginkgo/extensions"
FILES_MATCHING PATTERN "*.hpp"
)
11 changes: 0 additions & 11 deletions extension/property_tree/include/property_tree/json_parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,6 @@ void json_parser(gko::config::pnode& ptree, rapidjson::Value& dom)
}


std::string convert_quote(const std::string& str)
{
auto output = str;
for (std::string::size_type pos{};
std::string::npos != (pos = output.find("'", pos)); pos += 1) {
output.replace(pos, 1, "\"", 1);
}
return output;
}


} // namespace extension
} // namespace gko

Expand Down
147 changes: 0 additions & 147 deletions extension/property_tree/include/property_tree/string_parser.hpp

This file was deleted.

3 changes: 1 addition & 2 deletions extension/property_tree/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,4 @@ function(gkoext_pt_create_test test_name)
endfunction(gkoext_pt_create_test)


gkoext_pt_create_test(json_parser rapidjson)
gkoext_pt_create_test(string_parser)
gkoext_pt_create_test(json_parser rapidjson ginkgo)
Loading

0 comments on commit eb934d6

Please sign in to comment.