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

Port marian to WASM for inference #24

Merged
merged 46 commits into from
Mar 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
fd4989e
Added __unix__ preprocessor around unistd.h
abhi-agg Nov 19, 2020
efe2c09
Enabled compiling only marian decoder
abhi-agg Jan 29, 2021
80ec1a8
cmake changes for marian decoder only builds
abhi-agg Feb 1, 2021
ab29cbc
Added a wasm compatible blas/sgemm submodule "onnxjs"
abhi-agg Feb 1, 2021
6b95d31
Enabled using wasm-compatible sgemm routine of onnxjs
abhi-agg Dec 3, 2020
773d565
Updated intgemm submodule
abhi-agg Feb 2, 2021
b11cd34
Make marian decoder compile on WASM
abhi-agg Feb 4, 2021
f00909e
Prefer if/else in place of try/catch in FastOpt makeScalar (#774)
graemenail Jan 6, 2021
310cba7
Fix to resolve run time failures for FastOpt enabled WASM builds (#779)
qianqianzhu Jan 7, 2021
c3492d3
Enable compilation without using pthreads
abhi-agg Feb 4, 2021
179b8e6
Removed usage of "register" storage type from code
abhi-agg Feb 5, 2021
caf07b3
Updated onnxjs submodule
abhi-agg Feb 5, 2021
5dafba9
Updated sentencepiece submodule
abhi-agg Feb 5, 2021
a7ee4a1
cmake changes (leftover) for marian decoder only builds
abhi-agg Feb 5, 2021
230c4d9
Updated sentencepiece submodule
abhi-agg Feb 5, 2021
9d7767b
Enable "-pthread" compile flag for COMPILE_WITH_PTHREADS=off
abhi-agg Feb 5, 2021
d2dbf9d
Disabled compiling optimizers/quantizer.cpp file for native builds
abhi-agg Feb 5, 2021
ece499d
Change "sentencepiece" submodule URL from "marian-nmt" to "browsermt"
abhi-agg Feb 12, 2021
08f2b79
Added "wasm" folder and "docker"
abhi-agg Feb 12, 2021
4d1de8c
cmake changes for compiling without try/catch
abhi-agg Feb 15, 2021
769e229
Guard try/catch in marian sources (except submodules)
abhi-agg Feb 15, 2021
dcbcb35
Set ASSERTIONS=0 and DISABLE_EXCEPTION_CATCHING=1 for wasm builds
abhi-agg Feb 15, 2021
3c8a34f
Enable Docker wasm build without exceptions
abhi-agg Feb 15, 2021
2b7f788
Remove trailing slash from intgemm submodule since it caused issues i…
motin Feb 19, 2021
9d2d55a
Remove optimizers/quantizer.cpp from decoder only builds
abhi-agg Feb 24, 2021
dd3c24f
Fix binary model loading on 32bit and make wasm debugging possible on…
XapaJIaMnu Mar 1, 2021
900184d
Enabled simd wormhole for wasm builds (docker based)
abhi-agg Mar 3, 2021
3064e36
Updated intgemm submodule
abhi-agg Mar 4, 2021
e516a37
Updated sentencepiece submodule
abhi-agg Mar 4, 2021
2ca2a23
Build only sentencepiece libraries for marian decoder-only builds
abhi-agg Mar 4, 2021
25a200e
Set intgemm's WORMHOLE cmake option to ON when compiling for WASM
abhi-agg Mar 9, 2021
68b516a
Removed dead code from CMakeLists.txt
abhi-agg Mar 9, 2021
9802096
Cleaned up threadpool.h file for USE_PTHREADS pre-processor
abhi-agg Mar 10, 2021
2344432
Removed deadcode from prod.cpp
abhi-agg Mar 10, 2021
cc77573
Appropriate use of DECODER_ONLY preprocessor directive
abhi-agg Mar 16, 2021
3223a50
Updated CHANGELOG file
abhi-agg Mar 18, 2021
f5cbbbb
Small refactoring
abhi-agg Mar 18, 2021
4012fe0
Removed conditional disabling of try/catch blocks in 3rd party sources
abhi-agg Mar 18, 2021
c3fa3a2
Removed conditional disabling of try/catch blocks in marian sources
abhi-agg Mar 18, 2021
5ecfd6c
Cleaned up docker folder, updated wasm README
abhi-agg Mar 9, 2021
79009b5
Added github workflow for wasm builds
abhi-agg Mar 22, 2021
f2f8694
Fixed GPU only builds on Ubuntu
abhi-agg Mar 23, 2021
db82d12
More clean up in wasm folder
abhi-agg Mar 23, 2021
765f830
Aggregate all wasm specific cmake options under one cmake option
abhi-agg Mar 23, 2021
92132b9
Removed COMPILE_DECODER_ONLY cmake option altogether
abhi-agg Mar 23, 2021
ecd063e
Renamed cmake option COMPILE_WITH_PTHREADS to USE_THREADS
abhi-agg Mar 23, 2021
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
56 changes: 56 additions & 0 deletions .github/workflows/macos-wasm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: MacOS WASM

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
build-wasm:
name: WASM
runs-on: macos-10.15

steps:
- name: Setup Emscripten toolchain
uses: mymindstorm/setup-emsdk@v8

- name: Verify Emscripten setup
run: emcc -v

- name: Checkout
uses: actions/checkout@v2
with:
submodules: recursive

- name: Configure builds
run: |
mkdir -p build-wasm
cd build-wasm
emcmake cmake \
-DCOMPILE_CUDA=off \
-DUSE_DOXYGEN=off \
-DCOMPILE_EXAMPLES=off \
-DCOMPILE_SERVER=off \
-DCOMPILE_TESTS=off \
-DUSE_FBGEMM=off \
-DUSE_SENTENCEPIECE=on \
-DUSE_STATIC_LIBS=on \
-DUSE_MKL=off \
-DCOMPILE_WASM=on ../

- name: Compile
working-directory: build-wasm
run: emmake make -j2

- name: Check artifacts
working-directory: build-wasm
run: |
ls -all .
if ls marian-decoder.wasm &>/dev/null && ls marian-decoder.js &>/dev/null
then
echo "Artifacts Successfully Generated"
else
echo "Failure: Artifacts Not Present"
exit 1
fi
7 changes: 5 additions & 2 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
url = https://github.com/marian-nmt/marian-regression-tests
[submodule "src/3rd_party/sentencepiece"]
path = src/3rd_party/sentencepiece
url = https://github.com/marian-nmt/sentencepiece
url = https://github.com/browsermt/sentencepiece
[submodule "src/3rd_party/nccl"]
path = src/3rd_party/nccl
url = https://github.com/marian-nmt/nccl
Expand All @@ -16,7 +16,10 @@
branch = master
[submodule "src/3rd_party/intgemm"]
path = src/3rd_party/intgemm
url = https://github.com/kpu/intgemm/
url = https://github.com/kpu/intgemm
[submodule "src/3rd_party/simple-websocket-server"]
path = src/3rd_party/simple-websocket-server
url = https://github.com/marian-nmt/Simple-WebSocket-Server
[submodule "src/3rd_party/onnxjs"]
path = src/3rd_party/onnxjs
url = https://github.com/abhi-agg/onnxjs.git
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Quantized training (fixed point or log-based quantization) with --quantize-bits N command
- Support for loading lexical shortlist from a binary blob
- Integrate a shortlist converter (which can convert a text lexical shortlist to a binary shortlist) into marian-conv with --shortlist option
- Added ONNXJS submodule to use its wasm-compatible sgemm routine for wasm builds
- Enable compiling marian on wasm platform

### Fixed
- Segfault of spm_train when compiled with -DUSE_STATIC_LIBS=ON seems to have gone away with update to newer SentencePiece version.
Expand All @@ -55,8 +57,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Added default "none" for option shuffle in BatchGenerator, so that it works in executables where shuffle is not an option.
- Added a few missing header files in shortlist.h and beam_search.h.
- Improved handling for receiving SIGTERM during training. By default, SIGTERM triggers 'save (now) and exit'. Prior to this fix, batch pre-fetching did not check for this sigal, potentially delaying exit considerably. It now pays attention to that. Also, the default behaviour of save-and-exit can now be disabled on the command line with --sigterm exit-immediately.
- Fix the runtime failures for FASTOPT on 32-bit builds (wasm just happens to be 32-bit) because it uses hashing with an inconsistent mix of uint64_t and size_t.
abhi-agg marked this conversation as resolved.
Show resolved Hide resolved
- Fix loading the binary model on 32-bit builds and for wasm platform

### Changed
- Updated intgemm repository to version 1a176394bb0c2d243c42fe574e063924a92aa120 from https://github.com/kpu/intgemm.
- Changed SentencePiece repository from https://github.com/google/sentencepiece to the version 3ffdc0065a03cadd9d0e5e123aaf9b6ea7ffb05d of https://github.com/browsermt/sentencepiece.
- Updated SentencePiece repository to version 8336bbd0c1cfba02a879afe625bf1ddaf7cd93c5 from https://github.com/google/sentencepiece.
- Enabled compilation of SentencePiece by default since no dependency on protobuf anymore.
- Changed default value of --sentencepiece-max-lines from 10000000 to 2000000 since apparently the new version doesn't sample automatically anymore (Not quite clear how that affects quality of the vocabulary).
Expand All @@ -68,6 +74,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Changed compile flags -Ofast to -O3 and remove --ffinite-math
- Moved old graph groups to depracated folder
- Make cublas and cusparse handle inits lazy to save memory when unused
- Replaced exception-based implementation for type determination in FastOpt::makeScalar

## [1.9.0] - 2020-03-10

Expand Down
148 changes: 108 additions & 40 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ endif ()
project(marian CXX C)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(BUILD_ARCH native CACHE STRING "Compile for this CPU architecture.")

include(CMakeDependentOption)

# Custom CMake options
option(COMPILE_CPU "Compile CPU version" ON)
Expand All @@ -26,6 +27,41 @@ option(USE_NCCL "Use NCCL library" ON)
option(USE_SENTENCEPIECE "Download and compile SentencePiece" ON)
option(USE_STATIC_LIBS "Link statically against non-system libs" OFF)
option(GENERATE_MARIAN_INSTALL_TARGETS "Generate Marian install targets (requires CMake 3.12+)" OFF)
option(M32_BINARIES "Generate 32bit binaries even when building outside of WASM. Useful for testing some WASM specific functionality without the need for the compiling to WASM." OFF)
option(COMPILE_WASM "Compile customized marian for WASM target" OFF)

# cmake options that are dependent on COMPILE_WASM cmake option
CMAKE_DEPENDENT_OPTION(USE_THREADS "Compile with multi-threading support" OFF
"COMPILE_WASM" ON)
CMAKE_DEPENDENT_OPTION(USE_WASM_COMPATIBLE_BLAS "Compile with wasm compatible blas" ON
"COMPILE_WASM" OFF)
CMAKE_DEPENDENT_OPTION(COMPILE_WITHOUT_EXCEPTIONS "Compile without exceptions" ON
"COMPILE_WASM" OFF)

if (COMPILE_WASM)
set(WORMHOLE ON CACHE BOOL "Use WASM wormhole in intgemm https://bugzilla.mozilla.org/show_bug.cgi?id=1672160")
endif()

if(M32_BINARIES OR COMPILE_WASM)
set("BUILD_WIDTH" "-m32")
else(M32_BINARIES OR COMPILE_WASM)
set("BUILD_WIDTH" "-m64")
endif()

if(NOT COMPILE_WASM)
# Setting BUILD_ARCH to native invokes CPU intrinsic detection logic below.
# Prevent invoking that logic for WASM builds.
set(BUILD_ARCH native CACHE STRING "Compile for this CPU architecture.")
endif()

if(USE_THREADS)
# Need to set compile definition as well
add_compile_definitions(USE_PTHREADS)
endif()

if(COMPILE_WITHOUT_EXCEPTIONS)
add_compile_definitions(WITHOUT_EXCEPTIONS)
endif()

# fbgemm and sentencepiece are both defined with "non-local" installation targets (the source projects don't define them,
# so we define them in src\3rd_party\CMakeLists.txt), but that isn't supported until CMake 3.12. Prior to CMake 3.12,
Expand Down Expand Up @@ -165,6 +201,10 @@ else(MSVC)
set(INTRINSICS "${INTRINSICS} -mavx512f")
list(APPEND INTRINSICS_NVCC -Xcompiler\ -mavx512f)
endif(AVX512_FOUND)
elseif(COMPILE_WASM)
# Can't set to -msse4.1 because onnxjs doesn't compile with this flag. It can be upgraded to
# -msse4.1 once marian can solely be compiled with intgemm ("onnxjs" will be removed in that case)
set(INTRINSICS "-mssse3 -msimd128")
else()
set(INTRINSICS "-msse4.1")
endif()
Expand Down Expand Up @@ -197,24 +237,44 @@ else(MSVC)
set(CMAKE_RDYNAMIC_FLAG "-rdynamic")
endif(CMAKE_COMPILER_IS_GNUCC)

set(CMAKE_CXX_FLAGS "-std=c++11 -pthread ${CMAKE_GCC_FLAGS} -fPIC ${DISABLE_GLOBALLY} -march=${BUILD_ARCH} ${INTRINSICS}")
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -m64 -funroll-loops -g ${CMAKE_RDYNAMIC_FLAG}")
set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g ${CMAKE_RDYNAMIC_FLAG}")
set(CMAKE_CXX_FLAGS_SLIM "-O3 -m64 -funroll-loops -DNDEBUG")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELEASE}")
set(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_CXX_FLAGS_RELEASE} -pg")
set(CMAKE_CXX_FLAGS_PROFGEN "${CMAKE_CXX_FLAGS_RELEASE} -fprofile-generate -fprofile-correction")
set(CMAKE_CXX_FLAGS_PROFUSE "${CMAKE_CXX_FLAGS_RELEASE} -fprofile-use -fprofile-correction")

# these need to be set separately
set(CMAKE_C_FLAGS "-pthread ${CMAKE_GCC_FLAGS} -fPIC ${DISABLE_GLOBALLY} -march=${BUILD_ARCH} ${INTRINSICS}")
set(CMAKE_C_FLAGS_RELEASE "-O3 -m64 -funroll-loops -g ${CMAKE_RDYNAMIC_FLAG}")
set(CMAKE_C_FLAGS_DEBUG "-O0 -g ${CMAKE_RDYNAMIC_FLAG}")
set(CMAKE_C_FLAGS_SLIM "-O3 -m64 -funroll-loops -DNDEBUG")
set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELEASE}")
set(CMAKE_C_FLAGS_PROFILE "${CMAKE_C_FLAGS_RELEASE} -pg")
set(CMAKE_C_FLAGS_PROFGEN "${CMAKE_C_FLAGS_RELEASE} -fprofile-generate -fprofile-correction")
set(CMAKE_C_FLAGS_PROFUSE "${CMAKE_C_FLAGS_RELEASE} -fprofile-use -fprofile-correction")
if(COMPILE_WASM)
# Setting USE_SSE2 definition to enable SSE2 specific code in "3rd_party/sse_mathfun.h" for wasm builds
add_compile_definitions(USE_SSE2)
# Add compile definition for wasm builds
add_compile_definitions(WASM)
set(PTHREAD_FLAG "-pthread")
set(DISABLE_PTHREAD_MEMGROWTH_WARNING -Wno-error=pthreads-mem-growth)
set(CMAKE_CXX_FLAGS "-std=c++11 ${PTHREAD_FLAG} ${CMAKE_GCC_FLAGS} -fPIC ${DISABLE_GLOBALLY} ${INTRINSICS}")
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -s WASM=1 -s ASSERTIONS=0 -s DISABLE_EXCEPTION_CATCHING=1 -s LLD_REPORT_UNDEFINED -s FORCE_FILESYSTEM=1 -s ALLOW_MEMORY_GROWTH=1 -g2 ${DISABLE_PTHREAD_MEMGROWTH_WARNING} -funroll-loops")
# Disabling Pthreads + memory growth warning to be an error
# Pthreads + memory growth causes JS accessing the wasm memory to be slow
# https://github.com/WebAssembly/design/issues/1271
list(APPEND ALL_WARNINGS ${DISABLE_PTHREAD_MEMGROWTH_WARNING})

