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

Add first (almost) working version with runtime

parent 75bf109d
No related branches found
No related tags found
No related merge requests found
......@@ -6,6 +6,7 @@ from ir.cast import Cast
from ir.bin_op import BinOp, BinOpDef
from ir.data_types import Type_Int, Type_Float, Type_String, Type_Vector
from ir.functions import Call
from ir.layouts import Layout_AoS, Layout_SoA, Layout_Invalid
from ir.lit import Lit
from ir.loops import For, Iter, ParticleFor, While
from ir.math import Sqrt
......@@ -160,7 +161,16 @@ class CGen:
"Prop_Invalid"
assert ptype != "Prop_Invalid", "Invalid property type!"
self.print(f"ps->addProperty(Property({p.id()}, \"{p.name()}\", {p.name()}, {ptype}));")
playout = "AoS" if p.layout() == Layout_AoS else \
"SoA" if p.layout() == Layout_SoA else \
"Invalid"
if p.type() != Type_Vector or p.layout() == Layout_Invalid:
self.print(f"ps->addProperty(Property({p.id()}, \"{p.name()}\", {p.name()}, {ptype}));")
else:
sizes = ", ".join([str(self.generate_expression(size)) for size in ast_node.sizes()])
self.print(f"ps->addProperty(Property({p.id()}, \"{p.name()}\", {p.name()}, {ptype}, {playout}, {sizes}));")
if isinstance(ast_node, Timestep):
self.generate_statement(ast_node.block)
......
from ir.ast_node import ASTNode
from ir.layouts import Layout_AoS
from ir.lit import as_lit_ast
class Properties:
......@@ -100,13 +101,17 @@ class PropertyList(ASTNode):
class RegisterProperty(ASTNode):
def __init__(self, sim, prop):
def __init__(self, sim, prop, sizes):
super().__init__(sim)
self.prop = prop
self.sizes_list = [as_lit_ast(sim, s) for s in sizes]
self.sim.add_statement(self)
def property(self):
return self.prop
def sizes(self):
return self.sizes_list
def __str__(self):
return f"Property<{self.prop.name()}>"
......@@ -16,7 +16,7 @@ size_t read_particle_data(PairsSim *ps, const char *filename, double *grid_buffe
int read_grid_data = 0;
if(in_file.is_open()) {
while(getline(in_file, line)) {
while(std::getline(in_file, line)) {
std::stringstream line_stream(line);
std::string in0;
int i = 0;
......@@ -25,7 +25,6 @@ size_t read_particle_data(PairsSim *ps, const char *filename, double *grid_buffe
if(!read_grid_data) {
PAIRS_ASSERT(i < ps->getNumDims() * 2);
grid_buffer[i] = std::stod(in0);
read_grid_data = 1;
} else {
PAIRS_ASSERT(i < nprops);
property_t p_id = properties[i];
......@@ -55,7 +54,8 @@ size_t read_particle_data(PairsSim *ps, const char *filename, double *grid_buffe
i++;
}
n++;
n += (read_grid_data) ? 1 : 0;
read_grid_data = 1;
}
in_file.close();
......
from functools import reduce
from ir.data_types import Type_Float, Type_Vector
from ir.loops import ParticleFor
from ir.memory import Malloc, Realloc
from ir.properties import RegisterProperty
from ir.utils import Print
import operator
class PropertiesAlloc:
......@@ -19,15 +21,15 @@ class PropertiesAlloc:
if p.type() == Type_Float:
sizes = [capacity]
elif p.type() == Type_Vector:
sizes = [capacity * self.sim.ndims()]
sizes = [capacity, self.sim.ndims()]
else:
raise Exception("Invalid property type!")
if self.realloc:
Realloc(self.sim, p, sizes)
Realloc(self.sim, p, reduce(operator.mul, sizes))
else:
Malloc(self.sim, p, sizes, True)
RegisterProperty(self.sim, p)
Malloc(self.sim, p, reduce(operator.mul, sizes), True)
RegisterProperty(self.sim, p, sizes)
return self.sim.block
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment