Subject: [Instant-dev] Timing of in-memory cache

From: "Martin Sandve Alnæs" <[email-masked]>
Date: Fri, 5 Sep 2008 10:50:37 +0200

I've added a test that times the cache mechanism, using
a signature object that sleeps for a second in sig.signature()
and half a second in sig.__hash__().
It's called test18.py. Seems to me that the cache works fine.

--
Martin

---

From: Anders Logg <[email-masked]>
Date: Sat, 6 Sep 2008 12:44:05 +0200

> It's called test18.py. Seems to me that the cache works fine.

ok, nice. I'll try to test it for FFC.

There is a benchmark in bench/fem/jit/ in DOLFIN which I use for
testing. It runs more than 100 times faster, maybe 1000 - I didn't
even wait for it to finish, with the in-memory cache (in FFC) than
without it (using the disk cache).

-- 
Anders

---

From: Anders Logg <[email-masked]>
Date: Sat, 6 Sep 2008 14:12:19 +0200

> It's called test18.py. Seems to me that the cache works fine.

I can't get it to work, but maybe I'm using it wrong.

I'm running the bench/fem/jit/ test script in DOLFIN with the current
version of FFC (just pushed) and I always get the following:

--- Calling FFC JIT compiler ---
1. Module returned by import_module:  None
2. Calling FFC just-in-time (JIT) compiler, this may take some time... done
3. Creating Python extension (compiling and linking), this may take some time... done
Assembling matrix over cells (finished).

In step (1), Instant always returns None when calling import_module().
I assume this means that the module was not found, neither in the
in-memory cache nor disk cache.

Since it returns None, FFC generates code in step (2). This takes a
second or two.

Then in step (3), FFC sends the generated code to build_module(). This
goes surprisingly fast, so it seem Instant must return something from
cache.

So, something strange is going on, both in step (1) and (3). Here's
the code for FFC's jit() which is now very short:

    # Check options
    options = check_options(input_form, options)

    # Wrap input
    jit_object = wrap(input_form, options)

    # Check cache
    module = instant.import_module(jit_object)
    print "Module returned by import_module: ", module

    # Compile form
    debug("Calling FFC just-in-time (JIT) compiler, this may take some  time...", -1)
    signature = jit_object.signature()
    compile(input_form, signature, options)
    debug("done", -1)

    # Wrap code into a Python module using Instant
    debug("Creating Python extension (compiling and linking), this may take some time...", -1)
    filename = signature + ".h"
    (cppargs, path, ufc_include) = extract_instant_flags(options)
    module = instant.build_module(wrap_headers=[filename],
                                  additional_declarations=ufc_include,
                                  include_dirs=path,
                                  cppargs=cppargs,
                                  signature=signature)
    debug("done", -1)

    # Extract form
    exec("compiled_form = module.%s()" % signature)

Can you spot something wrong?

-- 
Anders

---

From: "Martin Sandve Alnæs" <[email-masked]>
Date: Sat, 6 Sep 2008 14:29:21 +0200

> Can you spot something wrong?

No... I'll try to run it.

>    exec("compiled_form = module.%s()" % signature)

This is clearer:

    compiled_form = getattr(module, signature)()

--
Martin

---

From: Anders Logg <[email-masked]>
Date: Sat, 6 Sep 2008 14:38:40 +0200

> No... I'll try to run it.

Thanks.

>     compiled_form = getattr(module, signature)()

ok, I didn't know that was possible.

-- 
Anders

---

From: "Martin Sandve Alnæs" <[email-masked]>
Date: Sat, 6 Sep 2008 15:30:48 +0200

1) You should send jitobject as the signature to build_module.
2) Your jitobject doesn't implement __hash__, the only thing dict will
use then is the object id.

I don't know how to best compute an efficient hash value here.

--
Martin

2008/9/6 Anders Logg <[email-masked]>:
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.6 (GNU/Linux)
>
> iD8DBQFIwnnPTuwUCDsYZdERAhQ5AJ0WWUitJnkA5NDNyivR3o4U+kAXaQCfTSI0
> izIg7cCMcrHkpmra6jffoB4=
> =tNNj
> -----END PGP SIGNATURE-----
>
>