# use our customizations to the generated emscripted html and js resources
set(MARIAN_DECODER_EMSCRIPTEN_LINK_FLAGS "--pre-js ${CMAKE_SOURCE_DIR}/wasm/pre-module.js \
--post-js ${CMAKE_SOURCE_DIR}/wasm/post-module.js \
--shell-file ${CMAKE_SOURCE_DIR}/wasm/custom_shell.html")
else(COMPILE_WASM)
set(CMAKE_CXX_FLAGS "-std=c++11 -pthread ${CMAKE_GCC_FLAGS} -fPIC ${DISABLE_GLOBALLY} -march=${BUILD_ARCH} ${INTRINSICS} ${BUILD_WIDTH}")
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -funroll-loops -g ${CMAKE_RDYNAMIC_FLAG}")
set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g ${CMAKE_RDYNAMIC_FLAG}")
set(CMAKE_CXX_FLAGS_SLIM "-O3 ${BUILD_WIDTH} -funroll-loops -DNDEBUG")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELEASE}")
set(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_CXX_FLAGS_RELEASE} -pg")
set(CMAKE_CXX_FLAGS_PROFGEN "${CMAKE_CXX_FLAGS_RELEASE} -fprofile-generate -fprofile-correction")
set(CMAKE_CXX_FLAGS_PROFUSE "${CMAKE_CXX_FLAGS_RELEASE} -fprofile-use -fprofile-correction")

