Skip to content

Commit

Permalink
Add forgotten file & improve README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Henri-Pierre CHARLES authored and Henri-Pierre CHARLES committed Dec 5, 2023
1 parent 7025b8b commit 653c6a6
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 39 deletions.
6 changes: 2 additions & 4 deletions CodeExamples/Array-Mult-Specialization.hl
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
#include <time.h>

typedef int (*pifi)(int *);


h2_insn_t * genMulArray(h2_insn_t * ptr, int b, int len)
pifi genMulArray(pifi ptr, int b, int len)
{
#[
int 32 1 mult (int[] 32 1 a)
Expand All @@ -19,7 +17,7 @@ h2_insn_t * genMulArray(h2_insn_t * ptr, int b, int len)
}
}
]#
return (h2_insn_t *) ptr;
return ptr;
}

void printArray(int * array, int len)
Expand Down
69 changes: 69 additions & 0 deletions CodeExamples/Loop-in-If.hl
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// -*- c -*-
#include <stdio.h>
#include <stdlib.h>

typedef int (*pifii)(int, int);

/* C compilette prototype */
h2_insn_t * genPlusOrMul(h2_insn_t * ptr)
{
#[
int 32 1 PlusOrMul(int 32 1 plus, int 32 1 LoopValue)
{
int 32 1 tmp, i, reste;

tmp = 1; // 1 = loop with addition, multiplication otherwise
if (plus == tmp)
{
tmp = 1;
for (i = 1; i <= LoopValue; i = i + 1)
{
tmp = tmp * i;
}
}
else
{
tmp = 0;
for (i = 1; i <= LoopValue; i = i + 1)
{
tmp = tmp + i;
}

}
return tmp;
}
]#
return (h2_insn_t *)ptr;
}


int main(int argc, char * argv[])
{
h2_insn_t * ptr;
int plus, loopValue, res;
int i, tmp;
pifii iPtr;

if (argc < 2)
{
printf("Give 2 values (Plus LoopValue)\n");
exit(-1);
}
plus = atoi (argv[1]); // Get operator + = 1, other = *
loopValue = atoi (argv[2]); // Get threshold value
ptr = h2_malloc (1024); // Allocate memory for 1024 instructions
iPtr = (pifii) genPlusOrMul(ptr); // Generate instructions
res = iPtr(plus, loopValue); // Call generated code
if (plus == 1)
for (tmp = 1, i = 1; i <= loopValue; i = i + 1)
{
tmp *= i;
}
else
for (tmp = 0, i = 1; i <= loopValue; i = i + 1)
{
tmp += i;
}
printf ("Result plus = %d, loopValue %d : %d (%d)\n", plus, loopValue, res, tmp);
return tmp != res;
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ int FarenheitToCelcius(int farenheit)

typedef int (*pifi)(int);

h2_insn_t * genC2F(h2_insn_t * ptr)
pifi genC2F(pifi ptr)
{
#[
int 32 1 C2F (int 32 1 a)
Expand All @@ -29,10 +29,10 @@ h2_insn_t * genC2F(h2_insn_t * ptr)
return r;
}
]#
return (h2_insn_t *) ptr;
return ptr;
}

h2_insn_t * genF2C(h2_insn_t * ptr)
pifi genF2C(pifi ptr)
{
#[
int 32 1 F2C (int 32 1 a)
Expand All @@ -43,7 +43,7 @@ h2_insn_t * genF2C(h2_insn_t * ptr)
return r;
}
]#
return (h2_insn_t *) ptr;
return ptr;
}

typedef int arrayTemp_t[3][13];
Expand Down Expand Up @@ -75,7 +75,7 @@ int main(int argc, char * argv[])
for (i = 0; i < 8; i ++)
tempArray[0][i] = 5*i;
startCg1 = h2_getticks();
fC2F = (pifi) genC2F(h2_malloc (1024)); // Allocate memory for binary code
fC2F = genC2F(h2_malloc (1024)); // Allocate memory for binary code
stopCg1 = h2_getticks();
startC = h2_getticks();
for (i = 0; i < 8; i ++)
Expand All @@ -92,7 +92,7 @@ int main(int argc, char * argv[])
for (i = 0; i < 13; i ++)
tempArray[0][i] = 35 + 5*i;
startCg2 = h2_getticks();
fF2C = (pifi) genF2C(h2_malloc (1024)); // and generate binary codes
fF2C = genF2C(h2_malloc (1024)); // and generate binary codes
stopCg2 = h2_getticks();
startC = h2_getticks();
for (i = 0; i < 13; i ++)
Expand Down
20 changes: 10 additions & 10 deletions HybroLangDemos/ImagePixelSum/CxRAM-ImagePixelAccumulation.hl
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,24 @@
#include <string.h>
#include "ReadPgmImage.h"

typedef void (*pifiii)(h2_cxram_line_t *, h2_cxram_line_t *);
#define MIN(a,b) (((a)<(b))?(a):(b))

// Compute the sum of the image cxram lines, accumulate the result in partialSum
typedef void (*pifiii)(h2_cxram_line_t *, h2_cxram_line_t *);
pifiii genSumReduction(h2_insn_t * ptr, int totalLine)
{
#[
int 32 1 sumImage(int[] 16 8 partialSum, int[] 16 8 image)
{
int 32 1 lineNumber;
partialSum[0] = 0;
for (lineNumber = 0; lineNumber < #(totalLine); lineNumber = lineNumber + 1)
{
partialSum[0] = partialSum[0] + image[lineNumber];
}
}
{
int 32 1 lineNumber;
partialSum[0] = 0;
for (lineNumber = 0; lineNumber < #(totalLine); lineNumber = lineNumber + 1)
{
partialSum[0] = partialSum[0] + image[lineNumber];
}
}
]#
return (pifiii) ptr;
return (pifiii) ptr;
}

int main(int argc, char * argv[])
Expand Down
10 changes: 5 additions & 5 deletions HybroLangDemos/Newton-SquareRoot-VariablePrecision/Newton.hl
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
#include <stdio.h>
#include <stdlib.h>

typedef float (*piff)(float, float, float);
typedef double (*pidd)(double, double, double);

#define True 1
#define False 0
#define FLOAT 32
#define DOUBLE 64


typedef float (*piff)(float, float, float);
typedef double (*pidd)(double, double, double);
/* Newton square root demonstration with variable precision */
h2_insn_t * genIterate(h2_insn_t * ptr, int FloatWidth)
{
Expand Down Expand Up @@ -45,7 +45,7 @@ int main(int argc, char **argv)
iterationNumber = 0;
af = atof (argv[1]);
precd = atof (argv[2]);
precf = precd * 1.e14;
precf = 1; // precd * 1.e14;
ptr = h2_malloc (1024);
isFloat = True;
printf ("Compute square root of %f\n", af);
Expand All @@ -69,6 +69,6 @@ int main(int argc, char **argv)
iterationNumber++,
isFloat?"float ":"double",
next, isFloat?precf:precd);
} while ( isFloat || (!isFloat && (diff > precd)));
} while ( diff > precd);
return 0;
}
13 changes: 8 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,29 @@ all:
echo "make buildGrammar # Build grammars (need antlr)"
echo "make DbPopulate # "

# Uncomment if you whish to use distant database
# DBIDS = --dbIds "DistantHost:DataBaseName:UserDbName:DbPassword"

DbPopulate:
make buildGrammar
./H2Isa.py -n # Create database schema
./H2Isa.py -n ${DBIDS} # Create database schema
make DbArch ARCH=aarch64
make DbArch ARCH=riscv
make DbArch ARCH=kalray
make DbArch ARCH=power
./H2Isa.py -i -a cxram # No register description for cxram
./H2Isa.py -i -a cxram ${DBIDS} # No register description for cxram
echo "Need to generate environment ?\nExample : ./GenCrossTools.py -s -a cxram-linux -a powerpc\n"

DbArch:
./H2Isa.py -i -a ${ARCH}; ./H2Reg.py -i -a ${ARCH}
./H2Isa.py -i -a ${ARCH} ${DBIDS} # ISA description database insertion
./H2Reg.py -i -a ${ARCH} ${DBIDS} # Register description database insertion

buildGrammar:
(cd HybroGen ; make all) # Lexers / parsers for input data
(cd HybroLang ; make all) # Lexers / parsers for HybroLang language

clean:
make buildGrammar
./H2Isa.py -p
./H2Isa.py -p ${DBIDS}
-(cd HybroGen ; make clean)
-(cd HybroLang; make clean)
-(cd CodeExamples/; make clean)
Expand Down
21 changes: 12 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ Computing through QEMU-based System Emulator"](https://hal.archives-ouvertes.fr/
# Installation Dependency

* Grammar use ANTLR4 with python4 backend
* `sudo apt install antlr4`
* `pip3 install antlr4-python3-runtime==4.7.2`

* Compilation need a postresql database. To install postgresql and configure it you can use this commands :
Expand All @@ -44,6 +43,7 @@ Computing through QEMU-based System Emulator"](https://hal.archives-ouvertes.fr/
* `sudo -i -u postgres`
* `createdb hybrogen`
* `createuser --pwprompt hybrogen` # the default password in the code is "hybrogen"
* Under psql prompt `grant all privileges on database hybrogen to hybrogen;`

It is a good practice to not create the database under your own
username. (The database could be multiuser accessible)
Expand All @@ -52,7 +52,6 @@ Computing through QEMU-based System Emulator"](https://hal.archives-ouvertes.fr/
* Qemu build need ninja
* `sudo apt install ninja-build`


# Hybrogen installation

## Create cross-compilers, debugger and emulator for supported platforms
Expand Down Expand Up @@ -96,10 +95,14 @@ architecture depending on your computing power and bandwith.

HybroGen is mainly written in with python but need some build

* Run `make buildGrammar` to build the ANTLR lexer / parser
* Run `make DbPopulate` to populate the SQL database with instructions description
* Congratulation, HybroGen is ready to work !

If you want to play with grammar / lexer / parser, you'll need some more steps:
* Install
* `sudo apt install antlr4`
* `make buildGrammar` to build the ANTLR lexer / parser

## For Computing in memory platform aka CXRAM

For this platform we need a qemu plugin which emulate the C-SRAM
Expand All @@ -109,17 +112,17 @@ Follow instructions on this repository : https://github.com/CEA-LIST/csram-qemu-

## Run some examples / démonstration

* Some code examples are located in the this sub directory : CodeExamples
* Some code examples are located in the this sub directory : `CodeExamples`

For example to run an demonstration for the power architecture here is
the command. Adapt for other architectures / demonstrations.

** `cd CodeExamples/`
** `source /opt/H4.0/powerpc/.cshrc`
** `./RunDemo.py -a power -i Array-Mult-Specialization`

* Regression can be run in the same directory : `./Regression.py power`
* `cd CodeExamples/`
* `source /opt/H4.0/powerpc/.cshrc`
* `./RunDemo.py -a power -i Array-Mult-Specialization`

* Regression can be run in the same directory :
* `./Regression.py power`

# Execution dependencies

Expand Down

0 comments on commit 653c6a6

Please sign in to comment.