Commit dccfebef authored by Brice Videau's avatar Brice Videau
Browse files

Use column api for copy operators and better checks of compatibility.

parent ea73d4fe
Pipeline #6663 passed with stage
in 12 minutes and 6 seconds
......@@ -535,8 +535,9 @@ static inline void aml_copy_layout_generic_helper(size_t d,
for (size_t i = 0; i < elem_number[0]; i += 1) {
coords[0] = i;
coords[0] = i;
memcpy(aml_layout_aderef(dst, coords),
aml_layout_aderef(src, coords), elem_size);
memcpy(aml_layout_aderef_column(dst, coords),
aml_layout_aderef_column(src, coords),
elem_size);
} else
for (size_t i = 0; i < elem_number[d - 1]; i += 1) {
coords[d - 1] = i;
......@@ -564,8 +565,9 @@ static inline void aml_copy_layout_transform_generic_helper(size_t d,
for (size_t i = 0; i < elem_number[target_dims[0]]; i += 1) {
coords_out[0] = i;
coords[target_dims[0]] = i;
memcpy(aml_layout_aderef(dst, coords_out),
aml_layout_aderef(src, coords), elem_size);
memcpy(aml_layout_aderef_column(dst, coords_out),
aml_layout_aderef_column(src, coords),
elem_size);
} else
for (size_t i = 0; i < elem_number[target_dims[d - 1]]; i += 1) {
coords_out[d - 1] = i;
......@@ -587,13 +589,18 @@ int aml_copy_layout_generic(struct aml_layout *dst,
size_t elem_size;
size_t *coords;
size_t *elem_number;
size_t *elem_number2;
assert(aml_layout_ndims(dst) == aml_layout_ndims(src));
d = aml_layout_ndims(dst);
assert(aml_layout_element_size(dst) == aml_layout_element_size(src));
elem_size = aml_layout_element_size(dst);
coords = (size_t *) alloca(d * sizeof(size_t));
elem_number = (size_t *) alloca(d * sizeof(size_t));
aml_layout_adims(src, elem_number);
elem_number2 = (size_t *) alloca(d * sizeof(size_t));
aml_layout_adims_column(src, elem_number);
aml_layout_adims_column(dst, elem_number2);
for (size_t i = 0; i < d; i += 1)
assert(elem_number[i] == elem_number2[i]);
aml_copy_layout_generic_helper(d, dst, src, elem_number, elem_size,
coords);
return 0;
......@@ -608,6 +615,7 @@ int aml_copy_layout_transform_generic(struct aml_layout *dst,
size_t *coords;
size_t *coords_out;
size_t *elem_number;
size_t *elem_number2;
assert(aml_layout_ndims(dst) == aml_layout_ndims(src));
d = aml_layout_ndims(dst);
assert(aml_layout_element_size(dst) == aml_layout_element_size(src));
......@@ -615,7 +623,11 @@ int aml_copy_layout_transform_generic(struct aml_layout *dst,
coords = (size_t *) alloca(d * sizeof(size_t));
coords_out = (size_t *) alloca(d * sizeof(size_t));
elem_number = (size_t *) alloca(d * sizeof(size_t));
aml_layout_adims(src, elem_number);
elem_number2 = (size_t *) alloca(d * sizeof(size_t));
aml_layout_adims_column(src, elem_number);
aml_layout_adims_column(dst, elem_number2);
for (size_t i = 0; i < d; i += 1)
assert(elem_number[target_dims[i]] == elem_number2[i]);
aml_copy_layout_transform_generic_helper(d, dst, src, elem_number,
elem_size, coords, coords_out,
target_dims);
......
......@@ -399,7 +399,7 @@ def aml_copy_layout_generic_helper(shuffle: false)
pr For( i, 0, elem_number[elem_index[0]], operator: '<', declit: true ) {
pr coord_dst[dst_index[0]] === i
pr coord_src[src_index[0]] === i
pr memcpy( FuncCall(:aml_layout_aderef, dst, coord_dst), FuncCall(:aml_layout_aderef, src, coord_src), elem_size )
pr memcpy( FuncCall(:aml_layout_aderef_column, dst, coord_dst), FuncCall(:aml_layout_aderef_column, src, coord_src), elem_size )
}
}, else: lambda {
pr For( i, 0, elem_number[elem_index[d - 1]], operator: '<', declit: true ) {
......@@ -465,9 +465,11 @@ def aml_copy_layout(native: true, shuffle: false)
coords = Sizet :coords, dim: Dim()
coords_out = Sizet :coords_out, dim: Dim()
elem_number = Sizet :elem_number, dim: Dim()
elem_number2 = Sizet :elem_number2, dim: Dim()
decl coords
decl coords_out if shuffle
decl elem_number
decl elem_number2
pr assert( FuncCall( :aml_layout_ndims, dst ) == FuncCall( :aml_layout_ndims, src ) )
pr d === FuncCall( :aml_layout_ndims, dst )
......@@ -476,7 +478,12 @@ def aml_copy_layout(native: true, shuffle: false)
pr coords === alloca(d * sizeof("size_t")).cast(coords)
pr coords_out === alloca(d * sizeof("size_t")).cast(coords_out) if shuffle
pr elem_number === alloca(d * sizeof("size_t")).cast(elem_number)
pr FuncCall( :aml_layout_adims, src, elem_number )
pr elem_number2 === alloca(d * sizeof("size_t")).cast(elem_number2)
pr FuncCall( :aml_layout_adims_column, src, elem_number )
pr FuncCall( :aml_layout_adims_column, dst, elem_number2 )
pr For(i, 0, d, operator: '<', declit: true) {
pr assert( "#{elem_number}[#{src_index[i]}] == #{elem_number2}[#{dst_index[i]}]" )
}
new_args = [d, dst, src, elem_number, elem_size, coords]
new_args << coords_out << target_dims if shuffle
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment