Skip to content

Commit

Permalink
[nsd/11arraydesign] Update data prep to use SimpleArray
Browse files Browse the repository at this point in the history
  • Loading branch information
yungyuc committed Jan 23, 2023
1 parent 9250507 commit c55eb58
Show file tree
Hide file tree
Showing 4 changed files with 154 additions and 67 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/nsd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -201,11 +201,9 @@ jobs:
- name: 11arraydesign_solve_cpp
run: |
make -C ${{ env.ARRAYDESIGNROOT }} solve_cpp.so
make -j -C ${{ env.ARRAYDESIGNROOT }} solve_cpp.so
make -C ${{ env.ARRAYDESIGNROOT }} solve_cpp_xarray.so
- name: 11arraydesign_data_prep
# macos does not have MKL.
if: startsWith(matrix.os, 'ubuntu')
run: |
make -C ${{ env.ARRAYDESIGNROOT }} data_prep.so
9 changes: 8 additions & 1 deletion nsd/11arraydesign/code/04_fit_poly.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def __exit__(self, *args, **kw):
self._t1 = time.time()
print("Wall time: {:g} s".format(self._t1 - self._t0))

print("prep")
# [begin prep pycon]
with Timer():
# np.unique returns a sorted array.
Expand Down Expand Up @@ -44,6 +45,7 @@ def plot_poly_fitted(i):
print('write to {}'.format(imagepath))
plt.savefig(imagepath, dpi=150)

print("lumped")
# [begin lumped pycon]
with Timer():
# Do the calculation for the 1000 groups of points.
Expand All @@ -56,6 +58,7 @@ def plot_poly_fitted(i):
polygroup[i,:] = data_prep.fit_poly(sub_x, sub_y, 2)
# [end lumped pycon]

print("point build")
# [begin point build pycon]
with Timer():
# Using numpy to build the point groups takes a lot of time.
Expand All @@ -65,6 +68,7 @@ def plot_poly_fitted(i):
data_groups.append((xdata[slct], ydata[slct]))
# [end point build pycon]

print("fitting")
# [begin fitting pycon]
with Timer():
# Fitting helper runtime is much less than building the point groups.
Expand All @@ -73,13 +77,16 @@ def plot_poly_fitted(i):
polygroup[it,:] = data_prep.fit_poly(sub_x, sub_y, 2)
# [end fitting pycon]

print("batch")
# [begin batch pycon]
with Timer():
rbatch = data_prep.fit_polys(xdata, ydata, 2)
# [end batch pycon]

print(rbatch.shape)
# Verify batch.
assert (rbatch[i] == polygroup[i]).all()
assert len(rbatch) == len(polygroup)
for i in range(1000):
assert (rbatch[i] == polygroup[i]).all()

# vim: set ff=unix fenc=utf8 et sw=4 ts=4 sts=4 tw=79:
35 changes: 19 additions & 16 deletions nsd/11arraydesign/code/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,26 @@ export PYTHONPATH=modmesh-master
UNAME_S := $(shell uname -s)

ifeq ($(UNAME_S),Darwin)
MKLROOT ?= /opt/intel/mkl
MKLINC ?= ${MKLROOT}/include
MKLLIB ?= ${MKLROOT}/lib
MKLEXT ?= a
# Do not define "HASMKL" macro.
INC += -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/Headers
LINKFLAGS := -framework Accelerate
else ifeq ($(UNAME_S),Linux)
MKLINC ?= /usr/include/mkl
CXXFLAGS += -DHASMKL -Wl,--no-as-needed
ifeq (${MKLROOT},)
INC += -I/usr/include/mkl
MKLLIB ?= /usr/lib/x86_64-linux-gnu
MKLEXT ?= so
CXXFLAGS += -Wl,--no-as-needed
else
INC += -I${MKLROOT}/include
MKLLIB ?= ${MKLROOT}/lib/intel64
endif
MKLEXT ?= so

MKLLINKLINE := \
LINKFLAGS := \
${MKLLIB}/libmkl_intel_lp64.${MKLEXT} \
${MKLLIB}/libmkl_sequential.${MKLEXT} \
${MKLLIB}/libmkl_core.${MKLEXT} \
-lpthread -lm -ldl
endif

PYTHON ?= $(shell which python3)
PYTHON_VERSION ?= $(shell $(PYTHON) -c 'import sys; print("%d.%d" % (sys.version_info.major, sys.version_info.minor))')
Expand All @@ -28,16 +32,12 @@ NUMPY_INC := $(shell python3 -c 'import numpy ; print(numpy.get_include())')
MODMESH_ROOT=modmesh_copy
MODMESH_PYMOD=$(MODMESH_ROOT)/modmesh/buffer/pymod

INC := -I$(shell python3-config --prefix)/include -I$(MODMESH_ROOT)
INC += -I$(shell python3-config --prefix)/include -I$(MODMESH_ROOT)

PYTHON_LIB := $(shell python3-config --prefix)/lib

CPATH := $(PYTHON_INC):$(NUMPY_INC)

ifdef YHROOT
CPATH := $(CPATH):$(YHROOT)/usr/$(YHFLAVOR)/include
endif

export CPATH

BASES := 01_grid 01_solve_python_loop 01_solve_analytical
Expand All @@ -64,8 +64,11 @@ testimport: libst

#cpp -v /dev/null -o /dev/null

data_prep.so: data_prep.cpp Makefile
g++ $< -o $@ -O3 -fPIC -shared -std=c++17 -lpython$(PYTHON_VERSION) -L$(PYTHON_LIB) ${INC} -I${MKLINC} ${MKLLINKLINE}
data_prep.o: data_prep.cpp Makefile
g++ -c $< -o $@ -O3 -fPIC -std=c++17 ${INC}

data_prep.so: data_prep.o wrap_SimpleArray.o wrap_ConcreteBuffer.o buffer_pymod.o Makefile
g++ $< wrap_ConcreteBuffer.o wrap_SimpleArray.o buffer_pymod.o -o $@ -shared -std=c++17 -lpython$(PYTHON_VERSION) -L$(PYTHON_LIB) ${LINKFLAGS}

solve_cpp_xarray.so: solve_cpp_xarray.cpp Makefile
g++ $< -o $@ -O3 -fPIC -shared -std=c++17 -lpython$(PYTHON_VERSION) -L$(PYTHON_LIB) ${INC}
Expand All @@ -80,7 +83,7 @@ solve_cpp.o: solve_cpp.cpp Makefile
g++ -c $< -o $@ -O3 -fPIC -std=c++17 ${INC}

solve_cpp.so: solve_cpp.o wrap_SimpleArray.o wrap_ConcreteBuffer.o buffer_pymod.o Makefile
g++ solve_cpp.o wrap_ConcreteBuffer.o wrap_SimpleArray.o buffer_pymod.o -o $@ -shared -std=c++17 -lpython$(PYTHON_VERSION) -L$(PYTHON_LIB)
g++ $< wrap_ConcreteBuffer.o wrap_SimpleArray.o buffer_pymod.o -o $@ -shared -std=c++17 -lpython$(PYTHON_VERSION) -L$(PYTHON_LIB)

../image/03_solve_cpp.png: 03_solve_cpp.py solve_cpp.so
./$<
Expand Down

0 comments on commit c55eb58

Please sign in to comment.