Skip to content

Commit

Permalink
Update for new default processor cahp-ruby
Browse files Browse the repository at this point in the history
  • Loading branch information
ushitora-anqou committed May 24, 2020
1 parent f010476 commit 879e6eb
Show file tree
Hide file tree
Showing 3 changed files with 137 additions and 52 deletions.
18 changes: 17 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ all: prepare \
build/kvsp \
build/share/kvsp/diamond-core.json \
build/share/kvsp/emerald-core.json \
build/share/kvsp/ruby-core.json \
build/llvm-cahp \
build/cahp-rt

Expand All @@ -27,6 +28,7 @@ build/kvsp:
-X main.iyokanL1Revision=$$(git -C ../Iyokan-L1 rev-parse --short HEAD) \
-X main.cahpDiamondRevision=$$(git -C ../cahp-diamond rev-parse --short HEAD) \
-X main.cahpEmeraldRevision=$$(git -C ../cahp-emerald rev-parse --short HEAD) \
-X main.cahpRubyRevision=$$(git -C ../cahp-ruby rev-parse --short HEAD) \
-X main.cahpRtRevision=$$(git -C ../cahp-rt rev-parse --short HEAD) \
-X main.cahpSimRevision=$$(git -C ../cahp-sim rev-parse --short HEAD) \
-X main.llvmCahpRevision=$$(git -C ../llvm-cahp rev-parse --short HEAD) \
Expand Down Expand Up @@ -61,6 +63,10 @@ build/cahp-emerald:
rsync -a --delete cahp-emerald/ build/cahp-emerald/
cd build/cahp-emerald && sbt run

build/cahp-ruby:
rsync -a --delete cahp-ruby/ build/cahp-ruby/
cd build/cahp-ruby && sbt run

build/yosys:
rsync -a --delete yosys build/
cd build/yosys && $(MAKE)
Expand All @@ -73,18 +79,28 @@ build/cahp-diamond/vsp-core-no-ram-rom.json: build/cahp-diamond build/yosys
../yosys/yosys build-no-ram-rom.ys

# NOTE: build/cahp-diamond/vsp-core-no-ram-rom.json is "fake" dependency;
# Without this the builds for Diamond and Emerald will run in parallel
# Without this the builds for processors will run in parallel
# to consume too much memory.
build/cahp-emerald/vsp-core-no-ram-rom.json: build/cahp-emerald build/yosys build/cahp-diamond/vsp-core-no-ram-rom.json
cd build/cahp-emerald && \
../yosys/yosys build-no-ram-rom.ys

# NOTE: build/cahp-emerald/vsp-core-no-ram-rom.json is "fake" dependency;
# Without this the builds for processors will run in parallel
# to consume too much memory.
build/cahp-ruby/vsp-core-ruby.json: build/cahp-ruby build/yosys build/cahp-emerald/vsp-core-no-ram-rom.json
cd build/cahp-ruby && \
../yosys/yosys build.ys

build/share/kvsp/diamond-core.json: build/cahp-diamond/vsp-core-no-ram-rom.json build/Iyokan-L1
dotnet run -p build/Iyokan-L1/ -c Release $< $@

build/share/kvsp/emerald-core.json: build/cahp-emerald/vsp-core-no-ram-rom.json build/Iyokan-L1
dotnet run -p build/Iyokan-L1/ -c Release $< $@

build/share/kvsp/ruby-core.json: build/cahp-ruby/vsp-core-ruby.json build/Iyokan-L1
dotnet run -p build/Iyokan-L1/ -c Release $< $@

