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

Add Target class

parent 65f1ea39
No related branches found
No related tags found
No related merge requests found
...@@ -31,4 +31,5 @@ psim.periodic(2.8) ...@@ -31,4 +31,5 @@ psim.periodic(2.8)
psim.vtk_output("output/test") psim.vtk_output("output/test")
psim.compute(lj, cutoff_radius, {'sigma6': sigma6, 'epsilon': epsilon}) psim.compute(lj, cutoff_radius, {'sigma6': sigma6, 'epsilon': epsilon})
psim.compute(euler, symbols={'dt': dt}) psim.compute(euler, symbols={'dt': dt})
psim.target(pairs.target_gpu())
psim.generate() psim.generate()
from pairs.code_gen.cgen import CGen from pairs.code_gen.cgen import CGen
from pairs.code_gen.target import Target
from pairs.sim.simulation import Simulation 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(f"{ref}.cpp", debug), dims, timesteps)
def target_cpu():
return Target(Target.Backend_CPP, Target.Feature_CPU)
def target_gpu():
return Target(Target.Backend_CUDA, Target.Feature_GPU)
class Target:
# Architectures
Arch_x86 = 0
Arch_Nvidia = 1
# Backend
Backend_CPP = 0
Backend_CUDA = 1
Backend_LLVM = 2
# Features
Feature_CPU = 1
Feature_AVX = 2
Feature_AVX2 = 3
Feature_AVX512 = 4
Feature_GPU = 5
# Operating system
OS_Unknown = 0
OS_Linux = 1
OS_Windows = 2
def __init__(self, backend, features, arch=None, os=None):
self.backend = backend
self.features = features if isinstance(features, list) else [features]
self.arch = arch if arch is not None else Target.Arch_x86 if Target.Feature_CPU in self.features else Target.Arch_Nvidia
self.os = os if os is not None else Target.OS_Unknown
def add_feature(self, feature):
self.features.append(feature)
def has_feature(self, feature):
return feature in self.features
def is_cpu(self):
return self.has_feature(Target.Feature_CPU)
def is_gpu(self):
return self.has_feature(Target.Feature_GPU)
...@@ -63,6 +63,7 @@ class Simulation: ...@@ -63,6 +63,7 @@ class Simulation:
self.expr_id = 0 self.expr_id = 0
self.iter_id = 0 self.iter_id = 0
self.vtk_file = None self.vtk_file = None
self._target = None
self.nparticles = self.nlocal + self.nghost self.nparticles = self.nlocal + self.nghost
self.properties.add_capacity(self.particle_capacity) self.properties.add_capacity(self.particle_capacity)
...@@ -214,7 +215,12 @@ class Simulation: ...@@ -214,7 +215,12 @@ class Simulation:
def vtk_output(self, filename): def vtk_output(self, filename):
self.vtk_file = filename self.vtk_file = filename
def target(self, target):
self._target = target
def generate(self): def generate(self):
assert self._target is not None, "Target not specified!"
timestep = Timestep(self, self.ntimesteps, [ timestep = Timestep(self, self.ntimesteps, [
(EnforcePBC(self, self.pbc), 20), (EnforcePBC(self, self.pbc), 20),
(SetupPBC(self, self.pbc), UpdatePBC(self, self.pbc), 20), (SetupPBC(self, self.pbc), UpdatePBC(self, self.pbc), 20),
...@@ -242,7 +248,8 @@ class Simulation: ...@@ -242,7 +248,8 @@ class Simulation:
]) ])
program = Module(self, name='main', block=Block.merge_blocks(decls, body)) program = Module(self, name='main', block=Block.merge_blocks(decls, body))
add_copies = AddDeviceCopies(program) if self._target.is_gpu():
add_copies = AddDeviceCopies(program)
# Transformations # Transformations
lower_everything(program) lower_everything(program)
...@@ -254,7 +261,9 @@ class Simulation: ...@@ -254,7 +261,9 @@ class Simulation:
set_used_bin_ops(program) set_used_bin_ops(program)
modularize(program) modularize(program)
merge_adjacent_blocks(program) merge_adjacent_blocks(program)
add_copies.mutate()
if self._target.is_gpu():
add_copies.mutate()
# For this part on, all bin ops are generated without usage verification # For this part on, all bin ops are generated without usage verification
self.check_decl_usage = False self.check_decl_usage = False
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment