Kiwi Scientific Acceleration: C# high-level synthesis for FPGA execution.
Visual Basic High-Level Synthesis (HLS) Demo

Kiwi Scientific Acceleration: Visual Basic High-Level Synthesis (HLS) Demo

Introduction

Although Kiwi is designed for use with CSharp, it works a little bit with Visual Basic since both compilers generate dotnet CIL PE portable assemblies...

Primes Demo

We tried the following Visual Basic Program

' Kiwi Scientific Acceleration - Visual Basic Demo
' Primes using Sieve of Eratostheneso
' For Kiwi use, since this has no inputs or output, compile with something like -bevelab-default-pause-mode=bblock,  or
' put a Kiwi.Pause call near the start, otherwise the whole program will be run at compile time!

Imports KiwiSystem

Module Primes

   Private Const MyLimit = 10000

   Dim flags(MyLimit-1) as Boolean

   Private Sub Setter()
      Console.WriteLine("Setting All Flags")
      Dim p1 as Integer
      p1 = 0
      While (p1 < MyLimit)
            Flags(p1) = true
            p1 = p1 + 1
      End While
   End Sub


   Private Sub CrossingsOff()
      Console.WriteLine("Crossings Off Flags")
      Dim ii, jj as Integer
      ii = 2
      While (ii < MyLimit)
            jj = ii*2
            While (jj < MyLimit)
                Flags(jj) = false
                jj = jj + ii
            End While
            ii = ii + 1
      End While
   End Sub


   Private Sub Printer()
      Console.WriteLine("Printing out the primes:")
      Dim count, p3 as Integer
      p3 = 0
      count = 0
      While (p3 < MyLimit)
            if Flags(p3) 
               Console.WriteLine("  {0} is prime", p3)
               count = count + 1
               End If
            p3 = p3 + 1
      End While
      Console.WriteLine("There are {0} primes below {1}.", count, MyLimit)
   End Sub

   Public Sub Main()
      Console.WriteLine("Primes Start:")
      Kiwi.Pause() 
      Setter()
      CrossingsOff()
      Printer()
      Console.WriteLine("Primes End:")
   End Sub

End Module
' eof

Mono Compile and Run

This is a simple Visual Basic program that compiles and runs well-enough under mono.

Compile:

vbnc Primes.vb  /r:/home/djg11/d320/hprls/kiwipro/kiwic/distro/support/Kiwi.dll /r:Kiwi_vb.dll
Visual Basic.Net Compiler version 0.0.0.5943 (Mono 3.0 - tarball)
Copyright (C) 2004-2010 Rolf Bjarne Kvinge. All rights reserved.
Assembly 'Primes, Version=0.0, Culture=neutral, PublicKeyToken=null' saved successfully to '/local/scratch/home/djg11/Dropbox/Kiwi-visual-basic/Primes.exe'.
Compilation successful
Compilation took 00:00:00.4294220

Run:

MONO_PATH=/home/djg11/d320/hprls/kiwipro/kiwic/distro/support:.. time mono  Primes.exe | tee goldspool
Primes Start:
Setting All Flags
Crossings Off Flags
Printing out the primes:
  0 is prime
  1 is prime
  2 is prime
  3 is prime
  5 is prime
  7 is prime
  11 is prime
  13 is prime
  17 is prime
... snip ...
  9941 is prime
  9949 is prime
  9967 is prime
  9973 is prime
There are 1231 primes below 10000.
Primes End:
0.01user 0.01system 0:00.04elapsed 78%CPU (0avgtext+0avgdata 13936maxresident)k
0inputs+0outputs (0major+2821minor)pagefaults 0swaps

KiwiC Compile

Visual Basic assemblies require a few extra facilities to be 'faked out' before the program can be run. We created and used an additional dll with the following trivial entries to get over this hurdle:

// Kiwi_vb.cs
// Kiwi Scientific Acceleration
// Additional bindings needed for a trival Visual Basic program to compile with KiwiC.
namespace Microsoft
{
  namespace VisualBasic
  {
    namespace Devices
    {
      public class Computer
      { //= "My.Computer";
        
      }
    }
    namespace ApplicationServices
    {
      public class ApplicationBase
      {
        
      }
      public class User
      {
        
      }
    }
  }
}
// eof

The dll was implemented in C# and compiled with mcs and the resulting Kiwi_vb.dll was simply added to the KiwiC command line.

$ mcs /target:library Kiwi_vb.cs
$ kiwic -kiwic-register-colours=1 -vnl-resets=synchronous -vnl-roundtrip=disable -bevelab-default-pause-mode=bblock -res2-loadstore-port-count=0 -repack-to-roms=enable Primes.exe Kiwi_vb.dll -root=Primes.Main -vnl=Primes.v
$ ls -l Primes.v ; wc Primes.v
-rw-rw-r-- 1 djg11 djg11 31159 Nov 29 10:06 Primes.v
571  2497 31159 Primes.v

The generated Verilog RTL file is HERE

RTL_SIM Run Under Icarus Verilog

iverilog Primes.v vsys.v /home/djg11/d320/hprls/kiwipro/kiwic/distro/lib/cvgates.v  /home/djg11/d320/hprls/kiwipro/kiwic/distro/lib/cv_fparith.v
./a.out | tee icarus.spool
VCD info: dumpfile vcd.vcd opened for output.
Primes Start:
Setting All Flags
Crossings Off Flags
Printing out the primes:
  0 is prime
  1 is prime
  2 is prime
  3 is prime
  5 is prime
  7 is prime
  11 is prime
  13 is prime
  17 is prime
  19 is prime
  23 is prime
  29 is prime
 ... snip ...
  9949 is prime
  9967 is prime
  9973 is prime
There are 1231 primes below 10000.
Primes End:

Conclusion

Kiwi can be used to compile Visual Basic, at least to some extent!

The output from RTL_SIM was the same as directly from mono.


December 2016.               UP.