-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtile.cpp
More file actions
112 lines (101 loc) · 4.07 KB
/
tile.cpp
File metadata and controls
112 lines (101 loc) · 4.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include "tile.hpp"
int main(int argc, char const *argv[])
{
/** NECESSARY FOR THE LANGUAGE'S GLOBAL ENVIRONMENT **/
/** ASSUMED GIVENS FROM USER **/
// Creates an ISL context.
isl_ctx *ctx = isl_ctx_alloc();
/** Creates the topology. **/
// The SRCs mapping to some unknown occupancy.
isl_map *src_occ = isl_map_read_from_str(ctx,
R"SRCS({ [xs, ys] -> [data] |
(0 <= xs < 2) and
(0 <= ys < 2) and
0 <= data < 16
})SRCS"
);
// The DSTs mapping to a known quantity.
isl_map *dst_fill = isl_map_read_from_str(ctx,
R"DSTS({ [xd, yd] -> [data] |
(0 <= xd < 4) and
(0 <= yd < 4) and
(4yd <= data < 4yd + 4) and
0 <= data < 16
})DSTS"
);
/* Defines the distance function, which serves as a unification of the
* src_occ and dst_fill coordinate systems. */
isl_map *dist_calc = isl_map_read_from_str(ctx,
R"DIST({[[xs, ys] -> [xd, yd]] -> [dist] |
2xs + 2ys + xd + yd = dist
})DIST"
);
/** PROGRAMMATIC GENERATION WITH TILE **/
// Generates the tiling and the subtiling.
isl_map *tiling = tile(0, isl_map_get_space(src_occ), 8, 1);
isl_map *subtiling = tile(0, isl_map_get_space(tiling), 4, 0);
// Intersects the two tiling specifications with existing src_occ specs.
src_occ = isl_map_intersect(isl_map_intersect(src_occ, tiling), subtiling);
// Dumps out combined result.
isl_map_dump(src_occ);
// Frees variables not already handled by __isl_take input params.
isl_map_free(src_occ);
isl_map_free(dst_fill);
isl_map_free(dist_calc);
// Frees ctx to ensure on program exit everything is freed.
isl_ctx_free(ctx);
return 0;
}
/**
* Creates an ISL set that restricts the data domain to a tiling split along a
* certain axis.
*
* Read as: Tile the data axis in position data_dim from
* src_space in blocks of n consecutive elements along src axis axis_dim.
*
* @param data_dim __isl_keep The data axis index.
* @param src_space __isl_take The space in which the axis is defined.
* @param n __isl_keep The number of elements in a block.
* @param axis_dim __isl_keep The axis index to tile along.
*/
isl_map *tile(
int data_dim,
isl_space *src_space,
int n,
int axis_dim
) {
// Allocates local space for the tiling restriction.
isl_local_space *tile_local_space = isl_local_space_from_space(src_space);
// Creates n*axis <= data (equiv. to data - n*axis >= 0)
isl_constraint *tile_lower = isl_constraint_alloc_inequality(isl_local_space_copy(tile_local_space));
tile_lower = isl_constraint_set_coefficient_si(tile_lower, isl_dim_in, axis_dim, -n);
tile_lower = isl_constraint_set_coefficient_si(tile_lower, isl_dim_out, data_dim, 1);
// Creates n*axis + n > data (equiv. to n*axis + n - data - 1 >= 0)
isl_constraint *tile_upper = isl_constraint_alloc_inequality(tile_local_space);
tile_upper = isl_constraint_set_coefficient_si(tile_upper, isl_dim_in, axis_dim, n);
tile_upper = isl_constraint_set_coefficient_si(tile_upper, isl_dim_out, data_dim, -1);
tile_upper = isl_constraint_set_constant_si(tile_upper, n - 1);
// Combines the two above restrictions to creates the tiling restriction.
isl_basic_map *tile = isl_basic_map_from_constraint(tile_lower);
tile = isl_basic_map_add_constraint(tile, tile_upper);
// Returns the tiling restriction
return isl_map_from_basic_map(tile);
}
/**
* Creates an ISL set that expands the data data domain in a certain src to duplicate
* it over a certain axis.
*
* Read as: Replicate the feature n times along the given src axis axis_dim.
*
* @param feature __isl_take The binding feature to replicate.
* @param n __isl_keep The number of times to replicate the feature.
* @param axis_dim __isl_keep The axis index to replicate along (assumed to be
* an src axis index in the space of feature).
*/
isl_map *replicate(
isl_map *feature,
int n,
int axis_dim
) {
return nullptr;
}