Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HAST-136: Posit floating point support #58

Open
wants to merge 48 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
0f56cf1
Adding 8, 16 and 32-bit Posit versions with es=0..4 via code generation
Mar 12, 2019
68a1826
Code styling
Mar 12, 2019
998a7f3
Code styling
Mar 12, 2019
7280219
Adding calculators and samples
Dec 15, 2020
5f6f37e
Merge remote-tracking branch 'origin/dev' into issue/HAST-136
Dec 15, 2020
f0ccc3c
Updating merged Lombiq.Arithmetics submodule
Dec 16, 2020
7af5f8f
Targeting .netcoreapp3.1
Dec 29, 2020
9266048
Targeting .netcoreapp3.1
Dec 29, 2020
21ea9a1
Starting to adjust to SimpleMemory changes
Jan 13, 2021
041b587
Updating Lombiq.Arithmetics with SDK-style project fixes to be able t…
BenedekFarkas Mar 18, 2021
76d4f56
Updating Host.Samples.Posit.csproj with T4 template generator declara…
BenedekFarkas Mar 18, 2021
920d7f6
Untabifying PositCalculatorTemplateFileManager.ttinclude
BenedekFarkas Mar 18, 2021
3edccb6
Unifying assembly and namespace reference syntax in PositCalculatorTe…
BenedekFarkas Mar 18, 2021
62fce97
Adding missing Microsoft.VisualStudio.Shell.Framework assembly refere…
BenedekFarkas Mar 18, 2021
85179c7
Posit Samples: Recompiling Posit Calculators and Posit Calculator Sam…
BenedekFarkas Mar 18, 2021
f9e249e
Fixing PositCalculator template syntax errors
BenedekFarkas Mar 18, 2021
0e903ae
Updating Lombiq.Arithmetics with T4 compilation issues fixed
BenedekFarkas Mar 21, 2021
f0f6db5
Temporary (?) workaround to be able transform Posit.tt as T4 template…
BenedekFarkas Mar 21, 2021
3e5fce5
Untabifying Sample.tt and setting csproj to auto-compile it
BenedekFarkas Mar 21, 2021
db3338d
Recompiling PositCalculatorSampleRunner.tt
BenedekFarkas Mar 21, 2021
8d1bd32
Fixing Sample.tt + code styling improvements
BenedekFarkas Mar 21, 2021
cb7e01b
Fixing syntax and structure in Program.tt, but VHDL source ouput is d…
BenedekFarkas Mar 21, 2021
1011d98
Reverting temporary changes in PositCalculatorSampleRunner.tt and fix…
BenedekFarkas Mar 21, 2021
7f51ec1
Fixing Posit sample hardware generation (just in the generated code)
Piedone Mar 22, 2021
8ee5401
Adding device name config for Posit samples
Piedone Mar 22, 2021
f65646a
Updating Program.tt and compiling it to adapt to Hastlayer API changes
BenedekFarkas Mar 22, 2021
1f9185e
Updating Program.tt to correct code formatting in Program.cs
BenedekFarkas Mar 22, 2021
0dd0246
Fixing code analysis warnings in Program
BenedekFarkas Mar 22, 2021
91f2695
Code styling in Program
BenedekFarkas Mar 22, 2021
f914f46
Updating Hast.Core and Lombiq.Arithmetics with their superrepo dev co…
BenedekFarkas Oct 29, 2021
68e8e8d
Merge branch 'dev' into issue/HAST-136
BenedekFarkas Oct 29, 2021
1327906
Updating Lombiq.Arithmetics with Lombiq.Arithmetics.Tests package ver…
BenedekFarkas Oct 29, 2021
74d090b
Updating Hast.Core with latest dev merged into the issue branch
BenedekFarkas Oct 29, 2021
e6ab2d1
Merge branch 'dev' into issue/HAST-136
BenedekFarkas Oct 29, 2021
6f847ec
Merge branch 'dev' into issue/HAST-136
BenedekFarkas Dec 15, 2021
ebf9c51
Updating Lombiq.Arithmetics with PositHelper.tt/cs code styling
BenedekFarkas Dec 15, 2021
424e075
Updating Lombiq.Arithmetics with FixedSizePositTests corrected
BenedekFarkas Dec 15, 2021
3a1271a
Updating Hast.Core and Lombiq.Arithmetics after merge from dev
BenedekFarkas Jan 7, 2022
fbab613
Merge branch 'dev' into issue/HAST-136
BenedekFarkas Jan 7, 2022
1d612a5
Hast.Samples.Posit: Upgrading Microsoft.VisualStudio.Validation to ve…
BenedekFarkas Jan 7, 2022
0593db5
Posit samples: Adapting Program.tt and PositCalculatorSampleRunner.tt…
BenedekFarkas Jan 10, 2022
808d98f
Updating Lombiq.Arithmetics with some of the failing tests fixed + fi…
BenedekFarkas Jan 10, 2022
69be216
Fixing PositCalculatorTemplateFileManager.ttinclude so that saving it…
BenedekFarkas Jan 10, 2022
0c5392e
Updating Lombiq.Arithmetics with the remaining tests fixed
BenedekFarkas Jan 10, 2022
6c1ab83
Fixing indentation in PositCalculator.tt and PositCalculatorSampleRun…
BenedekFarkas Jan 10, 2022
8bb2483
Updating Lombiq.Arithmetics with code styling improvements and adapti…
BenedekFarkas Jan 11, 2022
a71c95f
Updating Lombiq.Arithmetics with PositTemplate code styling
BenedekFarkas Jan 13, 2022
e69245f
Updating Lombiq.Arithmetics with PositTemplate code styling improvements
BenedekFarkas Jan 21, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Hast.Core
Submodule Hast.Core updated 0 files
6 changes: 6 additions & 0 deletions Hast.Samples.Posit/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
</configuration>
63 changes: 63 additions & 0 deletions Hast.Samples.Posit/Hast.Samples.Posit.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<OutputType>Exe</OutputType>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Hast.Abstractions\Hast.Transformer.Abstractions\Hast.Transformer.Abstractions.csproj" />
<ProjectReference Include="..\Hast.Abstractions\Hast.Transformer.Vhdl.Abstractions\Hast.Transformer.Vhdl.Abstractions.csproj" />
<ProjectReference Include="..\Hast.Common\Hast.Common.csproj" />
<ProjectReference Include="..\Hast.Layer\Hast.Layer.csproj" />
<ProjectReference Include="..\Hast.Remote.Client\Hast.Remote.Client.csproj" />
<ProjectReference Include="..\Lombiq.Arithmetics\Lombiq.Arithmetics.csproj" />
<ProjectReference Include="..\Samples\Hast.Samples.SampleAssembly\Hast.Samples.SampleAssembly.csproj" />
</ItemGroup>
<ItemGroup>
<Content Include="PositCalculator.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>PositCalculator.cs</LastGenOutput>
</Content>
<Content Include="PositCalculatorSampleRunner.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>PositCalculatorSampleRunner.cs</LastGenOutput>
</Content>
<Content Include="Program.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>Program.cs</LastGenOutput>
</Content>
<Content Include="Sample.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>Sample.cs</LastGenOutput>
</Content>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.Validation" Version="16.9.32" />
</ItemGroup>
<ItemGroup>
<Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" />
</ItemGroup>
<ItemGroup>
<Compile Update="PositCalculator.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>PositCalculator.tt</DependentUpon>
</Compile>
<Compile Update="PositCalculatorSampleRunner.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>PositCalculatorSampleRunner.tt</DependentUpon>
</Compile>
<Compile Update="Program.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Program.tt</DependentUpon>
</Compile>
<Compile Update="Sample.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Sample.tt</DependentUpon>
</Compile>
</ItemGroup>
</Project>
203 changes: 203 additions & 0 deletions Hast.Samples.Posit/Posit16E0Calculator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Hast.Layer;
using Hast.Transformer.Abstractions.SimpleMemory;
using Lombiq.Arithmetics;

