Skip to content

Commit f4f6af4

Browse files
tyh0123ajnonaka
andauthored
MagneX ML code PR (#89)
* docs * docs update * docs update * docs update * use forward euler to simple build works * Update README.md * Update README.md * Update README.md * whitespace * enable DMI and anis in scaling test * skyrmion diagnostic post processing utility * renname file * restart bugfix * sundials 7.1.1 * inputs file for paper demag plot * license and copyright * patches to get regression tests running again some benchmarks will be changing * fix sundials settings * cleanup per Weiqun * logic for different physics wasn't right for single-rate case * add SUNDIALS_HOME * sundials update * comments in inputs file * initial commit * updated ML part of the MagneX by adding: 1. USE_ML flag for during compile. 2. Added 'ml_enable' flag in the input file to control inference with ML or not * clean up makefile * fix trailing whitespace * no longer need fftw includes, these are contained in USE_FFT=TRUE * non ml compile * put in ml_demag protections when not implemented * minor * fixed MagneX.H header for compiling issue * cleanup include statements * pytorch install instructions --------- Co-authored-by: Andy Nonaka <AJNonaka@lbl.gov>
1 parent 69e9b00 commit f4f6af4

11 files changed

Lines changed: 604 additions & 84 deletions

File tree

Exec/GNUmakefile

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,51 @@ USE_HIP = FALSE
99
COMP = gnu
1010
DIM = 3
1111
USE_FFT = TRUE
12-
12+
USE_ML = FALSE
13+
TINY_PROFILE = FALSE
14+
PROFILE = FALSE
1315
USE_SUNDIALS = FALSE
1416
SUNDIALS_HOME ?= ../../sundials/instdir
1517

18+
ifeq ($(USE_ML),TRUE)
19+
20+
CPPFLAGS += -DAMREX_USE_ML
21+
22+
# Define a macro for the C++ preprocessor
23+
DEFINES += -DML_ENABLE -D_GLIBCXX_USE_CXX11_ABI=1
24+
25+
# Pytorch root directory selection
26+
ifeq ($(USE_CUDA),TRUE)
27+
PYTORCH_ROOT := ../../libtorch_cuda
28+
else
29+
PYTORCH_ROOT := ../../libtorch_cpu
30+
endif
31+
32+
TORCH_LIBPATH = $(PYTORCH_ROOT)/lib
33+
34+
# Library definitions
35+
ifeq ($(USE_CUDA),TRUE)
36+
# Note: Modern LibTorch often requires both torch_cuda and torch_cpu
37+
TORCH_LIBS = -ltorch -ltorch_cuda -ltorch_cpu -lc10 -lc10_cuda -lcuda
38+
else
39+
TORCH_LIBS = -ltorch -ltorch_cpu -lc10
40+
endif
41+
42+
# Header search paths
43+
INCLUDE_LOCATIONS += $(PYTORCH_ROOT)/include \
44+
$(PYTORCH_ROOT)/include/torch/csrc/api/include
45+
46+
# Library search paths
47+
LIBRARY_LOCATIONS += $(TORCH_LIBPATH)
48+
49+
# Linker flags (rpath ensures the .so files are found at runtime)
50+
ifeq ($(USE_CUDA),TRUE)
51+
LDFLAGS += -Xlinker "--no-as-needed,-rpath,$(TORCH_LIBPATH)" $(TORCH_LIBS)
52+
else
53+
LDFLAGS += -Wl,--no-as-needed,-rpath=$(TORCH_LIBPATH) $(TORCH_LIBS)
54+
endif
55+
endif
56+
1657
include $(AMREX_HOME)/Tools/GNUMake/Make.defs
1758

1859
include ../Source/Make.package

Exec/README

Lines changed: 0 additions & 72 deletions
This file was deleted.

Exec/README_md.pytorch

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# PyTorch (libtorch) Download and Setup
2+
3+
This guide downloads the libtorch CUDA 11.8 C++ distribution and unzips it in the same directory that contains `MagneX`, then renames the extracted folder to `libtorch_cuda`.
4+
5+
## Steps
6+
7+
1. Change to the parent directory of `MagneX`:
8+
9+
```bash
10+
cd <MAGNEX_PARENT_DIR>
11+
```
12+
13+
2. Download the libtorch archive with `wget`:
14+
15+
```bash
16+
wget https://download.pytorch.org/libtorch/cu118/libtorch-cxx11-abi-shared-with-deps-2.7.1%2Bcu118.zip
17+
```
18+
19+
3. Unzip the archive in the same directory:
20+
21+
```bash
22+
unzip libtorch-cxx11-abi-shared-with-deps-2.7.1+cu118.zip
23+
```
24+
25+
4. Rename the extracted folder to `libtorch_cuda`:
26+
27+
```bash
28+
mv libtorch libtorch_cuda
29+
```
30+
31+
## Result
32+
33+
After the steps above, you should have:
34+
35+
- `<MAGNEX_PARENT_DIR>/MagneX`
36+
- `<MAGNEX_PARENT_DIR>/pytorch_cuda`

Exec/README_md.sundials

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# SUNDIALS Setup
2+
3+
Refer to https://amrex-codes.github.io/amrex/docs_html/TimeIntegration_Chapter.html
4+
for SUNDIALS installation, build, and usage instructions.
5+
6+
Make sure that `SUNDIALS_HOME` in the `GNUmakefile` points to the installation directory.

Exec/README_sundials

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)