Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

graphicsmagick breaks torch matrix multiplication #21

Open
andreaskoepf opened this issue Sep 14, 2015 · 4 comments
Open

graphicsmagick breaks torch matrix multiplication #21

andreaskoepf opened this issue Sep 14, 2015 · 4 comments

Comments

@andreaskoepf
Copy link

andreaskoepf commented Sep 14, 2015

Sounds strange first but I have this phenomena on three different Ubuntu 14.04.3 LTS machines and it is perfectly reproductible on my side.

As soon as I load the graphicsmagick module torch matrix multiplications of larger tensors end in an endlessloop with 100% CPU:

torch.ones(100, 100) * torch.ones(100, 100) -- no problem
require 'graphicsmagick'
torch.ones(10, 10) * torch.ones(10, 10) -- no problem
torch.ones(100, 100) * torch.ones(100, 100) -- never returns [!]

Smaller tensor-multiplications (e.g. 10x10) interestingly even work after the require 'graphicsmagick' statement.

Could somebody please check whether this effect only occurs on Ubuntu machines?

@soumith
Copy link
Collaborator

soumith commented Sep 14, 2015

can verify that this:

  • happens on Ubuntu 14.04
  • does not happen in CentOS 6.6

@deltheil
Copy link
Contributor

It looks like this problem is related to the use of omp_set_dynamic in old GraphicsMagick versions, e.g. on Ubuntu 14.04 / GraphicsMagick 1.3.18:

    /*
      Enable the dynamic adjustment of the number of threads up to the
      value set by omp_set_num_threads(), but only if there is more
      than one thread available.
    */
    if (getenv("OMP_DYNAMIC") == NULL)
      omp_set_dynamic(max_threads > 1);

(see magick/resource.c - this is part of initializations performed by InitializeMagick())

It has been reverted in the meanwhile:

    * magick/resource.c (InitializeMagickResources): Revert use of
    omp_set_dynamic() since it caused a severe performance regression
    when doing a -stepthreads benchmark or when the number of OpenMP
    threads is set via OMP_NUM_THREADS.

So the solution is to use a recent GraphicsMagick version, or turn off this mode via export OMP_DYNAMIC=FALSE.

@andreaskoepf
Copy link
Author

andreaskoepf commented May 26, 2016

I just tried to reproduce the problem on my Ubuntu 14.04 machine without setting OMP_DYNAMIC=FALSE but the 100x100 matrix multiplication executed now without problems.

The installed libGraphicsMagickWand.so.2.6.0 is from Dec 2013:

lrwxrwxrwx 1 root root 30 Dec 22  2013 /usr/lib/libGraphicsMagickWand.so -> libGraphicsMagickWand.so.2.6.0

@deltheil
Copy link
Contributor

I reproduced the problem you reported on Ubuntu 14.04 with this exact version:

Dec 22  2013 /usr/lib/libGraphicsMagickWand.so.2.6.0

It corresponds to v1.3.18:

$ gm convert -version | head -n 1
GraphicsMagick 1.3.18 2013-03-10 Q8 http://www.GraphicsMagick.org/

And it was compiled with OpenMP support:

$ gm convert -version | grep -i openmp
  OpenMP                   yes (201107)
  CFLAGS   = -fopenmp

On this machine I verified that turning off the OMP_DYNAMIC mode solved the problem. On some other machines (Ubuntu 14.04, same GraphicsMagick version) I could not reproduce the problem for some reasons...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants