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

Add wasm build #201

Merged
merged 2 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
29 changes: 28 additions & 1 deletion Docs/Build.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,33 @@ Add this to `cmake` command:
-DLINK_NUMA=ON
```

# Cross build for ARM
# Cross build

See [cross build](CrossBuild.md).

# Benchmark build

Sequentual build
```sh
cmake .. -DCMAKE_BUILD_TYPE=Release -DSOLVER_DIM_MODES=DIM3 -DVALUE_TYPE=d -DCOMPLEX_FIELD_VALUES=ON -DPRINT_MESSAGE=ON -DPARALLEL_GRID=OFF
make fdtd3dbench
```

# WebAssembly build

Steps:
- Add `emcmake` before `cmake` command
- Increase inital memory size with `-s INITIAL_MEMORY=134217728`
- Set `-g2` debuggability level
- Add `emmake` before `make` command
- In order to generate htlm directly, change `CMAKE_EXECUTABLE_SUFFIX` to `.html` in /usr/share/emscripten/cmake/Modules/Platform/Emscripten.cmake

For example:
```sh
mkdir Release
cd Release
emcmake cmake .. -DCMAKE_CXX_FLAGS="-g2" -DCMAKE_EXE_LINKER_FLAGS="-s INITIAL_MEMORY=134217728" -DCMAKE_BUILD_TYPE=Release -DSOLVER_DIM_MODES=DIM3 -DVALUE_TYPE=d -DCOMPLEX_FIELD_VALUES=ON -DPRINT_MESSAGE=ON -DPARALLEL_GRID=OFF
emmake make fdtd3dbench
```

This will create `fdtd3d.js`, `fdtd3d.wasm` and `fdtd3d.html`.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

# fdtd3d

This is an open-source implementation of FDTD Maxwell's equations solver for different dimensions (1, 2 or 3) with support of concurrency (MPI/OpenMP/Cuda) if required and for different architectures (x64, Arm, Arm64, RISC-V, PowerPC). The key idea is building of solver for your specific needs with different components, i.e. concurrency support with enabled MPI, OpenMP or GPU support, parallel buffer types, specific dimension and others. OpenMP support is WIP.
This is an open-source implementation of FDTD Maxwell's equations solver for different dimensions (1, 2 or 3) with support of concurrency (MPI/OpenMP/Cuda) if required and for different architectures (x64, Arm, Arm64, RISC-V, PowerPC, Wasm). The key idea is building of solver for your specific needs with different components, i.e. concurrency support with enabled MPI, OpenMP or GPU support, parallel buffer types, specific dimension and others. OpenMP support is WIP.

For additional info on current project development status and future plans check issues and milestones, design docs are available at [documentation](Docs/Design.md). Also, doxygen documentation can be generated from config in `./Doxyfile`:

Expand All @@ -26,7 +26,7 @@ Build is done using cmake:
mkdir Release
cd Release
cmake .. -DCMAKE_BUILD_TYPE=Release
make
make fdtd3d
```

See [documentation](Docs/Build.md) for specific details.
Expand Down
3 changes: 3 additions & 0 deletions Source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ if ("${CUDA_ENABLED}")
set_target_properties (fdtd3d PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
else ()
add_executable (fdtd3d main.cpp)
add_executable (fdtd3dbench main.cpp)
target_compile_definitions (fdtd3dbench PUBLIC PREDEFINED_ARGS)
target_link_libraries (fdtd3dbench Scheme)
endif ()

target_link_libraries (fdtd3d Scheme)
Expand Down
5 changes: 5 additions & 0 deletions Source/Helpers/PAssert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,17 @@
#include "PAssert.h"

#include <cstdlib>

#ifdef HAVE_EXECINFO_H
#include <execinfo.h>
#endif // HAVE_EXECINFO_H

/**
* This function is used to exit and for debugging purposes.
*/
void program_fail ()
{
#ifdef HAVE_EXECINFO_H
const unsigned bufsize = 256;
int nptrs;
void *buffer[bufsize];
Expand All @@ -50,6 +54,7 @@ void program_fail ()
}

free(strings);
#endif // HAVE_EXECINFO

exit (1);
} /* program_fail */
30 changes: 18 additions & 12 deletions Source/Settings/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include "Settings.h"

#include <alloca.h>
#include <string.h>
#include <fstream>
#include <cstring>
Expand Down Expand Up @@ -70,12 +71,14 @@ Settings::Uninitialize ()
*/
CUDA_HOST
void
Settings::parseCoordinate (char *str, /**< string to parse */
Settings::parseCoordinate (const char *str, /**< string to parse */
int &xval, /**< out: x value */
int &yval, /**< out: y value */
int &zval) /**< out: z value */
{
char *coordStr = str;
const char *coordStr = str;
const int tmpBufSize = 16;
char * tmpCoordStr = (char *) alloca (tmpBufSize);
int i = 0;
while (coordStr[i] != '\0')
{
Expand All @@ -90,20 +93,23 @@ Settings::parseCoordinate (char *str, /**< string to parse */
{
isEnd = true;
}
coordStr[i] = '\0';

ASSERT (coordStr[1] == ':');
int val = STOI (coordStr+2);
ASSERT (i < tmpBufSize);
strncpy (tmpCoordStr, coordStr, i);
tmpCoordStr[i] = '\0';

if (coordStr[0] == 'x' || coordStr[0] == 'X')
ASSERT (tmpCoordStr[1] == ':');
int val = STOI (tmpCoordStr+2);

if (tmpCoordStr[0] == 'x' || tmpCoordStr[0] == 'X')
{
xval = val;
}
else if (coordStr[0] == 'y' || coordStr[0] == 'Y')
else if (tmpCoordStr[0] == 'y' || tmpCoordStr[0] == 'Y')
{
yval = val;
}
else if (coordStr[0] == 'z' || coordStr[0] == 'Z')
else if (tmpCoordStr[0] == 'z' || tmpCoordStr[0] == 'Z')
{
zval = val;
}
Expand All @@ -126,7 +132,7 @@ CUDA_HOST
int
Settings::parseArg (int &index, /**< out: current argument index */
int argc, /**< total number of indexes */
char **argv, /**< vector of cmd args */
const char * const * argv, /**< vector of cmd args */
bool isCmd) /**< flag, whether argumens are passed through actual command line */
{
ASSERT (index >= 0 && index < argc);
Expand Down Expand Up @@ -370,7 +376,7 @@ Settings::parseArg (int &index, /**< out: current argument index */
CUDA_HOST
int
Settings::setFromCmd (int argc, /**< number of arguments */
char **argv, /**< arguments */
const char * const * argv, /**< arguments */
bool isCmd) /**< flag, whether argumens are passed through actual command line */
{
if (argc == (isCmd ? 1 : 0))
Expand Down Expand Up @@ -519,7 +525,7 @@ Settings::loadCmdFromFile (std::string fileName) /**< name of file to load from
CUDA_HOST
int
Settings::saveCmdToFile (int argc, /**< number of arguments */
char **argv, /**< arguments */
const char * const * argv, /**< arguments */
std::string fileName) /**< name of file to save to */
{
printf ("Saving command line to file %s\n", fileName.c_str ());
Expand Down Expand Up @@ -550,7 +556,7 @@ Settings::saveCmdToFile (int argc, /**< number of arguments */
CUDA_HOST
void
Settings::SetupFromCmd (int argc, /**< number of arguments */
char **argv) /**< arguments */
const char * const *argv) /**< arguments */
{
int status = setFromCmd (argc, argv, true);

Expand Down
10 changes: 5 additions & 5 deletions Source/Settings/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,12 @@ class Settings

private:

CUDA_HOST int parseArg (int &, int, char **, bool);
CUDA_HOST int setFromCmd (int, char **, bool);
CUDA_HOST int parseArg (int &, int, const char * const *, bool);
CUDA_HOST int setFromCmd (int, const char * const *, bool);
CUDA_HOST int loadCmdFromFile (std::string);
CUDA_HOST int saveCmdToFile (int, char **, std::string);
CUDA_HOST int saveCmdToFile (int, const char * const *, std::string);

CUDA_HOST void parseCoordinate (char *, int &, int &, int &);
CUDA_HOST void parseCoordinate (const char *, int &, int &, int &);

#ifdef CUDA_ENABLED
CUDA_HOST void prepareDeviceSettings ();
Expand Down Expand Up @@ -226,7 +226,7 @@ class Settings
CUDA_HOST void Uninitialize ();

CUDA_HOST
void SetupFromCmd (int, char **);
void SetupFromCmd (int, const char * const *);

#define SETTINGS_ELEM_FIELD_TYPE_NONE(fieldName, getterName, fieldType, defaultVal, cmdArg, description) \
CUDA_DEVICE CUDA_HOST fieldType getterName () \
Expand Down
Loading
Loading