From e33eaa6f20fb12939f0aad9e52c73bc5646c6c42 Mon Sep 17 00:00:00 2001 From: mike dupont Date: Wed, 29 Nov 2023 15:41:23 -0500 Subject: [PATCH 1/3] compile on gcc --- CMakeLists.txt | 3 ++- dynet/exec.cc | 2 +- dynet/nodes-softmaxes.cc | 2 +- dynet/simd-functors.h | 5 +++++ 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ae2252acb..23a9873b1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -84,7 +84,7 @@ endif() if(MSVC) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -W1 /MP") # -Wall produces 20k warnings. Enable parallel compilation else() - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -fno-finite-math-only -Wall -Wno-missing-braces -std=c++11") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -fno-finite-math-only -Wall -Wno-missing-braces -std=c++20") if (NOT RELEASE_OPT_LEVEL) set(RELEASE_OPT_LEVEL "fast") @@ -181,6 +181,7 @@ if (WITH_CUDA_BACKEND) endif() endif() +set(EIGEN3_INCLUDE_DIR /usr/local/include/eigen3/) # look for Eigen if (DEFINED ENV{EIGEN3_INCLUDE_DIR} AND NOT DEFINED EIGEN3_INCLUDE_DIR) # use env variable if not set set(EIGEN3_INCLUDE_DIR $ENV{EIGEN3_INCLUDE_DIR}) diff --git a/dynet/exec.cc b/dynet/exec.cc index 8594dd70d..5817ba67b 100644 --- a/dynet/exec.cc +++ b/dynet/exec.cc @@ -7,7 +7,7 @@ #include "dynet/globals.h" #include "dynet/timing.h" #include "dynet/devices.h" - +#include #ifdef HAVE_CUDA #include "dynet/gpu-ops.h" #endif diff --git a/dynet/nodes-softmaxes.cc b/dynet/nodes-softmaxes.cc index e3c4f9ac1..99c49e1af 100644 --- a/dynet/nodes-softmaxes.cc +++ b/dynet/nodes-softmaxes.cc @@ -3,7 +3,7 @@ #include "dynet/nodes-impl-macros.h" #include "dynet/functors.h" - +#include using namespace std; namespace dynet { diff --git a/dynet/simd-functors.h b/dynet/simd-functors.h index 951863a00..3ffed8f1d 100644 --- a/dynet/simd-functors.h +++ b/dynet/simd-functors.h @@ -70,6 +70,11 @@ struct functor_traits > { }; } } +#define EIGEN_EMPTY_STRUCT_CTOR(X) \ + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE X() {} \ + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE X(const X& ) {} + + namespace dynet { template struct scalar_logistic_sigmoid_op { EIGEN_EMPTY_STRUCT_CTOR(scalar_logistic_sigmoid_op) From e2e46dc6bceac5a4456343cb80791a33c7286b39 Mon Sep 17 00:00:00 2001 From: mike dupont Date: Fri, 1 Dec 2023 05:46:41 -0500 Subject: [PATCH 2/3] python building --- CMakeLists.txt | 1 + setup.py | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 23a9873b1..75112e429 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,6 +2,7 @@ project(dynet) cmake_minimum_required(VERSION 2.8 FATAL_ERROR) set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake) +set(PYTHON) # DYNET uses Eigen which exploits modern CPU architectures. To get the # best possible performance, the following are recommended: diff --git a/setup.py b/setup.py index 179c1d713..ca6d58c39 100644 --- a/setup.py +++ b/setup.py @@ -108,10 +108,12 @@ def get_env(build_dir): PYTHON = sys.executable # Try to find Eigen -EIGEN3_INCLUDE_DIR = ENV.get("EIGEN3_INCLUDE_DIR") # directory where eigen is saved +EIGEN3_INCLUDE_DIR = "/usr/local/include/eigen3/" +#ENV.get("EIGEN3_INCLUDE_DIR") # directory where eigen is saved # The cmake directory and Python directory are different in manual install, so # will break if relative path is specified. Try moving up if path is specified # but not found + if (EIGEN3_INCLUDE_DIR is not None and not os.path.isdir(EIGEN3_INCLUDE_DIR) and os.path.isdir(os.path.join(os.pardir, EIGEN3_INCLUDE_DIR))): @@ -154,7 +156,7 @@ def get_env(build_dir): append_cmake_list(LIBRARY_DIRS, ENV.get("CUDA_RT_DIRS")) DATA_FILES += [DYNET_LIB_DIR + lib + ".lib" for lib in LIBRARIES] else: - COMPILER_ARGS[:] = ["-std=c++11", "-Wno-unused-function"] + COMPILER_ARGS[:] = ["-std=c++20", "-Wno-unused-function"] RUNTIME_LIB_DIRS.extend([DYNET_LIB_DIR, LIBS_INSTALL_DIR]) # in some OSX systems, the following extra flags are needed: if platform.system() == "Darwin": From 19d542a6f3a07e002ff583f504c6fc1ddd6f301b Mon Sep 17 00:00:00 2001 From: mike dupont Date: Fri, 1 Dec 2023 12:09:48 -0500 Subject: [PATCH 3/3] fix typo --- CMakeLists.txt | 2 +- dynet/dynet.cc | 3 ++- dynet/io.cc | 1 + examples/jupyter-tutorials/RNNs.ipynb | 2 +- 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 75112e429..60df58450 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,7 @@ project(dynet) cmake_minimum_required(VERSION 2.8 FATAL_ERROR) set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake) -set(PYTHON) +set(PYTHON "/home/mdupont/.pyenv/shims/python") # DYNET uses Eigen which exploits modern CPU architectures. To get the # best possible performance, the following are recommended: diff --git a/dynet/dynet.cc b/dynet/dynet.cc index 2d7c533ef..64bdb631c 100644 --- a/dynet/dynet.cc +++ b/dynet/dynet.cc @@ -1,4 +1,5 @@ -#include +#in +clude #include #include "dynet/dynet.h" diff --git a/dynet/io.cc b/dynet/io.cc index 766962615..408caeaa2 100644 --- a/dynet/io.cc +++ b/dynet/io.cc @@ -251,6 +251,7 @@ void TextFileLoader::populate(LookupParameter & lookup_param, if(lookup_param.p->all_dim != dim) DYNET_RUNTIME_ERR("Attempted to populate lookup parameter where arguments don't match (" << lookup_param.p->all_dim << " != " << dim << ")"); std::vector values(dim.size()); + copy(bu, &dataArray[dataArraySize], back_inserter(dataVec)); { std::getline(datastream, line); std::istringstream iss(line); iss >> values; } TensorTools::set_elements(lookup_param.get_storage().all_values, values); if(!zero_grad){ diff --git a/examples/jupyter-tutorials/RNNs.ipynb b/examples/jupyter-tutorials/RNNs.ipynb index 69115066c..5f61eb517 100644 --- a/examples/jupyter-tutorials/RNNs.ipynb +++ b/examples/jupyter-tutorials/RNNs.ipynb @@ -392,7 +392,7 @@ "What if we do not care about `.s()` and `.h()`, and do not need to access the previous vectors? In such cases\n", "we can use the `transduce(xs)` method instead of `add_inputs(xs)`.\n", "`transduce` takes in a sequence of `Expression`s, and returns a sequence of `Expression`s.\n", - "As a consequence of not returning `RNNState`s, `trnasduce` is much more memory efficient than `add_inputs` or a series of calls to `add_input`. " + "As a consequence of not returning `RNNState`s, `transduce` is much more memory efficient than `add_inputs` or a series of calls to `add_input`. " ] }, {