# these need to be set separately
set(CMAKE_C_FLAGS "-pthread ${CMAKE_GCC_FLAGS} -fPIC ${DISABLE_GLOBALLY} -march=${BUILD_ARCH} ${INTRINSICS}")
set(CMAKE_C_FLAGS_RELEASE "-O3 ${BUILD_WIDTH} -funroll-loops -g ${CMAKE_RDYNAMIC_FLAG}")
set(CMAKE_C_FLAGS_DEBUG "-O0 -g ${CMAKE_RDYNAMIC_FLAG}")
set(CMAKE_C_FLAGS_SLIM "-O3 ${BUILD_WIDTH} -funroll-loops -DNDEBUG")
set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELEASE}")
set(CMAKE_C_FLAGS_PROFILE "${CMAKE_C_FLAGS_RELEASE} -pg")
set(CMAKE_C_FLAGS_PROFGEN "${CMAKE_C_FLAGS_RELEASE} -fprofile-generate -fprofile-correction")
set(CMAKE_C_FLAGS_PROFUSE "${CMAKE_C_FLAGS_RELEASE} -fprofile-use -fprofile-correction")
endif(COMPILE_WASM)
endif(MSVC)

# with gcc 7.0 and above we need to mark fallthrough in switch case statements
Expand Down Expand Up @@ -435,29 +495,37 @@ if(USE_MPI)
endif(USE_MPI)

###############################################################################
# Find MKL
# Find BLAS library for CPU compilation
if(COMPILE_CPU)
set(EXT_LIBS ${EXT_LIBS} intgemm)
if(USE_MKL)
find_package(MKL)
endif(USE_MKL)
if(MKL_FOUND)
include_directories(${MKL_INCLUDE_DIR})
set(EXT_LIBS ${EXT_LIBS} ${MKL_LIBRARIES})
if(USE_WASM_COMPATIBLE_BLAS)
## Use a wasm compatible BLAS
set(EXT_LIBS ${EXT_LIBS} intgemm onnx-sgemm)
set(BLAS_FOUND TRUE)
add_definitions(-DCOMPILE_CPU=1 -DBLAS_FOUND=1 -DMKL_FOUND=1)
else(MKL_FOUND)
set(BLAS_VENDOR "OpenBLAS")
find_package(BLAS)
if(BLAS_FOUND)
include(FindCBLAS)
if(CBLAS_FOUND)
include_directories(${BLAS_INCLUDE_DIR} ${CBLAS_INCLUDE_DIR})
set(EXT_LIBS ${EXT_LIBS} ${BLAS_LIBRARIES} ${CBLAS_LIBRARIES})
add_definitions(-DCOMPILE_CPU=1 -DBLAS_FOUND=1)
endif(CBLAS_FOUND)
endif(BLAS_FOUND)
endif(MKL_FOUND)
set(BLAS_VENDOR "ONNX-SGEMM")
add_compile_definitions(COMPILE_CPU BLAS_FOUND WASM_COMPATIBLE_BLAS)
else(USE_WASM_COMPATIBLE_BLAS)
set(EXT_LIBS ${EXT_LIBS} intgemm)
Copy link
Member

