Hi,

Consider the follow trying to do matrix multiplication

proc gemm2(t : [?tD] ?R, u : [?uD], v : [?vD] R, unroll : int)
{
    const (rows, columns) = tD.dims();
    const (_, common) = uD.dims();
    const n = columns.last;
    const S = (1 << unroll) - 1;

    for c in columns by (S+1) do
    {
        const cfinal = if c + S > n then n else c + S;
        const cslice = c .. cfinal;
        var vslab : [cslice, common] R;

        // transpose those nasty columns into rows!

        [j in common] vslab[cslice, j] = v[j, cslice];

        // rip through every single row
        // should this be blocked better?

        forall r in rows do
        {
            const ref ur = u[r, ..];

            for j in cslice do
            {
                t[r, j] = vmDot(common, ur, vslab[j, ..]);
            }
        }
    } }

where vmDot(r, x, y) returns the dot product of two 1D-arrays 'x' & 'y' across the index range 'r'.

It works:

But, on changing the last loop, this

        forall r in rows do
        {
            const ref ur = u[r, ..];
            const x = [j in cslice] vmDot(common, ur, vslab[j, ..]);

            t[r, cslice] = x;
        }

slows down slightly, about 5+%. On the other hand, the more concise

        forall r in rows do
        {
            const x = [j in cslice] vmDot(common, u[r, ..], vslab[j, ..]);

            t[r, cslice] = x;
        }

slows down seriously, about 25+%.

I am curious on what is going on here just so I know what is an optimal
approach.

Let me know if you want the test code.

Has any research work been done on an optimal GEMM in Chapel and if so, is it been documented anyway.

Regards - Damian

Pacific Engineering Systems International, 277-279 Broadway, Glebe NSW 2037
Ph:+61-2-8571-0847 .. Fx:+61-2-9692-9623 | unsolicited email not wanted here
Views & opinions here are mine and not those of any past or present employer


_______________________________________________
Chapel-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/chapel-developers

Reply via email to