Subject: [Instant-dev] Slow memory cache?

From: Anders Logg <[email-masked]>
Date: Thu, 11 Sep 2008 15:42:00 +0200

I'm still struggling with getting good performance from the in-memory
cache in Instant.

Below are the results for the JIT benchmark in bench/fem/jit in DOLFIN.

When using only the caching provided by Instant, the results are

  Disk cache:      0.552037000656
  In-memory cache: 0.551201319695

But when I turn on the internal FFC cache, I get

  Disk cache:      0.556658029556
  In-memory cache: 0.00709209442139

The speedup is a factor 80. To run the benchmark with or without the
FFC cache, change the variable use_ffc_cache in jit.py in FFC.

I have printed out some debugging in cache.py in Instant and it seems
that the in-memory cache is being used (not the disk cache).

-- 
Anders

---

From: "Martin Sandve Alnæs" <[email-masked]>
Date: Thu, 11 Sep 2008 15:47:37 +0200

Have you added __hash__ and __eq__ or __cmp__ functions to your jit
object class? If not, the memory cache may not work as expected.

-- 
Martin

2008/9/11 Anders Logg <[email-masked]>:
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.6 (GNU/Linux)
>
> iD8DBQFIySAoTuwUCDsYZdERAm6dAJ9lRJinzVE8S2ywfTvXHwUYFcx/6wCfdr8B
> 1n19Q3HHv1jU/65njM0R39A=
> =PXoq
> -----END PGP SIGNATURE-----
>
> _______________________________________________
> Instant-dev mailing list
> [email-masked]
> http://fenics.org/mailman/listinfo/instant-dev
>
>

---

From: Anders Logg <[email-masked]>
Date: Thu, 11 Sep 2008 15:52:43 +0200

> object class? If not, the memory cache may not work as expected.

I have added _hash_. What should __eq__ return?

-- 
Anders

---

From: "Martin Sandve Alnæs" <[email-masked]>
Date: Thu, 11 Sep 2008 16:11:11 +0200

> I have added _hash_. What should __eq__ return?

Equality with other object, True or False. Hashmaps do not actually
require unique hash keys, so objects with the same hash may be
different. __cmp__ returns -1, 0 or +1 meaning self<other,
self==other, self>other. Don't implement both.

--
Martin

---

From: Anders Logg <[email-masked]>
Date: Thu, 11 Sep 2008 16:19:45 +0200

> self==other, self>other. Don't implement both.

Didn't help.

Could you add some print statement in Instant temporarily that shouts
when the in-memory cache is being used?

-- 
Anders

---

From: "Martin Sandve Alnæs" <[email-masked]>
Date: Thu, 11 Sep 2008 18:27:29 +0200

Answering your previous question about verbosity, try
    instant.set_logging_level("debug")

also, you can do:
    instant.set_logging_level("info")
    instant.set_logging_level("warning")
    instant.set_logging_level("error")

Also, take a look at the test test19.py which
demonstrates that the memory cache does work.

-- 
Martin

2008/9/11 Anders Logg <[email-masked]>:
> iD8DBQFIySkBTuwUCDsYZdERAk91AJ0cIFvyJgMv8XPpn9HY8mNuL8VW0gCfWy6I
> wVix/JqeaB8zbiAaY/iUq5E=
> =vkp0

---

From: "Martin Sandve Alnæs" <[email-masked]>
Date: Thu, 11 Sep 2008 18:51:31 +0200

It's not Instant that uses this time, you have some other bug:

--- Calling FFC JIT compiler ---
instant.import_module time: 0.330512046814
Assembling matrix over cells (finished).
TIME IS 0.335214853287
Assembly # 0

--- Calling FFC JIT compiler ---
instant.import_module time: 0.000116109848022
Assembling matrix over cells (finished).
TIME IS 0.333696126938
Assembly # 1

--- Calling FFC JIT compiler ---
instant.import_module time: 0.0001220703125
Assembling matrix over cells (finished).
TIME IS 0.331577062607

-- 
Martin

---

From: "Martin Sandve Alnæs" <[email-masked]>
Date: Thu, 11 Sep 2008 18:53:22 +0200

You're calling jitobject.signature() in extract_form.

-- 
Martin

---

From: Anders Logg <[email-masked]>
Date: Thu, 11 Sep 2008 20:05:51 +0200

> You're calling jitobject.signature() in extract_form.

Thanks! I did this since I needed to know the name of the form to
extract from the module, but it worked fine to use module.__name__.

It works fine now. Here are timings with and without the FFC cache:

  Disk cache:      0.552545070648
  In-memory cache: 0.00687968730927

  Disk cache:      0.555771112442
  In-memory cache: 0.00716300010681

The difference is 4% and the time is less than 0.01 seconds so I'm
removing the FFC cache. Some of the difference is extra calls needed
in the JIT compiler to extract the form from the module so Instant
accounts only for part of the difference, I don't know how much.

In conclusion, FFC and Instant work fine now and the JIT code in FFC
is short and neat.

-- 
Anders

---

From: "Martin Sandve Alnæs" <[email-masked]>
Date: Thu, 11 Sep 2008 22:06:53 +0200

Instant has quite a few assertions now, compared to the memory cache
it may take a little time.

-- 
Martin

2008/9/11 Anders Logg <[email-masked]>:
> iD8DBQFIyV3+TuwUCDsYZdERApq5AJ9fhOsIWM5kra8b1bIGDBjLWe7jSACeNqfV
> O3ZhobvuEVWjkVUUM/vlQjM=
> =ysyv