Choose a reason for hiding this comment

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

nit could have been outside the if statement

if(USE_MKL)
find_package(MKL)
endif(USE_MKL)
if(MKL_FOUND)
include_directories(${MKL_INCLUDE_DIR})
set(EXT_LIBS ${EXT_LIBS} ${MKL_LIBRARIES})
set(BLAS_FOUND TRUE)
add_definitions(-DCOMPILE_CPU=1 -DBLAS_FOUND=1 -DMKL_FOUND=1)
else(MKL_FOUND)
set(BLAS_VENDOR "OpenBLAS")
find_package(BLAS)
if(BLAS_FOUND)
include(FindCBLAS)
if(CBLAS_FOUND)
include_directories(${BLAS_INCLUDE_DIR} ${CBLAS_INCLUDE_DIR})
set(EXT_LIBS ${EXT_LIBS} ${BLAS_LIBRARIES} ${CBLAS_LIBRARIES})
add_definitions(-DCOMPILE_CPU=1 -DBLAS_FOUND=1)
endif(CBLAS_FOUND)
endif(BLAS_FOUND)
endif(MKL_FOUND)
endif(USE_WASM_COMPATIBLE_BLAS)
endif(COMPILE_CPU)

###############################################################################
Expand Down
17 changes: 12 additions & 5 deletions src/3rd_party/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,21 @@
include_directories(.)

add_subdirectory(./yaml-cpp)
add_subdirectory(./SQLiteCpp)
if(NOT COMPILE_WASM)
add_subdirectory(./SQLiteCpp)
add_subdirectory(./zlib)
add_subdirectory(./faiss)
include_directories(./faiss)
endif()
add_subdirectory(./pathie-cpp)
add_subdirectory(./zlib)
add_subdirectory(./faiss)
include_directories(./faiss)

set(INTGEMM_DONT_BUILD_TESTS ON CACHE BOOL "Disable intgemm tests")
add_subdirectory(./intgemm)

if(USE_WASM_COMPATIBLE_BLAS)
add_subdirectory(./onnxjs)
endif(USE_WASM_COMPATIBLE_BLAS)

if(USE_FBGEMM)
# @TODO: find out if this is somehow harmful. This is supppressing CMake warnings for CMAKE_SUPPRESS_DEVELOPER_WARNINGS
# meant to silence CMakeFiles of 3rd_party tools.
Expand Down Expand Up @@ -78,7 +84,6 @@ if(USE_SENTENCEPIECE)

add_subdirectory(./sentencepiece)
include_directories(./sentencepiece)

set_target_properties(spm_encode spm_decode spm_train spm_normalize spm_export_vocab
PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}")

Expand Down Expand Up @@ -123,13 +128,15 @@ include_directories(./CLI)
include_directories(./pathie-cpp/include)

if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
if(NOT COMPILE_WASM)
#set_target_properties(SQLiteCpp PROPERTIES COMPILE_FLAGS
set_property(TARGET SQLiteCpp APPEND_STRING PROPERTY COMPILE_FLAGS
" -Wno-parentheses-equality -Wno-unused-value")
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 9.0)
set_property(TARGET SQLiteCpp APPEND_STRING PROPERTY COMPILE_FLAGS
" -Wno-implicit-int-float-conversion")
endif()
endif()
set_property(TARGET libyaml-cpp APPEND_STRING PROPERTY COMPILE_FLAGS
" -fPIC -Wno-unused-value")
set_property(TARGET pathie-cpp APPEND_STRING PROPERTY COMPILE_FLAGS
Expand Down
12 changes: 11 additions & 1 deletion src/3rd_party/cnpy/cnpy.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
#ifndef LIBCNPY_H_
#define LIBCNPY_H_

#if !defined(WASM)
Copy link
Member

Choose a reason for hiding this comment

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

Fun fact: now that @XapaJIaMnu has binary working, you can get rid of cnpy entirely.

Copy link
Author

Choose a reason for hiding this comment

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

Yes, but for compilation we will still have to keep this ifdef. Right?

#include "3rd_party/zlib/zlib.h"
#endif

#include<string>
#include<stdexcept>
Expand All @@ -18,7 +20,7 @@
#include<map>
#include <memory>

#ifdef __APPLE__
#if defined(__APPLE__) || defined(__unix__)
#include <unistd.h>
#endif

Expand Down Expand Up @@ -133,6 +135,9 @@ namespace cnpy {

template<typename T> void npz_save(std::string zipname, std::string fname, const T* data, const unsigned int* shape, const unsigned int ndims, std::string mode = "w")
{
#if defined(WASM)
throw std::runtime_error("npz_save() not supported in WASM builds");
#else
//first, append a .npy to the fname
fname += ".npy";

Expand Down Expand Up @@ -221,6 +226,7 @@ namespace cnpy {
fwrite(&footer[0],sizeof(char),footer.size(),fp);
//BUGBUG: no check for write error
fclose(fp);
#endif
}

//one item pass to npz_save() below
Expand Down Expand Up @@ -265,6 +271,9 @@ namespace cnpy {
static inline
void npz_save(std::string zipname, const std::vector<NpzItem>& items)
{
#if defined(WASM)
throw std::runtime_error("npz_save() not supported in WASM builds");
#else
auto tmpname = zipname + "$$"; // TODO: add thread id or something
unlink(tmpname.c_str()); // when saving to HDFS, we cannot overwrite an existing file
FILE* fp = fopen(tmpname.c_str(),"wb");
Expand Down Expand Up @@ -366,6 +375,7 @@ namespace cnpy {
unlink(tmpname.c_str());
throw std::runtime_error("npz_save: error saving to file: " + zipname);
}
#endif
}

static inline
Expand Down
Loading