Skip to content

Commit

Permalink
* Add demonstrators for 4 code generation scenarios:
Browse files Browse the repository at this point in the history
    * a : Program initialization :https://HybroLangDemos/Newton-SquareRoot-VariablePrecision/Newton.hl
    * b : Kernel initialization : https://CodeExamples/Array-Mult-Specialization.hl
    * c : Applicaiton controlled : https://HybroLangDemos/Newton-SquareRoot-VariablePrecision/Newton.hl
	* d : Heterogeneous target : https://HybroLangDemos/ImagePixelSum/CxRAM-ImagePixelAccumulation.hl

* Correct minor bugs (mul on cxram)
  • Loading branch information
Henri-Pierre CHARLES authored and Henri-Pierre CHARLES committed May 22, 2023
1 parent 60e3654 commit a056def
Show file tree
Hide file tree
Showing 22 changed files with 380 additions and 71 deletions.
19 changes: 15 additions & 4 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
2023-04-19 Henri-Pierre CHARLES HC227932 <hc227932@gre056290.intra.cea.fr>
2023-05-22 Henri-Pierre CHARLES HC227932 <Henri-Pierre.Charles@cea.fr>

* Add demonstrators for 4 code generation scenarios
* a : Program initialization :
https://HybroLangDemos/Newton-SquareRoot-VariablePrecision/Newton.hl
* b : Kernel initialization :
https://CodeExamples/Array-Mult-Specialization.hl
* c : Applicaiton controlled :
https://HybroLangDemos/Newton-SquareRoot-VariablePrecision/Newton.hl
* d : Heterogeneous target : https://HybroLangDemos/ImagePixelSum/CxRAM-ImagePixelAccumulation.hl

* Correct minor bugs (mul on cxram)

2023-04-19 Henri-Pierre CHARLES HC227932 <Henri-Pierre.Charles@cea.fr>

* Release 3.0: Target platforms risc-v, power, aarch64, cxram
* More complex demonstrations
* Sync with release 1.0 of https://github.com/CEA-LIST/csram-qemu-plugin


2022-07-14 Henri-Pierre Charles <hc227932@gre061041>
2022-07-14 Henri-Pierre Charles <hc227932@gre056290.intra.cea.fr>

* Target platforms : partial part of the ISA of RISCV, Power,
Kalray, CxRAM platforms

* Release 2.0: First public release


86 changes: 86 additions & 0 deletions CodeExamples/Array-Mult-Specialization.hl
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// -*- c -*-
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

typedef int (*pifi)(int *, int);


h2_insn_t * genMulArray(h2_insn_t * ptr, int b)
{
#[
int 32 1 mult (int[] 32 1 a, int 32 1 len)
{
int 32 1 r, i;
for (i = 0; i < len; i = i + 1)
{
a[i] = a[i] * #(b); // b values will be included in code generation
}
}
]#
return (h2_insn_t *) ptr;
}

void printArray(int * array, int len)
{
printf ("Array values (%d) : ", len);
for (int i = 0; i < len; i++)
printf ("%d ", array[i]);
printf ("\n");
}

void mulArray(int * array, int len, int value)
{
for (int i = 0; i < len; i++)
array[i] = array[i] * value;
}

int main(int argc, char * argv[])
{

h2_insn_t * ptr;
int arrayLen, mulValue, i, resultOK;
pifi fPtr;
int *array1, *array2;
clock_t startC, stopC, startHg, stopHg;

if (argc < 3)
{
printf("Give 2 values (array len & mult. coefficient )\n");
exit(-1);
}
arrayLen = atoi (argv[1]); // Get the
mulValue = atoi (argv[2]);
array1 = calloc (arrayLen, sizeof (int));
array2 = calloc (arrayLen, sizeof (int));
for (i = 0; i < arrayLen; i++)
{
array1[i] = random () % 100;
array2[i] = array1[i];
}
printArray (array1, arrayLen);
printf("// Multiply an array with a constant value\n");
printf("// Array len = %d\n", arrayLen);
printf("// Code specialization on value = %d\n", mulValue);
ptr = h2_malloc (1024); // Allocate memory for 1024 instructions
fPtr = (pifi) genMulArray (ptr, mulValue);
startHg = clock();
fPtr(array1, arrayLen); // Call generated code
stopHg = clock();
printArray (array1, arrayLen);
resultOK = 0;
startC = clock();
mulArray (array2, arrayLen, mulValue);
stopC = clock();
printf ("C version %ld Hg version %ld\n\n", stopC - startC, stopHg - startHg);
for (int i = 0; i < arrayLen; i++)
{
if (array2[i] != array1[i])
{
printf("Erreur multiplication!\n");
resultOK = -1;
break;
}
}
return resultOK;
}
5 changes: 3 additions & 2 deletions CodeExamples/CelciusFarenheit.hl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ h2_insn_t * genF2C(h2_insn_t * ptr)
int 32 1 F2C (int 32 1 a)
{
int 32 1 r;
r = a - 32 * 5 / 9;
r = a - 32;
r = r * 5 / 9;
return r;
}
]#
Expand Down Expand Up @@ -56,7 +57,7 @@ int main(int argc, char * argv[])
fF2C = (pifi) genF2C (ptr); //
res = fF2C(in0); // Call generated code
printf("%d (farenheit) -> (celcius)%d\n", in0, res);
if (res != (in0 - 32 * 5 / 9))
if (res != ((in0 - 32) * 5 / 9))
resultOK += 1;

if (resultOK == 0)
Expand Down
7 changes: 3 additions & 4 deletions CodeExamples/CxRAM-SimpleAdd16.hl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void printVec(h2_cxram_line_t * vectorLine, int len, char * mesg)

int main(int argc, char * argv[])
{
int i, resultOK;
int i;
h2_insn_t * ptr;
pifiii code;
h2_cxram_line_t *in1, *in2, *res;
Expand All @@ -57,11 +57,10 @@ int main(int argc, char * argv[])
printVec (in1, CXRAM_VECLEN/2, " ");
printVec (in2, CXRAM_VECLEN/2, "+");
printVec (res, CXRAM_VECLEN/2, "=");
resultOK = 0;
for (i=0; i < CXRAM_VECLEN / sizeof(in1->i16[0]); i++)
{
if (res->i16[i] != (in1->i16[i] + in2->i16[i]))
resultOK = 1;
return 1;
}
return resultOK;
return 0;
}
13 changes: 6 additions & 7 deletions CodeExamples/CxRAM-SimpleAdd32.hl
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void printVec(int * vectorLine, int len, char * mesg)
int main(int argc, char * argv[])
{
#define VECLEN 4
int i, resultOK;
int i;
pifiii code;
#ifdef CXRAM
h2_cxram_line_t *in1, *in2, *res;
Expand Down Expand Up @@ -66,24 +66,23 @@ int main(int argc, char * argv[])
in1[i] = atoi(argv[i+1]);
in2[i] = 542;
res[i] = 0;
#endif
#endif
}
ptr = h2_malloc (1024);
code = genAddImages(ptr);
code (in1, in2, res);
printVec (in1, VECLEN/4, " ");
printVec (in2, VECLEN/4, "+");
printVec (res, VECLEN/4, "=");
resultOK = 0;
for (i=0; i < VECLEN / sizeof(in1[0]); i++)
for (i=0; i < VECLEN; i++)
{
#ifdef CXRAM
if (res->i32[i] != (in1->i32[i] + in2->i32[i]))
resultOK = 1;
return 1;
#else
if (res[i] != (in1[i] + in2[i]))
resultOK = 1;
return 1;
#endif
}
return resultOK;
return 0;
}
9 changes: 4 additions & 5 deletions CodeExamples/CxRAM-SimpleAdd8.hl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void printVec(h2_cxram_line_t * vectorLine, int len, char * mesg)

int main(int argc, char * argv[])
{
int i, resultOK;
int i;
h2_insn_t * ptr;
pifiii code;
h2_cxram_line_t *in1, *in2, *res;
Expand All @@ -56,11 +56,10 @@ int main(int argc, char * argv[])
printVec (in1, CXRAM_VECLEN, " ");
printVec (in2, CXRAM_VECLEN, "+");
printVec (res, CXRAM_VECLEN, "=");
resultOK = 0;
for (i=0; i < CXRAM_VECLEN / sizeof(in1[0]); i++)
for (i=0; i < CXRAM_VECLEN / sizeof(in1->i8[0]); i++)
{
if (res->i8[i] != (in1->i8[i] + in2->i8[i]))
resultOK = 1;
return 1;
}
return resultOK;
return 0;
}
10 changes: 5 additions & 5 deletions CodeExamples/CxRAM-SimpleAnd.hl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void printVec(h2_cxram_line_t * vectorLine, int len, char * mesg)

