Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Yaml Crash Problem WIP #282

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from 11 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
2 changes: 2 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
Language: Cpp
BasedOnStyle: LLVM
DisableFormat: false
IndentWidth: 2
ColumnLimit: 120
...
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# along with this program. If not, see http://www.gnu.org/licenses.
# -----------------------------------------------------------------------------

cmake_minimum_required(VERSION 3.7)
cmake_minimum_required(VERSION 3.9)
project(htm_core CXX)

set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}")
Expand All @@ -29,6 +29,7 @@ set($ENV{HTM_CPP} ${REPOSITORY_DIR})
#
option(FORCE_CPP11 "Force compiler to use C++11 standard." OFF)
option(FORCE_BOOST "Force compiler to install and use Boost." OFF)
set(YAML_PARSER "yamlcpp" CACHE STRING "Specify the YAML parser to use 'yamlcpp', 'RapidYaml', 'libyaml', default 'yamlcpp'." )
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i know this is a WIP, eventually we'll want to have just 1 parser.

set(BINDING_BUILD "none" CACHE STRING "Specify the Binding to build 'Python2','Python3' or 'none', default 'none'." )
# Note: by setting the CXX environment variable, a non-default c++ compiler can be specified.

Expand Down Expand Up @@ -77,6 +78,8 @@ message(STATUS "INTERNAL_LINKER_FLAGS_STR= ${INTERNAL_LINKER_FLAGS_STR}")
message(STATUS "COMMON_COMPILER_DEFINITIONS_STR=${COMMON_COMPILER_DEFINITIONS_STR}")
message(STATUS "COMMON_OS_LIBS = ${COMMON_OS_LIBS}")

add_definitions(-DYAML_PARSER_${YAML_PARSER})

# Set up builds of external dependencies and get their exports.
# (see individual external/*.cmake modules for exported settings and functions)
include(external/bootstrap.cmake)
Expand Down
20 changes: 14 additions & 6 deletions external/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
# - cmake ../..
# Note: on MSVC, run startupMSVC.bat after deleting the build folder.

cmake_minimum_required(VERSION 3.7)
cmake_minimum_required(VERSION 3.9)
project(htm_core CXX)

set(CMAKE_VERBOSE_MAKEFILE OFF)
Expand Down Expand Up @@ -78,12 +78,20 @@ FILE(REMOVE "${EXPORT_FILE_NAME}")
# common
include(common.cmake)


################
# Yaml-cpp
include(YamlCppLib.cmake)


# Yaml Parser
if (${YAML_PARSER} STREQUAL "yamlcpp")
# Yaml-cpp
include(YamlCppLib.cmake)

elseif(${YAML_PARSER} STREQUAL "RapidYaml")
# Rapid YAML
include(RapidYaml.cmake)

elseif(${YAML_PARSER} STREQUAL "libyaml")
# libyaml
include(libyaml.cmake)
endif()
################
# Eigen
include(eigen.cmake)
Expand Down
107 changes: 107 additions & 0 deletions external/RapidYaml.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# -----------------------------------------------------------------------------
# HTM Community Edition of NuPIC
# Copyright (C) 2019, Numenta, Inc.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero Public License version 3 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU Affero Public License for more details.
#
# You should have received a copy of the GNU Affero Public License
# along with this program. If not, see http://www.gnu.org/licenses.
# -----------------------------------------------------------------------------

# Rapid YAML must be downloaded in four parts.
# - ryml from repository at https://github.com/biojppm/rapidyaml - the main library
# - c4core from repository at https://github.com/biojppm/c4core/ - the C library of utilities
# - cmake from repository at https://github.com/biojppm/cmake/ - Cmake scripts
# - debugbreak from repository at https://github.com/biojppm/debugbreak/ - debug break function
# There are links from rapidyaml to a specific branch of c4core in the extern folder of rapidyaml
# but the downloader does not follow it. So we need to do three downloads.

message(STATUS "${REPOSITORY_DIR}/build/ThirdParty/share/ryml.zip")
if( (EXISTS "${REPOSITORY_DIR}/build/ThirdParty/share/ryml.zip")
AND (EXISTS "${REPOSITORY_DIR}/build/ThirdParty/share/ryml_c4core.zip")
AND (EXISTS "${REPOSITORY_DIR}/build/ThirdParty/share/ryml_cmake.zip")
AND (EXISTS "${REPOSITORY_DIR}/build/ThirdParty/share/ryml_debugbreak.zip"))
set(URL1 "${REPOSITORY_DIR}/build/ThirdParty/share/ryml.zip")
set(URL2 "${REPOSITORY_DIR}/build/ThirdParty/share/ryml_c4core.zip")
set(URL3 "${REPOSITORY_DIR}/build/ThirdParty/share/ryml_cmake.zip")
set(URL4 "${REPOSITORY_DIR}/build/ThirdParty/share/ryml_debugbreak.zip")
else()
#There are no releases. Use the masters.
set(URL1 https://github.com/biojppm/rapidyaml/archive/master.zip)
set(URL2 https://github.com/biojppm/c4core/archive/master.zip)
set(URL3 https://github.com/biojppm/cmake/archive/master.zip)
set(URL4 https://github.com/biojppm/debugbreak/archive/master.zip)
endif()

message(STATUS "Obtaining RapidYAML from ${URL1}" )
include(DownloadProject/DownloadProject.cmake)
download_project(PROJ ryml
PREFIX "${EP_BASE}/ryml"
URL ${URL1}
UPDATE_DISCONNECTED 1
QUIET
)
download_project(PROJ ryml_c4core
PREFIX "${EP_BASE}/ryml_c4core"
SOURCE_DIR "${ryml_SOURCE_DIR}/extern/c4core"
URL ${URL2}
UPDATE_DISCONNECTED 1
QUIET
)
download_project(PROJ ryml_cmake
PREFIX "${EP_BASE}/ryml_cmake"
SOURCE_DIR "${ryml_SOURCE_DIR}/extern/c4core/cmake"
URL ${URL3}
UPDATE_DISCONNECTED 1
QUIET
)
download_project(PROJ ryml_debugbreak
PREFIX "${EP_BASE}/ryml_debugbreak"
SOURCE_DIR "${ryml_SOURCE_DIR}/extern/c4core/extern/debugbreak"
URL ${URL4}
UPDATE_DISCONNECTED 1
QUIET
)

#Need to enable Exceptions
set(c4path "${ryml_SOURCE_DIR}/extern/c4core/src/c4")
file(RENAME "${c4path}/config.hpp" "${c4path}/config1.hpp")
file(READ "${c4path}/config1.hpp" content1)
string(REPLACE "//#define C4_ERROR_THROWS_EXCEPTION"
"#define C4_ERROR_EXCEPTIONS_ENABLED\n#define C4_ERROR_THROWS_EXCEPTION"
content
"${content1}")
file(WRITE "${c4path}/config.hpp" "${content}")

file(RENAME "${c4path}/error.cpp" "${c4path}/error1.cpp")
file(READ "${c4path}/error1.cpp" content2)
string(REPLACE "if(s_error_flags & (ON_ERROR_LOG|ON_ERROR_CALLBACK))"
"if(s_error_flags & (ON_ERROR_LOG|ON_ERROR_CALLBACK|ON_ERROR_THROW))"
content1
"${content2}")
string(REPLACE "throw Exception(ss.c_str())"
"throw Exception(buf)"
content
"${content1}")
file(WRITE "${c4path}/error.cpp" "${content}")

set(C4_EXCEPTIONS_ENABLED ON)
set(C4_ERROR_THROWS_EXCEPTION ON)
add_subdirectory(${ryml_SOURCE_DIR} ${ryml_BINARY_DIR})

set(yaml_INCLUDE_DIRS "${ryml_SOURCE_DIR}/src@@@${ryml_SOURCE_DIR}/extern/c4core/src@@@${ryml_SOURCE_DIR}/extern/c4core/extern")
if (MSVC)
set(yaml_LIBRARIES "${ryml_BINARY_DIR}$<$<CONFIG:Release>:/Release/ryml.lib>$<$<CONFIG:Debug>:/Debug/ryml.lib>")
else()
set(yaml_LIBRARIES ${ryml_BINARY_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}ryml${CMAKE_STATIC_LIBRARY_SUFFIX})
endif()
FILE(APPEND "${EXPORT_FILE_NAME}" "yaml_INCLUDE_DIRS@@@${yaml_INCLUDE_DIRS}\n")
FILE(APPEND "${EXPORT_FILE_NAME}" "yaml_LIBRARIES@@@${yaml_LIBRARIES}\n")

10 changes: 5 additions & 5 deletions external/YamlCppLib.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ set(YAML_CPP_BUILD_CONTRIB OFF CACHE BOOL "prevent contrib modules" FORCE)
set(MSVC_SHARED_RT ON CACHE BOOL "Use compile option /MD rather than /MT" FORCE)
add_subdirectory(${yaml-cpp_SOURCE_DIR} ${yaml-cpp_BINARY_DIR})

set(yaml-cpp_INCLUDE_DIRS ${yaml-cpp_SOURCE_DIR}/include)
set(yaml_INCLUDE_DIRS ${yaml-cpp_SOURCE_DIR}/include)
if (MSVC)
set(yaml-cpp_LIBRARIES "${yaml-cpp_BINARY_DIR}$<$<CONFIG:Release>:/Release/libyaml-cppmd.lib>$<$<CONFIG:Debug>:/Debug/libyaml-cppmdd.lib>")
set(yaml_LIBRARIES "${yaml-cpp_BINARY_DIR}$<$<CONFIG:Release>:/Release/libyaml-cppmd.lib>$<$<CONFIG:Debug>:/Debug/libyaml-cppmdd.lib>")
else()
set(yaml-cpp_LIBRARIES ${yaml-cpp_BINARY_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}yaml-cpp${CMAKE_STATIC_LIBRARY_SUFFIX})
set(yaml_LIBRARIES ${yaml-cpp_BINARY_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}yaml-cpp${CMAKE_STATIC_LIBRARY_SUFFIX})
endif()
FILE(APPEND "${EXPORT_FILE_NAME}" "yaml-cpp_INCLUDE_DIRS@@@${yaml-cpp_SOURCE_DIR}/include\n")
FILE(APPEND "${EXPORT_FILE_NAME}" "yaml-cpp_LIBRARIES@@@${yaml-cpp_LIBRARIES}\n")
FILE(APPEND "${EXPORT_FILE_NAME}" "yaml_INCLUDE_DIRS@@@${yaml-cpp_SOURCE_DIR}/include\n")
FILE(APPEND "${EXPORT_FILE_NAME}" "yaml_LIBRARIES@@@${yaml_LIBRARIES}\n")

3 changes: 2 additions & 1 deletion external/bootstrap.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ execute_process(COMMAND ${CMAKE_COMMAND}
-D CMAKE_INSTALL_PREFIX=.
-D NEEDS_BOOST:BOOL=${NEEDS_BOOST}
-D BINDING_BUILD:STRING=${BINDING_BUILD}
-D YAML_PARSER:STRING=${YAML_PARSER}
-D CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-D REPOSITORY_DIR=${REPOSITORY_DIR}
../../external
Expand Down Expand Up @@ -91,7 +92,7 @@ FOREACH(line ${lines})
message(STATUS " ${name} = ${${name}}")
ENDFOREACH()
set(EXTERNAL_INCLUDES
${yaml-cpp_INCLUDE_DIRS}
${yaml_INCLUDE_DIRS}
${Boost_INCLUDE_DIRS}
${eigen_INCLUDE_DIRS}
${mnist_INCLUDE_DIRS}
Expand Down
49 changes: 49 additions & 0 deletions external/libYaml.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# -----------------------------------------------------------------------------
# Numenta Platform for Intelligent Computing (NuPIC)
# Copyright (C) 2019, Numenta, Inc. Unless you have purchased from
# Numenta, Inc. a separate commercial license for this software code, the
# following terms and conditions apply:
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero Public License version 3 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU Affero Public License for more details.
#
# You should have received a copy of the GNU Affero Public License
# along with this program. If not, see http://www.gnu.org/licenses.
#
# http://numenta.org/licenses/
# -----------------------------------------------------------------------------
# This downloads and builds the libyaml library.
#
if(EXISTS ${REPOSITORY_DIR}/build/ThirdParty/share/libyaml.zip
set(URL ${REPOSITORY_DIR}/build/ThirdParty/share/libyaml.zip)
else()
set(URL "https://github.com/yaml/libyaml/archive/master.zip")
endif()

message(STATUS "Obtaining libyaml")
include(DownloadProject/DownloadProject.cmake)
download_project(PROJ libyaml
PREFIX ${EP_BASE}/libyaml
URL ${URL}
GIT_SHALLOW ON
UPDATE_DISCONNECTED 1
QUIET
)

add_subdirectory(${libyaml_SOURCE_DIR} ${libyaml_BINARY_DIR})

set(yaml_INCLUDE_DIRS ${libyaml_SOURCE_DIR}/include)
if (MSVC)
set(yaml_LIBRARIES "${libyaml_BINARY_DIR}$<$<CONFIG:Release>:/Release/liblibyamlmd.lib>$<$<CONFIG:Debug>:/Debug/liblibyamlmdd.lib>")
else()
set(yaml_LIBRARIES ${libyaml_BINARY_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}libyaml${CMAKE_STATIC_LIBRARY_SUFFIX})
endif()
FILE(APPEND "${EXPORT_FILE_NAME}" "yaml_INCLUDE_DIRS@@@${yaml_SOURCE_DIR}\n")
FILE(APPEND "${EXPORT_FILE_NAME}" "yaml_LIBRARIES@@@${yaml_LIBRARIES}\n")

12 changes: 5 additions & 7 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,6 @@ set(engine_files
htm/engine/RegisteredRegionImplCpp.hpp
htm/engine/Spec.cpp
htm/engine/Spec.hpp
htm/engine/YAMLUtils.cpp
htm/engine/YAMLUtils.hpp
htm/engine/Watcher.cpp
htm/engine/Watcher.hpp
)
Expand All @@ -127,9 +125,9 @@ set(ntypes_files
htm/ntypes/BasicType.hpp
htm/ntypes/Collection.hpp
htm/ntypes/Dimensions.hpp
htm/ntypes/Scalar.cpp
htm/ntypes/Scalar.hpp
htm/ntypes/Value.cpp
htm/ntypes/Value-yamlcpp.cpp
htm/ntypes/Value-rapidyaml.cpp
htm/ntypes/Value-libyaml.cpp
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO, only one will be used when finalized

htm/ntypes/Value.hpp
)

Expand Down Expand Up @@ -263,7 +261,7 @@ endif()
#
set(src_combined_htmcore_source_archives
${src_lib_static}
${yaml-cpp_LIBRARIES}
${yaml_LIBRARIES}
${Boost_LIBRARIES}
${common_LIBRARIES}
)
Expand All @@ -283,7 +281,7 @@ else()
# Note that these libraries must already exist (from depenancies)
set(all_object_locations)
set(src_externLibs
${yaml-cpp_LIBRARIES}
${yaml_LIBRARIES}
${Boost_LIBRARIES}
${common_LIBRARIES}
)
Expand Down
11 changes: 4 additions & 7 deletions src/htm/engine/RegionImplFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include <htm/engine/Output.hpp>
#include <htm/engine/Input.hpp>
#include <htm/engine/Spec.hpp>
#include <htm/engine/YAMLUtils.hpp>
#include <htm/ntypes/Value.hpp>
#include <htm/os/Env.hpp>
#include <htm/os/Path.hpp>
Expand Down Expand Up @@ -112,9 +111,8 @@ RegionImpl *RegionImplFactory::createRegionImpl(const std::string nodeType,
Region *region) {

RegionImpl *impl = nullptr;
std::shared_ptr<Spec>& ns = getSpec(nodeType);
ValueMap vm = YAMLUtils::toValueMap(nodeParams.c_str(), ns->parameters,
nodeType, region->getName());
ValueMap vm;
vm.parse(nodeParams);

if (regionTypeMap.find(nodeType) != regionTypeMap.end()) {
impl = regionTypeMap[nodeType]->createRegionImpl(vm, region);
Expand All @@ -124,9 +122,8 @@ RegionImpl *RegionImplFactory::createRegionImpl(const std::string nodeType,

// If the parameter 'dim' was defined, parse that out as a global parameter.
if (vm.contains("dim")) {
std::shared_ptr<Array> dim = vm.getArray("dim");
Dimensions d(dim->asVector<UInt32>());
impl->setDimensions(d);
std::vector<UInt32> dim = vm["dim"].asVector<UInt32>();
impl->setDimensions(dim);
}

return impl;
Expand Down
Loading