Skip to content

Commit

Permalink
Merge pull request #9 from ReconfigureIO/feature/sdaccel-library
Browse files Browse the repository at this point in the history
replace magic libraries with open-source ones
  • Loading branch information
CampGareth authored Dec 14, 2017
2 parents 3c501df + 2418fd6 commit 965d548
Show file tree
Hide file tree
Showing 20 changed files with 199 additions and 179 deletions.
2 changes: 1 addition & 1 deletion addition-gaps/cmd/test-addition/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package main
import (
"encoding/binary"
"fmt"
"github.com/ReconfigureIO/sdaccel/xcl"
"os"
"xcl"
)

func main() {
Expand Down
6 changes: 3 additions & 3 deletions addition-gaps/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package main

import (
// Import the entire framework (including bundled verilog)
_ "sdaccel"
_ "github.com/ReconfigureIO/sdaccel"

aximemory "axi/memory"
axiprotocol "axi/protocol"
aximemory "github.com/ReconfigureIO/sdaccel/axi/memory"
axiprotocol "github.com/ReconfigureIO/sdaccel/axi/protocol"
)

// The Top function will be presented as a kernel
Expand Down
2 changes: 1 addition & 1 deletion addition/cmd/test-addition/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package main
import (
"encoding/binary"
"fmt"
"github.com/ReconfigureIO/sdaccel/xcl"
"os"
"xcl"
)

func main() {
Expand Down
6 changes: 3 additions & 3 deletions addition/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package main

import (
// Import the entire framework (including bundled verilog)
_ "sdaccel"
_ "github.com/ReconfigureIO/sdaccel"

// Use the new AXI protocol package
aximemory "axi/memory"
axiprotocol "axi/protocol"
aximemory "github.com/ReconfigureIO/sdaccel/axi/memory"
axiprotocol "github.com/ReconfigureIO/sdaccel/axi/protocol"

"github.com/ReconfigureIO/addition"
)
Expand Down
2 changes: 1 addition & 1 deletion histogram-array/cmd/test-histogram/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package main
import (
"encoding/binary"
"fmt"
"github.com/ReconfigureIO/sdaccel/xcl"
"log"
"math/rand"
"reflect"
"xcl"
)

const (
Expand Down
15 changes: 9 additions & 6 deletions histogram-array/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@ package main

import (
// import the entire framework (including bundled verilog)
_ "sdaccel"
_ "github.com/ReconfigureIO/sdaccel"
// Use the new AXI protocol package
aximemory "axi/memory"
axiprotocol "axi/protocol"
aximemory "github.com/ReconfigureIO/sdaccel/axi/memory"
axiprotocol "github.com/ReconfigureIO/sdaccel/axi/protocol"
)

// calculate the bin for the histogram
func CalculateIndex(sample uint32) uint16 {
return uint16(sample) >> (16 - 9)
}

// magic identifier for exporting
func Top(
inputData uintptr,
Expand All @@ -32,11 +37,9 @@ func Top(
for ; length > 0; length-- {
// First we'll pull of each sample from the channel
sample := <-inputChan
// calculate the bin for the histogram
index := uint16(sample) >> (16 - 9)

// And increment the value in that bin
histogram[uint(index)] += 1
histogram[CalculateIndex(sample)] += 1
}

data := make(chan uint32)
Expand Down
17 changes: 17 additions & 0 deletions histogram-array/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package main

import (
"testing"
"testing/quick"
)

func TestCalculateIndexDoesNotOutOfBounds(t *testing.T) {
// Check that we never generate an index out of bounds
f := func(x uint32) bool {
index := CalculateIndex(x)
return index < 512
}
if err := quick.Check(f, nil); err != nil {
t.Error(err)
}
}
2 changes: 1 addition & 1 deletion histogram-parallel/cmd/test-histogram/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package main
import (
"encoding/binary"
"fmt"
"github.com/ReconfigureIO/sdaccel/xcl"
"log"
"math/rand"
"reflect"
"xcl"
)

const (
Expand Down
8 changes: 4 additions & 4 deletions histogram-parallel/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package main

import (
// Import the entire framework (including bundled verilog)
_ "sdaccel"
_ "github.com/ReconfigureIO/sdaccel"

axiarbitrate "axi/arbitrate"
aximemory "axi/memory"
axiprotocol "axi/protocol"
axiarbitrate "github.com/ReconfigureIO/sdaccel/axi/arbitrate"
aximemory "github.com/ReconfigureIO/sdaccel/axi/memory"
axiprotocol "github.com/ReconfigureIO/sdaccel/axi/protocol"
)

// Magic identifier for exporting
Expand Down
2 changes: 1 addition & 1 deletion histogram/cmd/test-histogram/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package main
import (
"encoding/binary"
"fmt"
"github.com/ReconfigureIO/sdaccel/xcl"
"log"
"math/rand"
"reflect"
"xcl"
)

const (
Expand Down
6 changes: 3 additions & 3 deletions histogram/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package main

import (
// Import the entire framework (including bundled verilog)
_ "sdaccel"
_ "github.com/ReconfigureIO/sdaccel"
// Use the new AXI protocol package
aximemory "axi/memory"
axiprotocol "axi/protocol"
aximemory "github.com/ReconfigureIO/sdaccel/axi/memory"
axiprotocol "github.com/ReconfigureIO/sdaccel/axi/protocol"
)

// Magic identifier for exporting
Expand Down
2 changes: 1 addition & 1 deletion memcopy/cmd/test-memcopy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package main

import (
"encoding/binary"
"github.com/ReconfigureIO/sdaccel/xcl"
"log"
"math/rand"
"reflect"
"testing/quick"
"time"
"xcl"
)

const DATA_WIDTH = 12
Expand Down
6 changes: 3 additions & 3 deletions memcopy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package main

import (
// Import the entire framework (including bundled verilog)
_ "sdaccel"
_ "github.com/ReconfigureIO/sdaccel"
// Use the new AXI protocol package
aximemory "axi/memory"
axiprotocol "axi/protocol"
aximemory "github.com/ReconfigureIO/sdaccel/axi/memory"
axiprotocol "github.com/ReconfigureIO/sdaccel/axi/protocol"
)

// Magic identifier for exporting
Expand Down
2 changes: 1 addition & 1 deletion memtest/cmd/memtest/main.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package main

import (
"github.com/ReconfigureIO/sdaccel/xcl"
"log"
"xcl"
)

func main() {
Expand Down
4 changes: 2 additions & 2 deletions memtest/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package main

import (
// import the entire framework (including bundled verilog)
_ "sdaccel"
"sdaccel/memory"
_ "github.com/ReconfigureIO/sdaccel"
"github.com/ReconfigureIO/sdaccel/axi/memory"
)

// magic identifier for exporting
Expand Down
6 changes: 3 additions & 3 deletions template/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package main

import (
// Import the entire framework (including bundled verilog)
_ "sdaccel"
_ "github.com/ReconfigureIO/sdaccel"

// Use the new AXI protocol package
aximemory "axi/memory"
axiprotocol "axi/protocol"
aximemory "github.com/ReconfigureIO/sdaccel/axi/memory"
axiprotocol "github.com/ReconfigureIO/sdaccel/axi/protocol"
)

func Top(
Expand Down
92 changes: 46 additions & 46 deletions tutorial3_examples/multiply-array/cmd/test-multiply-array/main.go
Original file line number Diff line number Diff line change
@@ -1,68 +1,68 @@
package main

import (
"encoding/binary"
"xcl"
"fmt"
"encoding/binary"
"fmt"
"github.com/ReconfigureIO/sdaccel/xcl"
)

func main() {
// Allocate a 'world' for interacting with kernels
world := xcl.NewWorld()
defer world.Release()
// Allocate a 'world' for interacting with kernels
world := xcl.NewWorld()
defer world.Release()

// Import the kernel.
// Right now these two identifiers are hard coded as an output from the build process
krnl := world.Import("kernel_test").GetKernel("reconfigure_io_sdaccel_builder_stub_0_1")
defer krnl.Release()
// Import the kernel.
// Right now these two identifiers are hard coded as an output from the build process
krnl := world.Import("kernel_test").GetKernel("reconfigure_io_sdaccel_builder_stub_0_1")
defer krnl.Release()

// Create/get data and pass arguments to the kernel as required. These could be small pieces of data,
// pointers to memory, data lengths so the Kernel knows what to expect. This all depends on your project.
// We have passed three arguments here, you can pass more as neccessary
// Create/get data and pass arguments to the kernel as required. These could be small pieces of data,
// pointers to memory, data lengths so the Kernel knows what to expect. This all depends on your project.
// We have passed three arguments here, you can pass more as neccessary

// make an array to send to the kernel for processing
input := make([]uint32, 10)
// make an array to send to the kernel for processing
input := make([]uint32, 10)

// seed it with incrementing values
for i, _ := range input {
input[i] = uint32(i)
}
// seed it with incrementing values
for i, _ := range input {
input[i] = uint32(i)
}

// Create space in shared memory for our array input
buff := world.Malloc(xcl.ReadOnly, uint(binary.Size(input)))
defer buff.Free()
// Create space in shared memory for our array input
buff := world.Malloc(xcl.ReadOnly, uint(binary.Size(input)))
defer buff.Free()

// Create a variable to hold the output from the FPGA
var output [10]uint32
// Create a variable to hold the output from the FPGA
var output [10]uint32

// Create space in the shared memory for the output from the FPGA
outputBuff := world.Malloc(xcl.ReadWrite, uint(binary.Size(output)))
defer outputBuff.Free()
// Create space in the shared memory for the output from the FPGA
outputBuff := world.Malloc(xcl.ReadWrite, uint(binary.Size(output)))
defer outputBuff.Free()

// write our input to the shared memory at the location we specified previously
binary.Write(buff.Writer(), binary.LittleEndian, &input)
// write our input to the shared memory at the location we specified previously
binary.Write(buff.Writer(), binary.LittleEndian, &input)

// zero out output space
binary.Write(outputBuff.Writer(), binary.LittleEndian, &output)
// zero out output space
binary.Write(outputBuff.Writer(), binary.LittleEndian, &output)

// Send the location of the input array as the first argument
krnl.SetMemoryArg(0, buff)
// Send the location the FPGA should put the result as the second argument
krnl.SetMemoryArg(1, outputBuff)
// Send the length of the input array, so the kernel knows what to expect, as the third argument
krnl.SetArg(2, uint32(len(input)))
// Send the location of the input array as the first argument
krnl.SetMemoryArg(0, buff)
// Send the location the FPGA should put the result as the second argument
krnl.SetMemoryArg(1, outputBuff)
// Send the length of the input array, so the kernel knows what to expect, as the third argument
krnl.SetArg(2, uint32(len(input)))

// Run the kernel with the supplied arguments. This is the same for all projects.
// The arguments ``(1, 1, 1)`` relate to x, y, z co-ordinates and correspond to our current
// underlying technology.
krnl.Run(1, 1, 1)
// Run the kernel with the supplied arguments. This is the same for all projects.
// The arguments ``(1, 1, 1)`` relate to x, y, z co-ordinates and correspond to our current
// underlying technology.
krnl.Run(1, 1, 1)

// Display/use the results returned from the FPGA as required!
// Display/use the results returned from the FPGA as required!

binary.Read(outputBuff.Reader(), binary.LittleEndian, &output);
binary.Read(outputBuff.Reader(), binary.LittleEndian, &output)

for _, val := range output {
print(val)
}
for _, val := range output {
print(val)
}

}
Loading

0 comments on commit 965d548

Please sign in to comment.