|
1 | 1 | package main
|
2 | 2 |
|
3 | 3 | import (
|
4 |
| - "encoding/binary" |
5 |
| - "xcl" |
6 |
| - "fmt" |
| 4 | + "encoding/binary" |
| 5 | + "fmt" |
| 6 | + "github.com/ReconfigureIO/sdaccel/xcl" |
7 | 7 | )
|
8 | 8 |
|
9 | 9 | func main() {
|
10 |
| - // Allocate a 'world' for interacting with kernels |
11 |
| - world := xcl.NewWorld() |
12 |
| - defer world.Release() |
| 10 | + // Allocate a 'world' for interacting with kernels |
| 11 | + world := xcl.NewWorld() |
| 12 | + defer world.Release() |
13 | 13 |
|
14 |
| - // Import the kernel. |
15 |
| - // Right now these two identifiers are hard coded as an output from the build process |
16 |
| - krnl := world.Import("kernel_test").GetKernel("reconfigure_io_sdaccel_builder_stub_0_1") |
17 |
| - defer krnl.Release() |
| 14 | + // Import the kernel. |
| 15 | + // Right now these two identifiers are hard coded as an output from the build process |
| 16 | + krnl := world.Import("kernel_test").GetKernel("reconfigure_io_sdaccel_builder_stub_0_1") |
| 17 | + defer krnl.Release() |
18 | 18 |
|
19 |
| - // Create/get data and pass arguments to the kernel as required. These could be small pieces of data, |
20 |
| - // pointers to memory, data lengths so the Kernel knows what to expect. This all depends on your project. |
21 |
| - // We have passed three arguments here, you can pass more as neccessary |
| 19 | + // Create/get data and pass arguments to the kernel as required. These could be small pieces of data, |
| 20 | + // pointers to memory, data lengths so the Kernel knows what to expect. This all depends on your project. |
| 21 | + // We have passed three arguments here, you can pass more as neccessary |
22 | 22 |
|
23 |
| - // make an array to send to the kernel for processing |
24 |
| - input := make([]uint32, 10) |
| 23 | + // make an array to send to the kernel for processing |
| 24 | + input := make([]uint32, 10) |
25 | 25 |
|
26 |
| - // seed it with incrementing values |
27 |
| - for i, _ := range input { |
28 |
| - input[i] = uint32(i) |
29 |
| - } |
| 26 | + // seed it with incrementing values |
| 27 | + for i, _ := range input { |
| 28 | + input[i] = uint32(i) |
| 29 | + } |
30 | 30 |
|
31 |
| - // Create space in shared memory for our array input |
32 |
| - buff := world.Malloc(xcl.ReadOnly, uint(binary.Size(input))) |
33 |
| - defer buff.Free() |
| 31 | + // Create space in shared memory for our array input |
| 32 | + buff := world.Malloc(xcl.ReadOnly, uint(binary.Size(input))) |
| 33 | + defer buff.Free() |
34 | 34 |
|
35 |
| - // Create a variable to hold the output from the FPGA |
36 |
| - var output [10]uint32 |
| 35 | + // Create a variable to hold the output from the FPGA |
| 36 | + var output [10]uint32 |
37 | 37 |
|
38 |
| - // Create space in the shared memory for the output from the FPGA |
39 |
| - outputBuff := world.Malloc(xcl.ReadWrite, uint(binary.Size(output))) |
40 |
| - defer outputBuff.Free() |
| 38 | + // Create space in the shared memory for the output from the FPGA |
| 39 | + outputBuff := world.Malloc(xcl.ReadWrite, uint(binary.Size(output))) |
| 40 | + defer outputBuff.Free() |
41 | 41 |
|
42 |
| - // write our input to the shared memory at the location we specified previously |
43 |
| - binary.Write(buff.Writer(), binary.LittleEndian, &input) |
| 42 | + // write our input to the shared memory at the location we specified previously |
| 43 | + binary.Write(buff.Writer(), binary.LittleEndian, &input) |
44 | 44 |
|
45 |
| - // zero out output space |
46 |
| - binary.Write(outputBuff.Writer(), binary.LittleEndian, &output) |
| 45 | + // zero out output space |
| 46 | + binary.Write(outputBuff.Writer(), binary.LittleEndian, &output) |
47 | 47 |
|
48 |
| - // Send the location of the input array as the first argument |
49 |
| - krnl.SetMemoryArg(0, buff) |
50 |
| - // Send the location the FPGA should put the result as the second argument |
51 |
| - krnl.SetMemoryArg(1, outputBuff) |
52 |
| - // Send the length of the input array, so the kernel knows what to expect, as the third argument |
53 |
| - krnl.SetArg(2, uint32(len(input))) |
| 48 | + // Send the location of the input array as the first argument |
| 49 | + krnl.SetMemoryArg(0, buff) |
| 50 | + // Send the location the FPGA should put the result as the second argument |
| 51 | + krnl.SetMemoryArg(1, outputBuff) |
| 52 | + // Send the length of the input array, so the kernel knows what to expect, as the third argument |
| 53 | + krnl.SetArg(2, uint32(len(input))) |
54 | 54 |
|
55 |
| - // Run the kernel with the supplied arguments. This is the same for all projects. |
56 |
| - // The arguments ``(1, 1, 1)`` relate to x, y, z co-ordinates and correspond to our current |
57 |
| - // underlying technology. |
58 |
| - krnl.Run(1, 1, 1) |
| 55 | + // Run the kernel with the supplied arguments. This is the same for all projects. |
| 56 | + // The arguments ``(1, 1, 1)`` relate to x, y, z co-ordinates and correspond to our current |
| 57 | + // underlying technology. |
| 58 | + krnl.Run(1, 1, 1) |
59 | 59 |
|
60 |
| - // Display/use the results returned from the FPGA as required! |
| 60 | + // Display/use the results returned from the FPGA as required! |
61 | 61 |
|
62 |
| - binary.Read(outputBuff.Reader(), binary.LittleEndian, &output); |
| 62 | + binary.Read(outputBuff.Reader(), binary.LittleEndian, &output) |
63 | 63 |
|
64 |
| - for _, val := range output { |
65 |
| - print(val) |
66 |
| - } |
| 64 | + for _, val := range output { |
| 65 | + print(val) |
| 66 | + } |
67 | 67 |
|
68 | 68 | }
|
0 commit comments