sac2c issues
https://gitlab.sac-home.org/sac-group/sac2c/-/issues
2024-03-11T09:15:20Z
https://gitlab.sac-home.org/sac-group/sac2c/-/issues/2394
TCcountArgs internal compiler error
2024-03-11T09:15:20Z
Thomas Koopman
TCcountArgs internal compiler error
Following program fails with `Assertion "TCcountArgs (FUNDEF_ARGS (fundef)) == TYgetProductSize (arg_ts)" failed at /home/thomas/repos/sac2c/src/libsac2c/typecheck/specialize.c:321 -- UpdateFixSignature called with incompatible no of arg...
Following program fails with `Assertion "TCcountArgs (FUNDEF_ARGS (fundef)) == TYgetProductSize (arg_ts)" failed at /home/thomas/repos/sac2c/src/libsac2c/typecheck/specialize.c:321 -- UpdateFixSignature called with incompatible no of arguments!`
When removing the unused `softmax(float[m] x)`, the error does not occur, so probably something to do with function overloading.
```
use StdIO: all;
inline
float max(float a, float b)
{
return _ge_SxS_(a, b) ? a : b;
}
inline
float maximum(float[m] x)
{
return with {
([0] <= iv < [m]): _sel_VxA_(iv, x);
}: fold(max, _sel_VxA_([0], x));
}
inline
float[m] maximum(float[m, n] x)
{
return {iv -> _sel_VxA_([0], _sel_VxA_(iv, x))};
}
inline
float[m] softmax(float[m] x)
{
return x;
}
inline
float[m, n] softmax(float[m, n] x)
{
m = maximum(x);
print(_shape_A_(m));
return x;
}
int main()
{
m = 1000;
x = {iv -> 1f | iv < [m]};
StdIO::print(softmax(x));
return _toi_S_(_sel_VxA_([0], softmax(x)));
}
```
https://gitlab.sac-home.org/sac-group/sac2c/-/issues/2391
Non-negativity constraint for type patterns
2024-03-08T10:44:22Z
Jordy Aaldering
Non-negativity constraint for type patterns
```
foo(int[o:oshp,i:ishp] a, int o)
```
In this example we need to ensure that `o` is not negative.
I suspect this is currently not enforced, and probably something horrible happens if `o` is negative.
```
foo(int[o:oshp,i:ishp] a, int o)
```
In this example we need to ensure that `o` is not negative.
I suspect this is currently not enforced, and probably something horrible happens if `o` is negative.
Jordy Aaldering
Jordy Aaldering
https://gitlab.sac-home.org/sac-group/sac2c/-/issues/2381
Assertion "(actual_cls != C_scl) && (formal_cls != C_scl)" fails
2024-03-03T10:26:09Z
Thomas Koopman
Assertion "(actual_cls != C_scl) && (formal_cls != C_scl)" fails
Not so minimal example
```
use MathArray: all;
use Structures: all;
use StdIO: all;
#define CATEGORIES 10
#define TRAIN_SIZE 60000
inline
float[n:shpi] rsum(int m, float[m:shpo,n:shpi] x)
{
return {iv -> sum({jv -> x[jv++iv] | jv < ...
Not so minimal example
```
use MathArray: all;
use Structures: all;
use StdIO: all;
#define CATEGORIES 10
#define TRAIN_SIZE 60000
inline
float[n:shpi] rsum(int m, float[m:shpo,n:shpi] x)
{
return {iv -> sum({jv -> x[jv++iv] | jv < shpo}) | iv < shpi};
}
noinline
float[m:mshp,n:oshp,b:bshp] MultiConv(float[n:ishp,b:bshp] in,
float[m:mshp,n:wshp] weights,
float[m:mshp] bias)
| all(oshp == ishp - wshp + 1)
{
x = {iv -> Convolve(in, weights[iv]) + bias[iv] | iv < mshp};
print(shape(x));
return x;
}
noinline
float[n:oshp,b:bshp] Convolve(float[n:ishp,b:bshp] in, float[n:wshp] weights)
{
oshp = ishp - wshp + 1;
return {iv -> rsum(n, {jv -> weights[jv] * in[iv + jv]}) | iv < oshp};
}
inline
float average( float[*] array)
{
return sum( array) / tof( prod( shape( array)));
}
inline
float[*] AveragePool( float[*] in, int[.] filter)
//
// assert( dim(in) >= shape(filter)[0] )
// assert( shape(out) == shape(in)/filter )
//
{
ones = genarray( [dim( in)], 1);
filter = drop( shape( filter), ones) ++ filter;
shp = shape( in) / filter;
/*
* out = { iv -> average( { ov -> in[iv+ov] | ov < filter})
* | iv < shp};
*/
out = with {
(. <= iv <= .) : average( with {
(. <= ov <= .) : in[iv*filter+ov];
} : genarray( filter, 0f));
} : genarray( shp, 0f);
return out;
}
inline
float[*] BackAveragePool( float[*] d_out, int[.] filter )
{
ones = genarray( [dim( d_out)], 1);
filter = drop( shape( filter), ones) ++ filter;
shp = shape( d_out) * filter;
d_in = with {
(. <= iv <=.) : d_out[iv/filter] / tof( prod( filter));
} : genarray( shp, 0f);
return d_in;
}
inline
float[*] BackWeights2( float[*] d_out, float[*] weights, float[*] in)
{
return with {
( . <= ov <= .) :
with {
(0*shape( d_out) <= iv < shape( d_out)) : in[ iv+ov] * d_out[iv];
} : fold( +, 0f );
} : genarray( shape( weights), 0f);
}
float[*], float[*], float[*]
BackMultiConv( float[*] d_out, float[*] weights, float[*] in, float[*] bias)
{
shp_act_map = take( -[dim(in)], shape(weights));
shp_maps = drop( -[dim(in)], shape(weights));
d_in = with {
( . <= iv <= .) :
with {
(0*shp_maps <= ov < shp_maps) {
lb = max( 0*shp_act_map, iv - take( -[dim(in)], shape(d_out)) + 1);
ub = min( shp_act_map, iv+1 );
} : with {
( lb <= ov2 < ub) : weights[ov ++ ov2] * d_out[ov ++ (iv-ov2)];
} : fold( +, 0f);
} : fold( +, 0f);
} : genarray( shape(in), 0f);
d_weights = with {
(. <= iv <= .) : BackWeights2( d_out[iv], weights[iv], in);
} : genarray( shp_maps, genarray( take( -[dim(in)], shape(weights)), 0f));
d_bias = with {
(. <= iv <= .) : sum( d_out[iv]);
} : genarray( shp_maps, 0f);
return ( d_in, d_weights, d_bias);
}
inline
float[*] BackLogistic( float[*] d_out, float[*] out)
{
return d_out * out * (1f - out);
}
inline
float[6,5,5], float[6], float[12,6,5,5], float[12], float[CATEGORIES,12,1,4,4], float[CATEGORIES], float
TrainZhang( float[28,28] in, float[6,5,5] k1, float[6] b1,
float[12,6,5,5] k2, float[12] b2,
float[CATEGORIES,12,1,4,4] fc, float[CATEGORIES] b,
float[CATEGORIES,1,1,1,1] target)
{
float[6,24,24] c1, d_c1;
float[6,12,12] s1, d_s1;
float[12,1,8,8] c2, d_c2;
float[12,1,4,4] s2, d_s2;
float[CATEGORIES,1,1,1,1] out, d_out;
c1 = MultiConv( in, k1, b1 );
s1 = AveragePool( c1, [2,2]);
c2 = MultiConv( s1, k2, b2);
s2 = AveragePool( c2, [2,2]);
out = MultiConv( s2, fc, b);
d_out = out - target;
error = 0f;
d_s2, d_fc, d_b = BackMultiConv( BackLogistic( d_out, out), fc, s2, b);
d_c2 = BackAveragePool( d_s2, [2,2]);
d_s1, d_k2, d_b2 = BackMultiConv( BackLogistic( d_c2, c2), k2, s1, b2);
d_c1 = BackAveragePool( d_s1, [2,2]);
_, d_k1, d_b1 = BackMultiConv( BackLogistic( d_c1, c1), k1, in, b1);
return ( d_k1, d_b1, d_k2, d_b2, d_fc, d_b, error);
}
int main()
{
batchsize = 100;
k1 = genarray( [6,5,5], 1f/25f);
b1 = genarray( [6], 1f/6f);
k2 = genarray( [12,6,5,5], 1f/150f);
b2 = genarray( [12], 1f/12f);
fc = genarray( [CATEGORIES,12,1,4,4], 1f/192f);
b = genarray( [CATEGORIES], 1f/tof(CATEGORIES));
training_images = genarray([TRAIN_SIZE,28,28], 0f);
training_labels = genarray([TRAIN_SIZE], 3);
error = 0d;
delta_k1, delta_b1, delta_k2, delta_b2, delta_fc, delta_b, berr =
with {
([0] <= iv < [batchsize]) {
in = training_images[iv];
target = genarray([CATEGORIES,1,1,1,1], 0f);
target[[training_labels[iv],0,0,0,0]] = 1f;
d_k1, d_b1, d_k2, d_b2, d_fc, d_b, err =
TrainZhang(in, k1, b1, k2, b2, fc, b, target);
}: (d_k1, d_b1, d_k2, d_b2, d_fc, d_b, err);
}: (fold(+, 0f * k1),
fold(+, 0f * b1),
fold(+, 0f * k2),
fold(+, 0f * b2),
fold(+, 0f * fc),
fold(+, 0f * b),
fold(+, 0f));
k1 = k1 - delta_k1;
b1 = b1 - delta_b1;
k2 = k2 - delta_k2;
b2 = b2 - delta_b2;
fc = fc - delta_fc;
b = b - delta_b;
error += tod(berr);
print(k1);
return 0;
}
```
using
```
sac2c 1.3.3-MijasCosta-1153-g14eb
build-type: DEBUG
built-by: "thomas" at 2024-02-12T12:49:22
```
with `check -c`
https://gitlab.sac-home.org/sac-group/sac2c/-/issues/2380
check tc false positive
2024-02-14T10:10:58Z
Thomas Koopman
check tc false positive
The following program gives `Type pattern error in application of averageOuter: feature `d:shp' in return value does not match feature `shp' in arrayCompilation failed while Running SAC optimizations`. I think the program is correct howe...
The following program gives `Type pattern error in application of averageOuter: feature `d:shp' in return value does not match feature `shp' in arrayCompilation failed while Running SAC optimizations`. I think the program is correct however. It should average `batchsize` many copies of `k1`.
```
use Array: all;
inline
float[d:shp] averageOuter(float[n,d:shp] array)
{
return {iv -> sum({[i] -> array[[i]++iv] | [i] < [n]}) | iv < shp};
}
int main()
{
batchsize = 100;
k1 = with {}: genarray([6, 5, 5], 1f / 25f);
/* [batchsize, 6, 5, 5] */
bd_k1 = {iv -> k1 | iv < [batchsize]};
k1 = averageOuter(bd_k1);
return _toi_S_(_sel_VxA_([0, 0, 0], k1));
}
```
Compiled with arguments `-check tc`
```
sac2c 1.3.3-MijasCosta-1153-g14eb
build-type: DEBUG
built-by: "thomas" at 2024-02-12T12:49:22
```
https://gitlab.sac-home.org/sac-group/sac2c/-/issues/2379
sac2c crash with -doawlf
2024-02-12T18:25:55Z
Robert Bernecky
sac2c crash with -doawlf
Title says it all.
```
cat crud2.sac
use Array:{iota};
noinline
int[*] myReshape (int[.] shp, int[*] data)
{
return _reshape_VxA_(shp, data);
}
int main()
{ z = myReshape( [5], iota(5));
StdIO::show(z);
return(0);
}
apex@medu...
Title says it all.
```
cat crud2.sac
use Array:{iota};
noinline
int[*] myReshape (int[.] shp, int[*] data)
{
return _reshape_VxA_(shp, data);
}
int main()
{ z = myReshape( [5], iota(5));
StdIO::show(z);
return(0);
}
apex@medusa:/tmp$ sac2c crud2.sac -doawlf
Warning:
AWLF is enabled: -ecc enabled.
Warning:
AWLF is enabled: -extrema enabled.
Warning:
AWLF is enabled: -maxoptcyc=20
Internal compiler error
Assertion "res == NULL || NODE_TYPE (res) == N_array" failed at /home/sac/sac2c/src/libsac2c/arrayopt/with_loop_utilities.c:289 -- Array conversion failed!
Please file a bug at: https://gitlab.sac-home.org/sac-group/sac2c/-/issues
apex@medusa:/tmp$ sac2c -V
sac2c 1.3.3-MijasCosta-1149-g4237
build-type: RELEASE
built-by: "sac" at 2024-02-09T11:28:36
```
Sven-Bodo Scholz
Sven-Bodo Scholz
https://gitlab.sac-home.org/sac-group/sac2c/-/issues/2378
check c problem ICM undefined!
2024-02-10T17:06:10Z
Sven-Bodo Scholz
check c problem ICM undefined!
When compiling
```
noinline
int[*] myReshape (int[.] shp, int[*] data)
{
return _reshape_VxA_(shp, data);
}
int main() {
x = myReshape ([1], 42);
return _sel_VxA_([0], x);
}
```
with `sac2c -check c`
we get
```
** 22: Cr...
When compiling
```
noinline
int[*] myReshape (int[.] shp, int[*] data)
{
return _reshape_VxA_(shp, data);
}
int main() {
x = myReshape ([1], 42);
return _sel_VxA_([0], x);
}
```
with `sac2c -check c`
we get
```
** 22: Creating binary code ...
/Volumes/Users/sbs/Dropbox/BodoSac/ruben/a.out.c:1476:265: error: use of undeclared identifier '_ICM_IS_UNDEFINED_'
SAC_RuntimeWarningLoc ("./bug1.sac", 4, 12, "Arrays `" "SACp_emal_6042__idc_1216""' with shape %s ""And `" "SACl_data""' with shape %s ""do not adhere to prod matches prod shape constraint", SAC_PrintShape (SACp_emal_6042__idc_1216__desc), SAC_PrintShape (_ICM_IS_UNDEFINED_));
^
1 error generated.
```
One can also use `-noprelude` alongside....
Without `-check c` it compiles and runs fine.
When inlining it also runs fine.
Jordy Aaldering
Jordy Aaldering
https://gitlab.sac-home.org/sac-group/sac2c/-/issues/2377
Complexity problem in IVD
2024-02-11T10:13:20Z
Thomas Koopman
Complexity problem in IVD
IVD checks for each `N_spids` whether a variable declaration exists, inserting one if necessary. This search is a linear traversal of the list of variable declarations. If we have `n` variables without declaration, that means we check `s...
IVD checks for each `N_spids` whether a variable declaration exists, inserting one if necessary. This search is a linear traversal of the list of variable declarations. If we have `n` variables without declaration, that means we check `sum_{i = 1}^n i = n(n + 1)/2 \in O(n^2)` times. For the program below, the phase FLAT generates about 100K variables without declaration, leading to this phase taking about 20 minutes.
```
use Array: all;
use Math: all;
use StdIO: all;
#define CATEGORIES 10
inline
float[n:shpi] sumOuter(int m, float[m:shpo,n:shpi] x)
{
return {iv -> sum({jv -> x[jv++iv] | jv < shpo}) | iv < shpi};
}
inline
float[d:n1] slide(int[d] i, float[d:m] x, int[d] n) | all(n1 == n + 1)
| all(n + 1 + i <= m)
{
return {iv -> x[iv + i] | iv < n + 1};
}
inline
float[d:mn] backslide(int[d] i, float[d:n1] y, int[d] mn)
| all(i < 1 + mn - n1)
{
return {iv -> 0f | iv < i;
iv -> y[iv - i] | i <= iv < n1 + i;
iv -> 0f | n1 + i <= iv < mn};
}
inline
float[*] logistics(float[*] x)
{
return {iv -> 1f / (1f + exp(-x[iv]))};
}
inline
float[n:oshp,n:ishp] block(float[d:shp] x, int[n] ishp)
| all(shp % ishp == 0)
| all(oshp * ishp == shp)
| (2 * n == d)
{
return {iv -> tile(ishp, iv * ishp, x) | iv < shp / ishp};
}
/* TODO: type patterns */
inline
float[*] unblock(float[*] a, int[.] bshp)
{
shp = drop(-shape(bshp), shape(a)) * bshp;
return {iv -> a[(iv / bshp) ++ (iv % bshp)] | iv < shp};
}
inline
float[n:ishp] selb(float[d:shp] x, int[n] iv, int[n] ishp)
| (2 * n == d)
| all(iv < shp / ishp)
{
return block(x, ishp)[iv];
}
int main()
{
/* Variables */
inp = {[i, j] -> tof(i * j) | [i, j] < [28, 28]};
k1 = genarray( [6,5,5], 1f/25f);
b1 = genarray( [6], 1f/6f);
k2 = genarray( [12,6,5,5], 1f/150f);
b2 = genarray( [12], 1f/12f);
fc = genarray( [CATEGORIES,12,1,4,4], 1f/192f);
b = genarray( [CATEGORIES], 1f/tof(CATEGORIES));
/* Generated code with minor adjustments:
UTF8 -> ASCII
4 -> 4f (as SaC does not coerce types)
one -> 1f
backlide -> backslide
*/
/* Shape [6, 24, 24] */
c11 = { x16 -> (sumOuter(2, { x17 -> (slide(x17, inp, [23, 23])) * ({ x18 -> ((k1)[x16])[x17] | x18 < [24, 24] }) | x17 < [5, 5]})) + ({ x19 -> (b1)[x16] | x19 < [24, 24] }) | x16 < [6] };
printf("c11\n");
print(c11);
/* Shape [6, 24, 24] */
c1 = logistics(c11);
printf("c1\n");
print(c1);
/* Shape [6, 12, 12] */
s1 = { x13 -> { x14 -> (sumOuter(2, { x15 -> (selb((c1)[x13], x14, [2, 2]))[x15] | x15 < [2, 2]})) / 4f | x14 < [12, 12] } | x13 < [6] };
printf("s1\n");
print(s1);
/* Shape [12, 1, 8, 8] */
c21 = { x9 -> (sumOuter(3, { x10 -> (slide(x10, s1, [0, 7, 7])) * ({ x11 -> ((k2)[x9])[x10] | x11 < [1, 8, 8] }) | x10 < [6, 5, 5]})) + ({ x12 -> (b2)[x9] | x12 < [1, 8, 8] }) | x9 < [12] };
printf("c21\n");
print(c21);
/* Shape [12, 1, 8, 8] */
c2 = logistics(c21);
printf("c2\n");
print(c2);
/* Shape [12, 1, 4, 4] */
s2 = { x5 -> { x6 -> { x7 -> (sumOuter(2, { x8 -> (selb(((c2)[x5])[x6], x7, [2, 2]))[x8] | x8 < [2, 2]})) / 4f | x7 < [4, 4] } | x6 < [1] } | x5 < [12] };
printf("s2\n");
print(s2);
/* Shape [10, 1, 1, 1, 1] */
r1 = { x1 -> (sumOuter(4, { x2 -> (slide(x2, s2, [0, 0, 0, 0])) * ({ x3 -> ((fc)[x1])[x2] | x3 < [1, 1, 1, 1] }) | x2 < [12, 1, 4, 4]})) + ({ x4 -> (b)[x1] | x4 < [1, 1, 1, 1] }) | x1 < [10] };
printf("r1\n");
print(r1);
/* Shape [10, 1, 1, 1, 1] */
r = logistics(r1);
printf("r\n");
print(r);
ddr = 1f;
/* Shape [10, 1, 1, 1, 1] */
ddr1 = ddr * (r1 * (1f + -r1));
printf("ddr1\n");
print(ddr1);
/* Shape [12, 1, 4, 4] */
dds2 = sumOuter(1, { x1 -> sumOuter(4, { x2 -> backslide(x2, { x3 -> (((ddr1)[x1])[x3]) * (((fc)[x1])[x2]) | x3 < [1, 1, 1, 1] }, [12, 1, 4, 4]) | x2 < [12, 1, 4, 4]}) | x1 < [10]});
printf("dds2\n");
print(dds2);
/* Shape [12, 1, 8, 8] */
ddc2 = { x1 -> { x2 -> unblock({ x3 -> { x4 -> ((((dds2)[x1])[x2])[x3]) / 4f | x4 < [2, 2] } | x3 < [4, 4] }, [2, 2]) | x2 < [1] } | x1 < [12] };
printf("ddc2\n");
print(ddc2);
/* Shape [12, 1, 8, 8] */
ddc21 = ddc2 * (c21 * (1f + -c21));
printf("ddc21\n");
print(ddc21);
/* Shape [6, 12, 12] */
dds1 = sumOuter(1, { x1 -> sumOuter(3, { x2 -> backslide(x2, { x3 -> (((ddc21)[x1])[x3]) * (((k2)[x1])[x2]) | x3 < [1, 8, 8] }, [6, 12, 12]) | x2 < [6, 5, 5]}) | x1 < [12]});
printf("dds1\n");
print(dds1);
/* Shape [6, 24, 24] */
ddc1 = { x1 -> unblock({ x2 -> { x3 -> (((dds1)[x1])[x2]) / 4f | x3 < [2, 2] } | x2 < [12, 12] }, [2, 2]) | x1 < [6] };
printf("ddc1\n");
print(ddc1);
/* Shape [6, 24, 24] */
ddc11 = (ddc1) * (c11 * (1f + -c11));
printf("ddc11\n");
print(ddc11);
ddb = { x1 -> sumOuter(4, { x2 -> ((ddr1)[x1])[x2] | x2 < [1, 1, 1, 1]}) | x1 < [10] };
printf("ddb\n");
print(ddb);
ddfc = { x1 -> { x2 -> sumOuter(4, { x3 -> (((ddr1)[x1])[x3]) * ((slide(x2, s2, [0, 0, 0, 0]))[x3]) | x3 < [1, 1, 1, 1]}) | x2 < [12, 1, 4, 4] } | x1 < [10] };
printf("ddfc\n");
print(ddfc);
ddb2 = { x1 -> sumOuter(3, { x2 -> ((ddc21)[x1])[x2] | x2 < [1, 8, 8]}) | x1 < [12] };
printf("ddb2\n");
print(ddb2);
ddk2 = { x1 -> { x2 -> sumOuter(3, { x3 -> (((ddc21)[x1])[x3]) * ((slide(x2, s1, [0, 7, 7]))[x3]) | x3 < [1, 8, 8]}) | x2 < [6, 5, 5] } | x1 < [12] };
printf("ddk2\n");
print(ddk2);
ddb1 = { x1 -> sumOuter(2, { x2 -> ((ddc11)[x1])[x2] | x2 < [24, 24]}) | x1 < [6] };
printf("ddb1\n");
print(ddb1);
ddk1 = { x1 -> { x2 -> sumOuter(2, { x3 -> (((ddc11)[x1])[x3]) * ((slide(x2, inp, [23, 23]))[x3]) | x3 < [24, 24]}) | x2 < [5, 5] } | x1 < [6] };
printf("ddk1\n");
print(ddk1);
ddinp = sumOuter(1, { x1 -> sumOuter(2, { x2 -> backslide(x2, { x3 -> (((ddc11)[x1])[x3]) * (((k1)[x1])[x2]) | x3 < [24, 24] }, [28, 28]) | x2 < [5, 5]}) | x1 < [6]});
printf("ddinp\n");
print(ddinp);
return 0;
}
```
https://gitlab.sac-home.org/sac-group/sac2c/-/issues/2376
Guards are skipped by pattern matching
2024-02-22T07:21:30Z
Jordy Aaldering
Guards are skipped by pattern matching
In the following example, we would want a type pattern error.
```
int div (int x, int y) | _neq_SxS_ (y, 0)
{
return _div_SxS_ (x, y);
}
int main()
{
return div (4, 0);
}
```
However, pattern matching skips guards, instead res...
In the following example, we would want a type pattern error.
```
int div (int x, int y) | _neq_SxS_ (y, 0)
{
return _div_SxS_ (x, y);
}
int main()
{
return div (4, 0);
}
```
However, pattern matching skips guards, instead resulting in `SCSprf_div_XxS: Division by zero encountered`
We should not skip over guards, so that the error message(s) can be generated by type patterns instead.
Jordy Aaldering
Jordy Aaldering
https://gitlab.sac-home.org/sac-group/sac2c/-/issues/2375
-noINL and -check c lead to internal compiler error `Assertion "(actual_cls !...
2024-03-03T10:26:17Z
Sven-Bodo Scholz
-noINL and -check c lead to internal compiler error `Assertion "(actual_cls != C_scl) && (formal_cls != C_scl)" failed`
When compiling
```
use Array: all;
int[n:shp] myrotate ( int[n] rv, int[n:shp] a)
{
return { iv -> a[mod(iv - rv, shp)] | iv < shp};
}
int main ()
{
res = myrotate( [], 42);
return res;
}
```
with
`sac2c -noINL -check c` we...
When compiling
```
use Array: all;
int[n:shp] myrotate ( int[n] rv, int[n:shp] a)
{
return { iv -> a[mod(iv - rv, shp)] | iv < shp};
}
int main ()
{
res = myrotate( [], 42);
return res;
}
```
with
`sac2c -noINL -check c` we get
```
** 20: Preparing C code generation ...
Internal compiler error
Assertion "(actual_cls != C_scl) && (formal_cls != C_scl)" failed at /Volumes/Users/sbs/sac2c/src/libsac2c/precompile/typeconv_precompile.c:409 -- Conversion from or to scalar encountered!
Please file a bug at: https://gitlab.sac-home.org/sac-group/sac2c/-/issues
```
using
```
sac2c 1.3.3-MijasCosta-1154-gc82ba
build-type: RELEASE
built-by: "sbs" at 2024-02-05T10:48:28
```
Jordy Aaldering
Jordy Aaldering
https://gitlab.sac-home.org/sac-group/sac2c/-/issues/2374
Type patterns does incorrect dimension computation
2024-02-05T09:44:39Z
Thomas Koopman
Type patterns does incorrect dimension computation
```
sac2c 1.3.3-MijasCosta-1143-g21fdd4
build-type: DEBUG
built-by: "thomas" at 2024-01-30T10:37:51
```
Following program throws runtime error `*** Type pattern error in application of MultiConv: feature \`b:bshp' in return value does n...
```
sac2c 1.3.3-MijasCosta-1143-g21fdd4
build-type: DEBUG
built-by: "thomas" at 2024-01-30T10:37:51
```
Following program throws runtime error `*** Type pattern error in application of MultiConv: feature \`b:bshp' in return value does not match feature \`b' in in`
```
use StdIO: all;
use Array: all;
noinline
float[m:mshp,n:oshp,b:bshp] MultiConv(float[n:ishp,b:bshp] in,
float[m:mshp,n:wshp] weights,
float[m:mshp] bias)
| all(oshp == ishp - wshp + 1)
{
printf("m = %d, n = %d, b = %d\n", m, n, b);
x = {iv -> Convolve(in, weights[iv]) + bias[iv] | iv < mshp};
print(shape(x));
return x;
}
noinline
float[n:oshp,b:bshp] Convolve(float[n:ishp,b:bshp] in, float[n:wshp] weights)
{
oshp = ishp - wshp + 1;
// return {iv -> rsum(n, {jv -> weights[jv] * in[iv + jv]}) | iv < oshp};
return {iv -> sum({jv -> weights[jv] * in[iv + jv]}) | iv < oshp};
}
int main()
{
in = genarray([28, 28], 0f);
weights = genarray([6, 5, 5], 0f);
bias = genarray([6], 0f);
print(MultiConv(in, weights, bias));
return 0;
}
```
Generated guard shows
```
_rtpf_0_pred = ( _eq_SxS_( b, _sub_SxS_( _dim_A_( _rtpf_1_ret), _sub_SxS_( m, n))) ? _rtpf_0_pred : _guard_error_( _|_ /* Type pattern error in application of MultiConv: feature `b:bshp' in return value does not match feature `b' in in */) );
```
or in other words checks that `b == dim(out) - (m - n)` while it should be `b == dim(out) - (m + n)`.
Jordy Aaldering
Jordy Aaldering
https://gitlab.sac-home.org/sac-group/sac2c/-/issues/2373
UAR crashes when called in WL
2024-02-01T14:47:43Z
Sven-Bodo Scholz
UAR crashes when called in WL
Trying
```
noinline
int foo( int a, int b)
{ return a; }
int main()
{
return _sel_VxA_( [0], { [i] -> foo(i,i) | [i] < [10] });
}
```
crashes in code generation with
```
** 21: Generating Code ...
**** Tag preparation ...
****...
Trying
```
noinline
int foo( int a, int b)
{ return a; }
int main()
{
return _sel_VxA_( [0], { [i] -> foo(i,i) | [i] < [10] });
}
```
crashes in code generation with
```
** 21: Generating Code ...
**** Tag preparation ...
**** Creating intermediate code macros ...
TRAVERSE ERROR: node of type 0:undefined found where 58:N_avis was expected!
```
when using debug compiler -v4
Jordy Aaldering
Jordy Aaldering
https://gitlab.sac-home.org/sac-group/sac2c/-/issues/2372
WLMP crashes on sequence of WL nested inside another WL
2024-02-13T09:43:02Z
Sven-Bodo Scholz
WLMP crashes on sequence of WL nested inside another WL
The following example:
```
int main()
{
inpp = with {
([0] <= iv < [20] ) { i = with {
([0] <= jv < iv) : 42;
(iv <= jv < [10]) : 24;
...
The following example:
```
int main()
{
inpp = with {
([0] <= iv < [20] ) { i = with {
([0] <= jv < iv) : 42;
(iv <= jv < [10]) : 24;
} : genarray([10], 0); } : i;
} : genarray([20], [0,0,0,0,0,0,0,0,0,0]);
return _sel_VxA_([0, 0], inpp);
}
```
OOOPSES in WLMP.
With noSRP and no SOP, it works fine....
Sven-Bodo Scholz
Sven-Bodo Scholz
https://gitlab.sac-home.org/sac-group/sac2c/-/issues/2371
Assertion in WLUTfindArrayForBound fails
2024-01-30T16:02:43Z
Thomas Koopman
Assertion in WLUTfindArrayForBound fails
# sac2c version
```
sac2c 1.3.3-MijasCosta-1137-gcc26d
build-type: DEBUG
built-by: "thomas" at 2024-01-29T11:23:03
```
No flags. With `check tc` it does compile, and runs without errors!
# Program
```
inline
int[d:shp] -(int[d:shp] a...
# sac2c version
```
sac2c 1.3.3-MijasCosta-1137-gcc26d
build-type: DEBUG
built-by: "thomas" at 2024-01-29T11:23:03
```
No flags. With `check tc` it does compile, and runs without errors!
# Program
```
inline
int[d:shp] -(int[d:shp] a, int[d:shp] b)
{
return {iv -> _sub_SxS_(_sel_VxA_(iv, a),
_sel_VxA_(iv, b))};
}
inline
int[d:shp] +(int[d:shp] a, int[d:shp] b)
{
return {iv -> _add_SxS_(_sel_VxA_(iv, a),
_sel_VxA_(iv, b))};
}
inline
double[d:mn] backslide(int[d] i, double[d:n1] y, int[d] mn)
| all(i < 1 + mn - n1)
{
return {iv -> 0d | iv < i;
iv -> _sel_VxA_(iv - i, y) | i <= iv < n1 + i;
iv -> 0d | n1 + i <= iv < mn};
}
int main()
{
w = {iv -> 42d | iv < [5, 5]};
inpp = {[x1, x2] -> backslide([x1, x2], with {}: genarray([24, 24], 0d), [28, 28])
| [x1, x2] < [5, 5]};
return _toi_S_(_sel_VxA_([0, 0, 0, 0], inpp));
}
```
# error
```
Assertion "res == NULL || NODE_TYPE (res) == N_array" failed at /home/thomas/repos/sac2c/src/libsac2c/arrayopt/with_loop_utilities.c:289 -- Array conversion failed!
```
Thomas Koopman
Thomas Koopman
https://gitlab.sac-home.org/sac-group/sac2c/-/issues/2370
Tensor Comprehension with dot as upper bound crashes in Type Inference
2024-01-28T13:00:30Z
Thomas Koopman
Tensor Comprehension with dot as upper bound crashes in Type Inference
Compiler commit cc26dcec
The following program crashes at the type inference stage.
```
int +(int a, int b)
{
return _add_SxS_(a, b);
}
int +(int[*] a, int b)
{
return {iv -> _sel_VxA_(iv, a) + b};
}
/* double[m + n] backslide(i...
Compiler commit cc26dcec
The following program crashes at the type inference stage.
```
int +(int a, int b)
{
return _add_SxS_(a, b);
}
int +(int[*] a, int b)
{
return {iv -> _sel_VxA_(iv, a) + b};
}
/* double[m + n] backslide(int i, double[n + 1] x) | (i < m) */
#define backslide(i, x) \
{iv -> 0d | iv < [i]; \
iv -> _sel_VxA_([iv + i], x) | [i] <= iv < _shape_A_(x) + [i]; \
iv -> 0d | [_shape_A_(x) + i] <= iv < .}
int main()
{
double[11000] x; /* m + n is illegal */
n = 10000;
m = 1000;
n1 = n + 1;
y = with {}: genarray([m], 0d);
x = backslide(_div_SxS_(m, 2), y);
return 0;
}
```
Sven-Bodo Scholz
Sven-Bodo Scholz
https://gitlab.sac-home.org/sac-group/sac2c/-/issues/2369
Multi-operator fold loop puts accumulators in wrong order
2024-01-26T09:05:37Z
Thomas Koopman
Multi-operator fold loop puts accumulators in wrong order
# Compiler
```
sac2c 1.3.3-MijasCosta-1135-g4b472
build-type: DEBUG
built-by: "thomas" at 2024-01-24T13:04:00
```
No flags
# Test
The following program creates three constant arrays of length `1000` with values 1, 5, 13 respectively....
# Compiler
```
sac2c 1.3.3-MijasCosta-1135-g4b472
build-type: DEBUG
built-by: "thomas" at 2024-01-24T13:04:00
```
No flags
# Test
The following program creates three constant arrays of length `1000` with values 1, 5, 13 respectively. These are then summed with a multi-operator with-loop and the results are printed. It should print `1000, 5000, 13000`, but it prints `7000, 5000, 7000`.
```
#define N 1000
int add(int a, int b)
{
return _add_SxS_(a, b);
}
noinline
int, int, int sum(int[N] eren, int[N] mikasa, int[N] reiner)
{
eren_res, mikasa_res, reiner_res =
with {
([0] <= iv < [N]) {
eren_term = _sel_VxA_(iv, eren);
mikasa_term = _sel_VxA_(iv, mikasa);
reiner_term = _sel_VxA_(iv, reiner);
}: (eren_term, mikasa_term, reiner_term);
}: (fold(add, 0), fold(add, 0), fold(add, 0));
return (eren_res, mikasa_res, reiner_res);
}
int main()
{
eren = with {}: genarray([N], 1);
mikasa = with {}: genarray([N], 5);
reiner = with {}: genarray([N], 13);
eren_sum, mikasa_sum, reiner_sum = sum(eren, mikasa, reiner);
StdIO::printf("%d, %d, %d\n", eren_sum, mikasa_sum, reiner_sum);
return 0;
}
```
# Investigation
The optimized code looks as follows. We see that the accumulators `_ea_150_reiner_res, _ea_148_mikasa_res, _ea_146_eren_res` are in reverse order. This means that the first and third sum get alternating terms from the first and third arrays, which explains the `7000 = 1 * 1000 / 2 + 13 * 1000 / 2`.
```
int, int, int _MAIN::sum( int[1000] eren { ,NN } , int[1000] mikasa { ,NN } , int[1000] reiner { ,NN } )
/*
* sum :: ---
*/
{
int _ivesli_2673 { , NN } ;
int _ea_151_reiner_term { , NN } ;
int _ea_150_reiner_res { , NN } ;
int _ea_149_mikasa_term { , NN } ;
int _ea_148_mikasa_res { , NN } ;
int _ea_147_eren_term { , NN } ;
int _ea_146_eren_res { , NN } ;
int _eat_74 { , NN } ;
int reiner_res { , NN } ;
int mikasa_res { , NN } ;
int eren_res { , NN } ;
int reiner_term { , NN } ;
int mikasa_term { , NN } ;
int eren_term { , NN } ;
int[1] iv { , NN } ;
int{0} _flat_16 { , NN } ;
_flat_16 = 0;
eren_res, mikasa_res, reiner_res = with /** FOLDABLE (all gen's const) **/
/** REFERENCED: 3 (total num refs) **/
{
/* Partn */
([ 0 ] <= iv=[_eat_74] < [ 1000 ] genwidth [ 1000 ])
{
_ea_150_reiner_res, _ea_148_mikasa_res, _ea_146_eren_res = _accu_( iv, _flat_16, _flat_16, _flat_16);
_ivesli_2673 = _idxs2offset_( [ 1000 ], _eat_74);
eren_term = _idx_sel_( _ivesli_2673, eren);
mikasa_term = _idx_sel_( _ivesli_2673, mikasa);
reiner_term = _idx_sel_( _ivesli_2673, reiner);
_ea_151_reiner_term = _add_SxS_( _ea_150_reiner_res, reiner_term);
_ea_149_mikasa_term = _add_SxS_( _ea_148_mikasa_res, mikasa_term);
_ea_147_eren_term = _add_SxS_( _ea_146_eren_res, eren_term);
} : _ea_147_eren_term, _ea_149_mikasa_term, _ea_151_reiner_term ;
} :
fold( _MAIN::add(), _flat_16),
fold( _MAIN::add(), _flat_16),
fold( _MAIN::add(), _flat_16);
return( eren_res, mikasa_res, reiner_res);
}
```
Thomas Koopman
Thomas Koopman
https://gitlab.sac-home.org/sac-group/sac2c/-/issues/2367
Combine _afterguard_ and _guard_, and update guard insertion of ECC
2023-12-22T14:55:41Z
Jordy Aaldering
Combine _afterguard_ and _guard_, and update guard insertion of ECC
Conformity checks only have an afterguard, we want to combine this afterguard with guard so that we have a single primitive function, instead of having almost the same thing twice.
Additionally, similarly to type patterns, we want this ...
Conformity checks only have an afterguard, we want to combine this afterguard with guard so that we have a single primitive function, instead of having almost the same thing twice.
Additionally, similarly to type patterns, we want this guard to occur both before and after the conformity checked code so that we can keep the context in the future if we have better error messages.
Something like:
```
p1 = conformity check 1
...
pv = conformity check v
x1', .., xn' = guard (x, .., xn, p1, .., pv, "context");
res1, .., resm = _prf_ (x1', .., xn');
res1', .., resm' = guard (res1, .., resm, p1, .., pv, "context");
```
Jordy Aaldering
Jordy Aaldering
https://gitlab.sac-home.org/sac-group/sac2c/-/issues/2365
scanner parser erroneous warning about type pattern in class / typedef
2023-12-13T12:15:47Z
Sven-Bodo Scholz
scanner parser erroneous warning about type pattern in class / typedef
With the latest compiler
```
sac2c -V
sac2c 1.3.3-MijasCosta-1125-g8ae1e
build-type: RELEASE
built-by: "sbs" at 2023-12-08T19:40:06
```
the following class:
```
class error;
classtype int[1];
```
triggers the following warning:
```
-sb...
With the latest compiler
```
sac2c -V
sac2c 1.3.3-MijasCosta-1125-g8ae1e
build-type: RELEASE
built-by: "sbs" at 2023-12-08T19:40:06
```
the following class:
```
class error;
classtype int[1];
```
triggers the following warning:
```
-sbs-n142230-> sac2c error.sac
error.sac:1:1: warning:
Type patterns are currently not supported for type definitions. Ignoring all type variables.
```
Jordy Aaldering
Jordy Aaldering
https://gitlab.sac-home.org/sac-group/sac2c/-/issues/2364
Conformity checks should be generated for type pattern code
2023-12-15T11:04:17Z
Jordy Aaldering
Conformity checks should be generated for type pattern code
Insertion of conformity checks was disabled for the generated type pattern code, this should be enabled again.
Insertion of conformity checks was disabled for the generated type pattern code, this should be enabled again.
Jordy Aaldering
Jordy Aaldering
https://gitlab.sac-home.org/sac-group/sac2c/-/issues/2363
Guard in type checker should create bottom types instead of aborting
2023-12-22T14:55:41Z
Jordy Aaldering
Guard in type checker should create bottom types instead of aborting
Jordy Aaldering
Jordy Aaldering
https://gitlab.sac-home.org/sac-group/sac2c/-/issues/2362
Type pattern guard function should include argument types
2024-01-27T06:36:18Z
Jordy Aaldering
Type pattern guard function should include argument types
Instead of a guard:
```
x1', .., xn' = guard(x1, .., xn, pred);
```
We want to include the type `ti` for each argument `xi`:
```
x1', .., xn' = guard(x1, .., xn, t1, .., tn, pred);
```
Instead of a guard:
```
x1', .., xn' = guard(x1, .., xn, pred);
```
We want to include the type `ti` for each argument `xi`:
```
x1', .., xn' = guard(x1, .., xn, t1, .., tn, pred);
```
Jordy Aaldering
Jordy Aaldering