bh107 / bohrium

Automatic parallelization of Python/NumPy, C, and C++ codes on Linux and MacOSX
http://www.bh107.org
Apache License 2.0
220 stars 31 forks source link

Setting BH_OPENMP_CACHE_DIR to empty string does not disable cache #602

Closed dionhaefner closed 5 years ago

dionhaefner commented 5 years ago

My config.ini says:

[openmp]
# Directory for cache files (persistent between executions). Default: the empty string, which disable the cache
cache_dir = /Users/dion/.local/var/bohrium/cache

Following the comment, I thought the following would disable the cache:

$ export BH_OPENMP_CACHE_DIR=""

Running the following example proves it doesn't:


bh_test.py

import bohrium as bh

a = bh.random.rand(100, 100)
print(a.sum())

$ BH_OPENMP_CACHE_DIR="" BH_OPENMP_PROF=1 python bh_test.py
5033.204504649353
[OpenMP] Profiling:
Fuse cache hits:                 1/3 (33.3333%)
Codegen cache hits:              0/1 (0%)
Compilation cache hits:          1/1 (100%)
Array contractions:              3/5 (60%)
Outer-fusion ratio:              3/8 (37.5%)
Malloc cache hits:               0/2 (0%)

Max memory usage:                0 MB
Syncs to NumPy:                  1
Total Work:                      30100 operations
Throughput:                      1.61991e+06ops
Work below par-threshold (1000): 0%

Wall clock:                      0.0185813s
Total Execution:                 0.001648s
  Pre-fusion:                    4.458e-05s
  Fusion:                        0.000108358s
  Codegen:                       8.5194e-05s
  Compilation:                   0.000687838s
  Exec:                          0.000548015s
  Copy2dev:                      0s
  Copy2host:                     0s
  Offload:                       0s
  Other:                         0.000174012s
Ext-method:                      0s

Unaccounted for (wall - total):  0.0169333s

(cache was hit as evident from Compilation cache hits: 1/1 (100%))

In contrast, this does move the cache correctly:

$ BH_OPENMP_CACHE_DIR="somedir" BH_OPENMP_PROF=1 python bh_test.py
4966.78060921937
[OpenMP] Profiling:
Fuse cache hits:                 1/3 (33.3333%)
Codegen cache hits:              0/1 (0%)
Compilation cache hits:          0/1 (0%)
Array contractions:              3/5 (60%)
Outer-fusion ratio:              3/8 (37.5%)
Malloc cache hits:               0/2 (0%)

Max memory usage:                0 MB
Syncs to NumPy:                  1
Total Work:                      30100 operations
Throughput:                      91890.1ops
Work below par-threshold (1000): 0%

Wall clock:                      0.327565s
Total Execution:                 0.30581s
  Pre-fusion:                    4.1762e-05s
  Fusion:                        0.000103344s
  Codegen:                       8.3128e-05s
  Compilation:                   0.304814s
  Exec:                          0.000578001s
  Copy2dev:                      0s
  Copy2host:                     0s
  Offload:                       0s
  Other:                         0.000189902s
Ext-method:                      0s

Unaccounted for (wall - total):  0.0217554s

but I have no idea where the newly created cache goes:

$ ls somedir
ls: somedir: No such file or directory
madsbk commented 5 years ago

It is because export BH_OPENMP_CACHE_DIR="" unset the BH_OPENMP_CACHE_DIR environment variable, which makes Bohrium use the value in the config.ini.

Maybe we should use a keyword instead of the empty string like: BH_OPENMP_CACHE_DIR=NONE