[colorforth] SEAForth questions again
- Subject: [colorforth] SEAForth questions again
- From: John Drake <jmdrake_98@xxxxxxxxx>
- Date: Fri, 3 Nov 2006 13:31:52 -0800 (PST)
I've been trying to write my first SEAForth demo.
To try and exploit the parrallelism I settled on
matrix multiplication as a test program.
I'm trying to multiply a 2 row matrix by a two
column matrix. These are the steps I'm attempting.
1) Data initially is in node 12
2) Row1 is passed to node 18
3) Row2 is passed to node 13
4) Column1 is passed to nodes 18 and 13
simultaneously
5) Multiplications R1*C1 and R2*C1 done
simultaneously
6) Column2 is passed to nodes 18 and 13
simultaneously
7) Multiplications R1*C2 and R2*C2 done
simultaneously
8) Results R1*C1, R1*C2, R2*C1, R2*C2 are
returned to node 12
I looked at the code runvmram.f as an
example. It uses these steps.
1) Data initially in node 12
2) Data passed through node 13 to node 14
3) Node 14 does a difference between the
previous and current data value and passes
result to node 15
4) Node 15 does a "running average" and passes
result to node 16
5) Node 16 "catches" the data into a buffer
Here's my first question. The following code
is from node 14.
\ ******* node 14 ********************
\ differentiator
\ pass "difference" between current and
\ previous to the next node
decimal
14 node !
0 org
machine
'--l- a! . . \ point reg a to left node
'r--- b! . . \ point reg b to right node
dup xor \ init t to zero
begin
@a over over . ( curr prev curr )
+ not ( c c-p ) !b . ( c ) \ will become p
4 drop . .
again
The "+ not" would seem to me to return the
value -(c+p) rather than (c-p). Am I missing
something here? (This isn't essential to my
problem, but I'm just trying to understand the
code.)
Anyway, here's my own code. (Note: for the
sake of brevity I'm only including code for
nodes 12 and 13 as node 18 is a clone of
node 13's code.)
\ ******* node 12 *************************
\ Pass row1 to node 13, row2 to node 18
\ and columns 1 and 2 to nodes 13 and 18
\ simultaneously
decimal
12 node!
$0 org
machine
: send-data
begin
'r--- b! . . \ point reg b to right node
7 for
@p+ !b . unext
[ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , ]
'-d-- b! . . \ point reg b to down node
7 for
@p+ !b . unext
[ 9 , 10 , 11 , 12 , 13 , 14 , 15 , 16 , ]
'rd-- b! \ point reg b to r and d nodes
0 !b . . \ dummy write for synch purposes
15 for
@p+ !b . unext
[ 17 , 18 , 19 , 20 , 21 , 22 , 23 , 24 ,
25 , 26 , 27 , 28 , 29 , 30 , 31 , 32 , ]
$20 a! 'r--- b!
@b !a+ @b !a+
'-d-- b! . .
@b !a+ @b !a+
again
[
\ ******* node 13 *****************************
\ Receive row1 then multiply it by columns 1 and 2
\ and return results.
decimal
13 node !
0 org
machine
'r--- b! . . \ point b to right node
$20 dup a! push \ point a to buffer - push adr
7 for
@b !a+ . unext
@b drop . . \ dummy read for synchronization purposes
pop dup a! push \ reset a to start of buffer
dup xor \ initilize TOS to 0
7 for
@b @a+ f*f .
+ next . .
dup dup xor . \ preserve result: 0 TOS
pop a! . . \ reset a to start of buffer
7 for
@b @a+ f*f .
+ next . .
!b !b . . \ Send results back to r node
Now for my next question. After running this I
didn't get correct results. I'm not sure I'm
using f*f correctly. I put the following test
code in.
\ ******* node 23 **********************
\ Test multiplication
decimal
23 node !
0 org
machine
2 5 f*f .
But the end result was:
23
0 .
a=00000
b=155
p=005
r=15555
t=00000
s=15555
That can't be right. So I'm wondering what I'm
doing wrong? Here is a link to my entire sourcefile
so someone else can look at this.
http://www.quartus.net/twiki/pub/Main/VentureForth/matrix.f
Note that in order to run this you have to change
the rombios.f file. By default only nodes 18 and
23 have the f*f word compiled. I copied and
pasted that to node 13.
Other than problems with f*f my code seems to
work correctly. It's interesting to watch the
processors activate-deactivate and to see stuff
running in parrallel. While this is a trivial
example, I did have to deal with solving
deadlock and race conditions. I think the
VentureForth environment is very helpful for
immediately spotting such things.
Regards,
John M. Drake
____________________________________________________________________________________
Get your email and see which of your friends are online - Right on the New Yahoo.com
(http://www.yahoo.com/preview)
---------------------------------------------------------------------
To unsubscribe, e-mail: colorforth-unsubscribe@xxxxxxxxxxxxxxxxxx
For additional commands, e-mail: colorforth-help@xxxxxxxxxxxxxxxxxx
Main web page - http://www.colorforth.com