int main(int argc, char * argv[])
{
int i, resultOK;
int i;
h2_insn_t * ptr;
pifiii code;
h2_cxram_line_t *in1, *in2, *res;
Expand All @@ -56,11 +56,11 @@ int main(int argc, char * argv[])
printVec (in1, CXRAM_VECLEN, " ");
printVec (in2, CXRAM_VECLEN, "&");
printVec (res, CXRAM_VECLEN, "=");
resultOK = 0;
for (i=0; i < CXRAM_VECLEN / sizeof(in1[0]); i++)
for (i=0; i < CXRAM_VECLEN / sizeof(in1->i8[0]); i++)
{
if (res->i8[i] != (in1->i8[i] & in2->i8[i]))
resultOK = 1;
return 1;
}
return resultOK;
printf ("\n");
return 0;
}
7 changes: 3 additions & 4 deletions CodeExamples/CxRAM-SimpleMul16.hl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void printVec(h2_cxram_line_t *vectorLine, int len, char * mesg)

int main(int argc, char * argv[])
{
int i, resultOK;
int i;
h2_insn_t * ptr;
pifiii code;
h2_cxram_line_t *in1, *in2, *res;
Expand Down Expand Up @@ -60,11 +60,10 @@ int main(int argc, char * argv[])
printVec (in2, CXRAM_VECLEN/2, "*");
printVec (res, CXRAM_VECLEN/2, "=");
#endif
resultOK = 0;
for (i=0; i < CXRAM_VECLEN / sizeof(in1->i16[0]); i++)
{
if (res->i16[i] != (in1->i16[i] * in2->i16[i]))
resultOK = 1;
return 1;
}
return resultOK;
return 0;
}
7 changes: 3 additions & 4 deletions CodeExamples/CxRAM-SimpleMul32.hl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void printVec(h2_cxram_line_t *vectorLine, int len, char * mesg)

int main(int argc, char * argv[])
{
int i, resultOK;
int i;
h2_insn_t * ptr;
pifiii code;
h2_cxram_line_t *in1, *in2, *res;
Expand Down Expand Up @@ -60,11 +60,10 @@ int main(int argc, char * argv[])
printVec (in2, CXRAM_VECLEN/4, "*");
printVec (res, CXRAM_VECLEN/4, "=");
#endif
resultOK = 0;
for (i=0; i < CXRAM_VECLEN / sizeof(in1->i32[0]); i++)
{
if (res->i32[i] != (in1->i32[i] * in2->i32[i]))
resultOK = 1;
return 1;
}
return resultOK;
return 0;
}
7 changes: 3 additions & 4 deletions CodeExamples/CxRAM-SimpleMul8.hl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void printVec(h2_cxram_line_t *vectorLine, int len, char * mesg)

int main(int argc, char * argv[])
{
int i, resultOK;
int i;
h2_insn_t * ptr;
pifiii code;
h2_cxram_line_t *in1, *in2, *res;
Expand Down Expand Up @@ -60,11 +60,10 @@ int main(int argc, char * argv[])
printVec (in2, CXRAM_VECLEN, "*");
printVec (res, CXRAM_VECLEN, "=");
#endif
resultOK = 0;
for (i=0; i < CXRAM_VECLEN / sizeof(in1->i8[0]); i++)
{
if (res->i8[i] != (in1->i8[i] * in2->i8[i]))
resultOK = 1;
return 1;
}
return resultOK;
return 0;
}
7 changes: 3 additions & 4 deletions CodeExamples/CxRAM-SimpleSub8.hl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void printVec(int8_t *vectorLine, int len, char * mesg)

int main(int argc, char * argv[])
{
int i, resultOK;
int i;
h2_insn_t * ptr;
pifiii code;
int8_t *in1, *in2, *res;
Expand Down Expand Up @@ -60,15 +60,14 @@ int main(int argc, char * argv[])
printVec (in2, CXRAM_VECLEN, "-");
printVec (res, CXRAM_VECLEN, "=");
#endif
resultOK = 0;
for (i=0; i < CXRAM_VECLEN / sizeof(in1[0]); i++)
{
int tmp = in1[i] - in2[i];
int resultat = tmp; // La soustraction est signée (tmp < 0)?0:tmp;
if (res[i] != resultat)
{
resultOK = -1;
return 1;
}
}
return resultOK;
return 0;
}
4 changes: 2 additions & 2 deletions CodeExamples/Regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ def cmd(cmdAndArgs, Verbose, doPrint = True, wdir = None, doExec = True):
"CxRAM-ImageDiff",
"CxRAM-ImagePixelAccumulation",
"CxRAM-Broadcast32",
"CxRAM-Convolution8",
"CxRAM-Convolution16",
# "CxRAM-Convolution8", # Convolution8 & 16 are not bit compatible
# "CxRAM-Convolution16", # thus can not be used as regression test
"CxRAM-Convolution32",
"CxRAM-MatrixMultiplication"
)
Expand Down
Loading

0 comments on commit a056def

Please sign in to comment.