Skip to content
Snippets Groups Projects
Commit 1b7d44b3 authored by Rafael Ravedutti's avatar Rafael Ravedutti
Browse files

Add CUDA compilation rules

parent d20485ef
No related branches found
No related tags found
No related merge requests found
.PHONY: all build clean lj_ns .PHONY: all build clean lj_ns
all: build lj_ns clean all: build lj_ns
@echo "Everything was done!" @echo "Everything was done!"
build: build:
...@@ -10,8 +10,14 @@ build: ...@@ -10,8 +10,14 @@ build:
lj_ns: lj_ns:
@echo "Generating and compiling CPP for Lennard-Jones example..." @echo "Generating and compiling CPP for Lennard-Jones example..."
python3 examples/lj_func.py python3 examples/lj_func.py
# Targets
cpu: build lj_ns
g++ -o lj_ns lj_ns.cpp g++ -o lj_ns lj_ns.cpp
gpu: build lj_ns
nvcc -o lj_ns lj_ns.cu
clean: clean:
@echo "Cleaning..." @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 dist pairs.egg-info functions functions.pdf
...@@ -4,7 +4,7 @@ from pairs.sim.simulation import Simulation ...@@ -4,7 +4,7 @@ from pairs.sim.simulation import Simulation
def simulation(ref, dims=3, timesteps=100, debug=False): def simulation(ref, dims=3, timesteps=100, debug=False):
return Simulation(CGen(f"{ref}.cpp", debug), dims, timesteps) return Simulation(CGen(ref, debug), dims, timesteps)
def target_cpu(): def target_cpu():
return Target(Target.Backend_CPP, Target.Feature_CPU) return Target(Target.Backend_CPP, Target.Feature_CPU)
......
...@@ -26,11 +26,12 @@ from pairs.code_gen.printer import Printer ...@@ -26,11 +26,12 @@ from pairs.code_gen.printer import Printer
class CGen: class CGen:
temp_id = 0 temp_id = 0
def __init__(self, output, target, debug=False): def __init__(self, ref, target, debug=False):
self.sim = None self.sim = None
self.target = None self.target = None
self.print = None
self.ref = ref
self.debug = debug self.debug = debug
self.print = Printer(output)
def assign_simulation(self, sim): def assign_simulation(self, sim):
self.sim = sim self.sim = sim
...@@ -39,6 +40,8 @@ class CGen: ...@@ -39,6 +40,8 @@ class CGen:
self.target = target self.target = target
def generate_program(self, ast_node): def generate_program(self, ast_node):
ext = ".cu" if self.target.is_gpu() else ".cpp"
self.print = Printer(self.ref + ext)
self.print.start() self.print.start()
self.print("#include <math.h>") self.print("#include <math.h>")
self.print("#include <stdbool.h>") self.print("#include <stdbool.h>")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment