Permalink
Browse files

Make NeuFlow use new Interface api

This removes the interface/protocol code from NeuFlow and will thus allow us to
more easily add new interfaces.
  • Loading branch information...
1 parent 59d0e44 commit 89b68742c1da417d5c3061e5c9563b59683ad8e3 @bmartini bmartini committed Apr 26, 2012
Showing with 15 additions and 65 deletions.
  1. +15 −65 src/NeuFlow.lua
View
@@ -62,7 +62,7 @@ function NeuFlow:__init(args)
if not l then
self.use_ethernet = false
else
- etherflow.open()
+ self.ethernet:open()
end
end
@@ -84,7 +84,7 @@ end
--
function NeuFlow:cleanup()
if self.use_ethernet then
- etherflow.close()
+ self.ethernet:close()
end
if self.tty then
self.tty:cleanup()
@@ -279,18 +279,10 @@ function NeuFlow:copyFromHost(source, dest)
else
-- process list of streams
print('<neuflow.NeuFlow> copy host->dev: ' .. #ldest .. 'x' .. ldest[1].orig_h .. 'x' .. ldest[1].orig_w)
- for i = 1,#ldest do
- self.core:startProcess()
- self.ethernet:streamFromHost(ldest[i], 'default')
- self.core:endProcess()
- end
- end
- -- always print a dummy flag, useful for profiling
- if self.mode ~= 'simulation' then
- self.core:startProcess()
- self.ethernet:printToEthernet('copy-done')
- self.core:endProcess()
+
+ self.ethernet:dev_copyFromHost(ldest)
end
+
return dest
end
@@ -300,29 +292,26 @@ function NeuFlow:copyToHost(source, dest)
if self.mode == 'simulation' or (not self.handshake) then
ack = 'no-ack'
end
- -- always print a dummy flag, useful for profiling
- if self.mode ~= 'simulation' then
- self.core:startProcess()
- self.ethernet:printToEthernet('copy-starting')
- self.core:endProcess()
- end
+
-- check if source is a list of streams, or a stream
local lsource
if #source == 0 then
lsource = {source}
else
lsource = source
end
+
-- record original sizes
local orig_h = lsource[1].orig_h
local orig_w = lsource[1].orig_w
+
-- process list of streams
print('<neuflow.NeuFlow> copy dev->host: ' .. #lsource .. 'x' .. lsource[1].orig_h .. 'x' .. lsource[1].orig_w)
- for i = 1,#lsource do
- self.core:startProcess()
- self.ethernet:streamToHost(lsource[i], 'default', ack)
- self.core:endProcess()
+
+ if self.mode ~= 'simulation' then
+ self.ethernet:dev_copyToHost(lsource, ack)
end
+
-- create/resize dest
if not dest then
dest = torch.Tensor()
@@ -449,7 +438,7 @@ function NeuFlow:loadBytecode(bytecode)
-- then transmit bytecode
print('<neuflow.NeuFlow> transmitting bytecode')
self.profiler:start('load-bytecode')
- etherflow.loadbytecode(bytecode)
+ self.ethernet:host_sendBytecode(bytecode)
self.profiler:lap('load-bytecode')
-- we are already transmitting the bytecode
-- we can close the log file now
@@ -486,57 +475,18 @@ end
--
function NeuFlow:copyToDev(tensor)
self.profiler:start('copy-to-dev')
- local dims = tensor:nDimension()
- if dims == 3 then
- for i = 1,tensor:size(1) do
- etherflow.sendtensor(tensor[i])
- end
- else
- etherflow.sendtensor(tensor)
- end
- self:getFrame('copy-done')
+ self.ethernet:host_copyToDev(tensor)
self.profiler:lap('copy-to-dev')
end
----------------------------------------------------------------------
-- receive tensor
--
function NeuFlow:copyFromDev(tensor)
- etherflow.handshake(self.handshake)
profiler_neuflow = self.profiler:start('on-board-processing')
self.profiler:setColor('on-board-processing', 'blue')
- self:getFrame('copy-starting')
self.profiler:lap('on-board-processing')
self.profiler:start('copy-from-dev')
- local dims = tensor:nDimension()
- if dims == 3 then
- for i = 1,tensor:size(1) do
- etherflow.receivetensor(tensor[i])
- end
- else
- etherflow.receivetensor(tensor)
- end
+ self.ethernet:host_copyFromDev(tensor, self.handshake)
self.profiler:lap('copy-from-dev')
end
-
-----------------------------------------------------------------------
--- helper functions:
--- getFrame() receives a frame
--- parse_descriptor() parses the frame received
---
-function NeuFlow:getFrame(tag, type)
- local data
- data = etherflow.receivestring()
- if (data:sub(1,2) == type) then
- tag_received = parse_descriptor(data)
- end
- return (tag_received == tag)
-end
-
-function parse_descriptor(s)
- local reg_word = "%s*([-%w.+]+)%s*"
- local reg_pipe = "|"
- ni,j,type,tag,size,nb_frames = string.find(s, reg_word .. reg_pipe .. reg_word .. reg_pipe ..
- reg_word .. reg_pipe .. reg_word)
- return tag, type
-end

0 comments on commit 89b6874

Please sign in to comment.