namespace Hast.Samples.Posit
{

public class Posit16E0Calculator
{
public const int CalculateLargeIntegerSum_InputInt32Index = 0;
public const int CalculateLargeIntegerSum_OutputInt32Index = 0;
public const int ParallelizedCalculateLargeIntegerSum_Int32NumbersStartIndex = 0;
public const int ParallelizedCalculateLargeIntegerSum_OutputInt32sStartIndex = 0;
public const int AddPositsInArray_InputPosit32CountIndex = 0;
public const int AddPositsInArray_InputPosit32sStartIndex = 1;
public const int AddPositsInArray_OutputPosit32Index = 2;
public const int CalculatePowerOfReal_InputInt32Index = 0;
public const int CalculatePowerOfReal_InputPosit32Index = 1;
public const int CalculatePowerOfReal_OutputPosit32Index = 0;

public const int MaxDegreeOfParallelism = 5;


public virtual void CalculateIntegerSumUpToNumber(SimpleMemory memory)
{
var number = memory.ReadUInt32(CalculateLargeIntegerSum_InputInt32Index);

var a = new Posit16E0((ushort)1);
var b = a;

for (uint i = 1; i < number; i++)
{
a += b;
}

var result = (int)a;
memory.WriteInt32(CalculateLargeIntegerSum_OutputInt32Index, result);
}

public virtual void CalculatePowerOfReal(SimpleMemory memory)
{
var number = memory.ReadInt32(CalculatePowerOfReal_InputInt32Index);
var positToMultiply = (ushort)memory.ReadUInt32(CalculatePowerOfReal_InputPosit32Index);

var a = new Posit16E0(positToMultiply, true);
var b = a;

for (uint i = 0; i < number; i++)
{
a *= b;
}

var result = a.PositBits;
memory.WriteUInt32(CalculatePowerOfReal_OutputPosit32Index, result);
}

public virtual void ParallelizedCalculateIntegerSumUpToNumbers(SimpleMemory memory)
{
var numbers = new int[MaxDegreeOfParallelism];

var tasks = new Task<int>[MaxDegreeOfParallelism];

for (int i = 0; i < MaxDegreeOfParallelism; i++)
{
var upToNumber = memory.ReadInt32(ParallelizedCalculateLargeIntegerSum_Int32NumbersStartIndex + i);

tasks[i] = Task.Factory.StartNew(
upToNumberObject =>
{
var a = new Posit16E0(1);
var b = a;

for (int j = 1; j < (int)upToNumberObject; j++)
{
a += b;
}

return (int)a;
}, upToNumber);
}

Task.WhenAll(tasks).Wait();

for (int i = 0; i < MaxDegreeOfParallelism; i++)
{
memory.WriteInt32(ParallelizedCalculateLargeIntegerSum_OutputInt32sStartIndex + i, tasks[i].Result);
}
}

public virtual void AddPositsInArray(SimpleMemory memory)
{
uint numberCount = memory.ReadUInt32(AddPositsInArray_InputPosit32CountIndex);

var result = new Posit16E0((ushort)memory.ReadUInt32(AddPositsInArray_InputPosit32sStartIndex), true);

for (int i = 1; i < numberCount; i++)
{
result += new Posit16E0((ushort)memory.ReadUInt32(AddPositsInArray_InputPosit32sStartIndex + i), true);
}

memory.WriteUInt32(AddPositsInArray_OutputPosit32Index, result.PositBits);
}
}


public static class Posit16E0CalculatorCalculatorExtensions
{
public static int CalculateIntegerSumUpToNumber(
this Posit16E0Calculator positCalculator,
int number,
IHastlayer hastlayer = null,
IHardwareGenerationConfiguration configuration = null)
{
var memory = hastlayer is null
? SimpleMemory.CreateSoftwareMemory(1)
: hastlayer.CreateMemory(configuration, 1);

memory.WriteInt32( Posit16E0Calculator.CalculateLargeIntegerSum_InputInt32Index, number);
positCalculator.CalculateIntegerSumUpToNumber(memory);

return memory.ReadInt32( Posit16E0Calculator.CalculateLargeIntegerSum_OutputInt32Index);
}

public static float CalculatePowerOfReal(
this Posit16E0Calculator positCalculator,
int number,
float real,
IHastlayer hastlayer = null,
IHardwareGenerationConfiguration configuration = null)
{
var memory = hastlayer is null
? SimpleMemory.CreateSoftwareMemory(2)
: hastlayer.CreateMemory(configuration, 2);

memory.WriteInt32( Posit16E0Calculator.CalculatePowerOfReal_InputInt32Index, number);
memory.WriteUInt32( Posit16E0Calculator.CalculatePowerOfReal_InputPosit32Index, new Posit16E0(real).PositBits);

positCalculator.CalculatePowerOfReal(memory);

return (float)new Posit16E0((ushort)memory.ReadUInt32( Posit16E0Calculator.CalculatePowerOfReal_OutputPosit32Index), true);
}

public static IEnumerable<int> ParallelizedCalculateIntegerSumUpToNumbers(
this Posit16E0Calculator positCalculator,
int[] numbers,
IHastlayer hastlayer = null,
IHardwareGenerationConfiguration configuration = null)
{
if (numbers.Length != Posit16E0Calculator.MaxDegreeOfParallelism)
{
throw new ArgumentException(
"Provide as many numbers as the degree of parallelism of Posit16E0Calculator is (" +
Posit16E0Calculator.MaxDegreeOfParallelism + ")");
}

var memory = hastlayer is null
? SimpleMemory.CreateSoftwareMemory(Posit16E0Calculator.MaxDegreeOfParallelism)
: hastlayer.CreateMemory(configuration, Posit16E0Calculator.MaxDegreeOfParallelism);

for (int i = 0; i < numbers.Length; i++)
{
memory.WriteInt32( Posit16E0Calculator.ParallelizedCalculateLargeIntegerSum_Int32NumbersStartIndex + i, numbers[i]);
}

positCalculator.ParallelizedCalculateIntegerSumUpToNumbers(memory);

var results = new int[ Posit16E0Calculator.MaxDegreeOfParallelism];

for (int i = 0; i < numbers.Length; i++)
{
results[i] = memory.ReadInt32( Posit16E0Calculator.ParallelizedCalculateLargeIntegerSum_OutputInt32sStartIndex + i);
}

return results;
}

public static float AddPositsInArray(
this Posit16E0Calculator positCalculator,
uint[] positArray,
IHastlayer hastlayer = null,
IHardwareGenerationConfiguration configuration = null)
{
var memory = hastlayer is null
? SimpleMemory.CreateSoftwareMemory(positArray.Length + 1)
: hastlayer.CreateMemory(configuration, positArray.Length + 1);

memory.WriteUInt32( Posit16E0Calculator.AddPositsInArray_InputPosit32CountIndex, (uint) positArray.Length);

for (var i = 0; i < positArray.Length; i++)
{
memory.WriteUInt32( Posit16E0Calculator.AddPositsInArray_InputPosit32sStartIndex + i, positArray[i]);
}

positCalculator.AddPositsInArray(memory);

return (float)new Posit32(memory.ReadUInt32( Posit16E0Calculator.AddPositsInArray_OutputPosit32Index), true);
}
}
}

Loading