Subject: [Ffc] Override cpp.format dictionary depending on -l parameter to ffc

From: Florian Rathgeber <[email-masked]>
Date: Mon, 02 Aug 2010 15:45:16 +0200

Hi,

I modified FFC to accept an additional option for the -l parameter to
output tensor tabulation code suitable for execution in a CUDA kernel on
the GPU. For that the indexing for coordinates, coefficients and the
element tensor needs to be changed since the data structures look
differently on the GPU (foremost they are flattened). The Jacobi
computations look differently as well due to the way coordinates are stored.

What I did was to provide a function override_gpu() in cpp.py that
updates the cpp.format dictionary to generate the correct index into the
data structures. This function is called at the beginning of
codegeneration.py:generate_code if the GPU target was specified by the
- -l parameter.

This works for tensor representation, but not functions values
(including coefficients) for quadrature, since the corresponding code is
generated by the class "QuadratureTransformerBase". I'm no Python
expert, but I assume the override of cpp.format on the global scope is
not visible inside the class scope.

Since "QuadratureTransformerBase" does not get the parameters, it cannot
know if the target is GPU and override_gpu() should be called.

My changes are more of a quick hack and certainly not a well-designed
way to solve this. I would be happy about suggestions both to quickly
fix the quadrature and also how to adapt the whole design to make it
more "clean" and straightforward.

(The corresponding wrapper code, which is different from the ordinary
DOLFIN wrapper code, is also generated depending on the -l option, but
that is a different topic, so I just mention it for the sake of
completeness)

I published my branch here:
https://code.launchpad.net/~florian-rathgeber/ffc/gpu-wrappers

Florian

---

From: Kristian Ølgaard <[email-masked]>
Date: Mon, 2 Aug 2010 16:08:45 +0200

On 2 August 2010 15:45, Florian Rathgeber
<[email-masked]> wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Hi,
>

It will be if you call override_gpu() in the representation stage
instead of the code generation stage.

> more "clean" and straightforward.

We handle the formatting of floats in a similar way so I don't think
the solution is too bad for now.

> that is a different topic, so I just mention it for the sake of

and the option is '-l dolfin-gpu' if anyone wonders.

Kristian

> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v2.0.12 (MingW32)
>
> iEYEARECAAYFAkxWy+wACgkQ8Z6llsctAxaqDACgsafJklBYddyOzjbcRP5NCSv1
> /2wAoKoXXkzgCN1xoTHKbKwChDEmmfky
> =OXKi
> -----END PGP SIGNATURE-----
>
>
> _______________________________________________
> Mailing list: https://launchpad.net/~ffc
> Post to     : [email-masked]
> Unsubscribe : https://launchpad.net/~ffc
> More help   : https://help.launchpad.net/ListHelp
>
>

---

From: Florian Rathgeber <[email-masked]>
Date: Mon, 02 Aug 2010 22:25:08 +0200

On 02.08.2010 16:08, Kristian Ølgaard wrote:
> -l parameter.

It does, thank you!

>> the solution is too bad for now.

OK, I guess I'll leave it like that for the moment.

>> and the option is '-l dolfin-gpu' if anyone wonders.

Right, I should have mentioned that.

Florian