build/llvm-cahp:
mkdir -p build/llvm-cahp
cd build/llvm-cahp && \
Expand Down
125 changes: 74 additions & 51 deletions kvsp/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ func getPathOf(name string) (string, error) {
path = "../share/kvsp/cahp-diamond.toml"
case "IYOKAN-BLUEPRINT-EMERALD":
path = "../share/kvsp/cahp-emerald.toml"
case "IYOKAN-BLUEPRINT-RUBY":
path = "../share/kvsp/cahp-ruby.toml"
case "IYOKAN-PACKET":
path = "iyokan-packet"
default:
Expand Down Expand Up @@ -248,7 +250,7 @@ func runIyokan(args0 []string, args1 []string) error {
return execCmd(iyokanPath, args)
}

func packELF(inputFileName, outputFileName string, cmdOpts []string) error {
func packELF(inputFileName, outputFileName string, cmdOpts []string, whichCAHPCPU string) error {
if !fileExists(inputFileName) {
return errors.New("File not found")
}
Expand All @@ -259,9 +261,10 @@ func packELF(inputFileName, outputFileName string, cmdOpts []string) error {
if err = attachCommandLineOptions(ram, cmdOpts); err != nil {
return err
}
ramA, ramB, err := splitRAM(ram)
if err != nil {
return err

args := []string{
"pack",
"--out", outputFileName,
}

// Write ROM data
Expand All @@ -270,40 +273,55 @@ func packELF(inputFileName, outputFileName string, cmdOpts []string) error {
return err
}
defer os.Remove(romTmpFile.Name())
_, err = romTmpFile.Write(rom)
if err != nil {
if _, err = romTmpFile.Write(rom); err != nil {
return err
}
args = append(args, "--rom", "rom:"+romTmpFile.Name())

// Write RAM A data
ramATmpFile, err := ioutil.TempFile("", "")
if err != nil {
return err
}
defer os.Remove(ramATmpFile.Name())
_, err = ramATmpFile.Write(ramA)
if err != nil {
return err
}
// Write RAM data
if whichCAHPCPU == "ruby" {
// Write RAM data
ramTmpFile, err := ioutil.TempFile("", "")
if err != nil {
return err
}
defer os.Remove(ramTmpFile.Name())
if _, err = ramTmpFile.Write(ram); err != nil {
return err
}
args = append(args, "--ram", "ram:"+ramTmpFile.Name())
} else {
// Split RAM into two
ramA, ramB, err := splitRAM(ram)
if err != nil {
return err
}

// Write RAM B data
ramBTmpFile, err := ioutil.TempFile("", "")
if err != nil {
return err
}
defer os.Remove(ramBTmpFile.Name())
_, err = ramBTmpFile.Write(ramB)
if err != nil {
return err
// Write RAM A data
ramATmpFile, err := ioutil.TempFile("", "")
if err != nil {
return err
}
defer os.Remove(ramATmpFile.Name())
if _, err = ramATmpFile.Write(ramA); err != nil {
return err
}
args = append(args, "--ram", "ramA:"+ramATmpFile.Name())

// Write RAM B data
ramBTmpFile, err := ioutil.TempFile("", "")
if err != nil {
return err
}
defer os.Remove(ramBTmpFile.Name())
if _, err = ramBTmpFile.Write(ramB); err != nil {
return err
}
args = append(args, "--ram", "ramB:"+ramBTmpFile.Name())
}

// Pack
_, err = runIyokanPacket("pack",
"--out", outputFileName,
"--rom", "rom:"+romTmpFile.Name(),
"--ram", "ramA:"+ramATmpFile.Name(),
"--ram", "ramB:"+ramBTmpFile.Name())
if err != nil {
if _, err = runIyokanPacket(args...); err != nil {
return err
}

Expand Down Expand Up @@ -353,24 +371,25 @@ func (pkt *plainPacket) loadTOML(src string) error {
}

// Load ram
var ramA, ramB []int
pkt.Ram = make([]int, 512)
for _, entry := range pktTOML.Ram {
if entry.Name == "ramA" {
ramA = entry.Bytes
} else if entry.Name == "ramB" {
ramB = entry.Bytes
} else {
switch entry.Name {
case "ram":
for addr := range entry.Bytes {
pkt.Ram[addr] = entry.Bytes[addr]
}
case "ramA":
for addr := range entry.Bytes {
pkt.Ram[addr*2+1] = entry.Bytes[addr]
}
case "ramB":
for addr := range entry.Bytes {
pkt.Ram[addr*2] = entry.Bytes[addr]
}
default:
return errors.New("Invalid TOML for result packet")
}
}
pkt.Ram = make([]int, 512)
for addr := range pkt.Ram {
if addr%2 == 1 {
pkt.Ram[addr] = ramA[addr/2]
} else {
pkt.Ram[addr] = ramB[addr/2]
}
}

// Check if the packet is correct
if _, ok := pkt.Flags["finflag"]; !ok {
Expand Down Expand Up @@ -421,7 +440,7 @@ func doCC() error {
}

// Run
args := []string{"-target", "cahp", "-mcpu=emerald", "-Oz", "--sysroot", cahpRtPath}
args := []string{"-target", "cahp", "-mcpu=generic", "-Oz", "--sysroot", cahpRtPath}
args = append(args, os.Args[2:]...)
return execCmd(path, args)
}
Expand All @@ -441,7 +460,7 @@ func doEmu() error {
// Parse command-line arguments.
fs := flag.NewFlagSet("emu", flag.ExitOnError)
var (
whichCAHPCPU = fs.String("cahp-cpu", "emerald", "Which CAHP CPU you use, emerald or diamond")
whichCAHPCPU = fs.String("cahp-cpu", "ruby", "Which CAHP CPU you use, diamond, emerald, or ruby")
iyokanArgs arrayFlags
)
fs.Var(&iyokanArgs, "iyokan-args", "Raw arguments for Iyokan")
Expand All @@ -455,7 +474,7 @@ func doEmu() error {
defer os.Remove(packedFile.Name())

// Pack
err = packELF(fs.Args()[0], packedFile.Name(), fs.Args()[1:])
err = packELF(fs.Args()[0], packedFile.Name(), fs.Args()[1:], *whichCAHPCPU)
if err != nil {
return err
}
Expand Down Expand Up @@ -544,6 +563,7 @@ func doEnc() error {
keyFileName = fs.String("k", "", "Secret key file name")
inputFileName = fs.String("i", "", "Input file name (plain)")
outputFileName = fs.String("o", "", "Output file name (encrypted)")
whichCAHPCPU = fs.String("cahp-cpu", "ruby", "Which CAHP CPU you use, diamond, emerald, or ruby")
)
err := fs.Parse(os.Args[2:])
if err != nil {
Expand All @@ -561,7 +581,7 @@ func doEnc() error {
defer os.Remove(packedFile.Name())

// Pack
err = packELF(*inputFileName, packedFile.Name(), fs.Args())
err = packELF(*inputFileName, packedFile.Name(), fs.Args(), *whichCAHPCPU)
if err != nil {
return err
}
Expand Down Expand Up @@ -622,6 +642,7 @@ func doPlainpacket() error {
var (
inputFileName = fs.String("i", "", "Input file name (plain)")
outputFileName = fs.String("o", "", "Output file name (encrypted)")
whichCAHPCPU = fs.String("cahp-cpu", "ruby", "Which CAHP CPU you use, diamond, emerald, or ruby")
)
err := fs.Parse(os.Args[2:])
if err != nil {
Expand All @@ -631,7 +652,7 @@ func doPlainpacket() error {
return errors.New("Specify -i, and -o options properly")
}

return packELF(*inputFileName, *outputFileName, fs.Args())
return packELF(*inputFileName, *outputFileName, fs.Args(), *whichCAHPCPU)
}

func doRun() error {
Expand All @@ -643,7 +664,7 @@ func doRun() error {
inputFileName = fs.String("i", "", "Input file name (encrypted)")
outputFileName = fs.String("o", "", "Output file name (encrypted)")
numGPU = fs.Uint("g", 0, "Number of GPUs (Unspecify or set 0 for CPU mode)")
whichCAHPCPU = fs.String("cahp-cpu", "emerald", "Which CAHP CPU you use, emerald or diamond")
whichCAHPCPU = fs.String("cahp-cpu", "ruby", "Which CAHP CPU you use, diamond, emerald, or ruby")
snapshotFileName = fs.String("snapshot", "", "Snapshot file name to write in")
quiet = fs.Bool("quiet", false, "Be quiet")
iyokanArgs arrayFlags
Expand Down Expand Up @@ -742,6 +763,7 @@ var iyokanRevision = "unk"
var iyokanL1Revision = "unk"
var cahpDiamondRevision = "unk"
var cahpEmeraldRevision = "unk"
var cahpRubyRevision = "unk"
var cahpRtRevision = "unk"
var cahpSimRevision = "unk"
var llvmCahpRevision = "unk"
Expand All @@ -753,6 +775,7 @@ func doVersion() error {
fmt.Printf("- Iyokan-L1\t(rev %s)\n", iyokanL1Revision)
fmt.Printf("- cahp-diamond\t(rev %s)\n", cahpDiamondRevision)
fmt.Printf("- cahp-emerald\t(rev %s)\n", cahpEmeraldRevision)
fmt.Printf("- cahp-ruby\t(rev %s)\n", cahpRubyRevision)
fmt.Printf("- cahp-rt\t(rev %s)\n", cahpRtRevision)
fmt.Printf("- cahp-sim\t(rev %s)\n", cahpSimRevision)
fmt.Printf("- llvm-cahp\t(rev %s)\n", llvmCahpRevision)
Expand Down
46 changes: 46 additions & 0 deletions share/cahp-ruby.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
[[file]]
type = "iyokanl1-json"
path = "ruby-core.json"
name = "core"

[[builtin]]
type = "rom"
name = "rom"
in_addr_width = 7
out_rdata_width = 32

[[builtin]]
type = "ram"
name = "ram"
in_addr_width = 8
in_wdata_width = 16
out_rdata_width = 16

[connect]
"rom/addr[0:6]" = "core/io_rom_addr[0:6]"
"core/io_rom_data[0:31]" = "rom/rdata[0:31]"

"ram/wren" = "core/io_ram_writeEnable"
"ram/addr[0:7]" = "core/io_ram_addr[0:7]"
"ram/wdata[0:15]" = "core/io_ram_writeData[0:15]"
"core/io_ram_readData[0:15]" = "ram/rdata[0:15]"

"core/reset" = "@reset"
"@finflag" = "core/io_finishFlag"

"@reg_x0[0:15]" = "core/io_mainRegOut_x0[0:15]"
"@reg_x1[0:15]" = "core/io_mainRegOut_x1[0:15]"
"@reg_x2[0:15]" = "core/io_mainRegOut_x2[0:15]"
"@reg_x3[0:15]" = "core/io_mainRegOut_x3[0:15]"
"@reg_x4[0:15]" = "core/io_mainRegOut_x4[0:15]"
"@reg_x5[0:15]" = "core/io_mainRegOut_x5[0:15]"
"@reg_x6[0:15]" = "core/io_mainRegOut_x6[0:15]"
"@reg_x7[0:15]" = "core/io_mainRegOut_x7[0:15]"
"@reg_x8[0:15]" = "core/io_mainRegOut_x8[0:15]"
"@reg_x9[0:15]" = "core/io_mainRegOut_x9[0:15]"
"@reg_x10[0:15]" = "core/io_mainRegOut_x10[0:15]"
"@reg_x11[0:15]" = "core/io_mainRegOut_x11[0:15]"
"@reg_x12[0:15]" = "core/io_mainRegOut_x12[0:15]"
"@reg_x13[0:15]" = "core/io_mainRegOut_x13[0:15]"
"@reg_x14[0:15]" = "core/io_mainRegOut_x14[0:15]"
"@reg_x15[0:15]" = "core/io_mainRegOut_x15[0:15]"

0 comments on commit 879e6eb

Please sign in to comment.