From e824ff9a8e55e20da67cd60cae5a50811dbfb0b1 Mon Sep 17 00:00:00 2001 From: Rafael Ravedutti <rafaelravedutti@gmail.com> Date: Thu, 9 Jun 2022 13:32:33 +0200 Subject: [PATCH] Compile both CPU and GPU versions together Signed-off-by: Rafael Ravedutti <rafaelravedutti@gmail.com> --- Makefile | 20 ++++++++++++-------- examples/lj_func.py | 14 +++++++++++++- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index 60e3a0a..c0e74cf 100644 --- a/Makefile +++ b/Makefile @@ -1,23 +1,27 @@ -.PHONY: all build clean lj_ns +.PHONY: all build clean lj_ns_cpu lj_ns_gpu -all: build lj_ns +all: build lj_ns_cpu lj_ns_gpu @echo "Everything was done!" build: @echo "Building pairs package..." python3 setup.py build && python3 setup.py install --user -lj_ns: - @echo "Generating and compiling CPP for Lennard-Jones example..." - python3 examples/lj_func.py +lj_ns_cpu: + @echo "Generating and compiling Lennard-Jones example for CPU..." + python3 examples/lj_func.py cpu + +lj_ns_gpu: + @echo "Generating and compiling Lennard-Jones example for GPU..." + python3 examples/lj_func.py gpu # Targets -cpu: build lj_ns +cpu: build lj_ns_cpu g++ -o lj_ns lj_ns.cpp -gpu: build lj_ns +gpu: build lj_ns_gpu nvcc -o lj_ns lj_ns.cu clean: @echo "Cleaning..." - rm -rf build lj_ns lj_ns.cpp dist pairs.egg-info functions functions.pdf + rm -rf build lj_ns lj_ns.cpp lj_ns.cu dist pairs.egg-info functions functions.pdf diff --git a/examples/lj_func.py b/examples/lj_func.py index 61c8119..2792c07 100644 --- a/examples/lj_func.py +++ b/examples/lj_func.py @@ -1,4 +1,5 @@ import pairs +import sys def lj(i, j): @@ -12,6 +13,12 @@ def euler(i): position[i] += dt * velocity[i] +cmd = sys.argv[0] +target = sys.argv[1] if len(sys.argv[1]) > 1 else "none" +if target != 'cpu' and target != 'gpu': + print(f"Invalid target, use {cmd} <cpu/gpu>") + + dt = 0.005 cutoff_radius = 2.5 skin = 0.3 @@ -32,5 +39,10 @@ psim.vtk_output("output/test") psim.compute(lj, cutoff_radius, {'sigma6': sigma6, 'epsilon': epsilon}) psim.compute(euler, symbols={'dt': dt}) psim.target(pairs.target_cpu()) -#psim.target(pairs.target_gpu()) + +if target == 'gpu': + psim.target(pairs.target_gpu()) +else: + psim.target(pairs.target_cpu()) + psim.generate() -- GitLab