tips-tricks.texi 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. @c -*-texinfo-*-
  2. @c This file is part of the StarPU Handbook.
  3. @c Copyright (C) 2009--2011 Universit@'e de Bordeaux 1
  4. @c Copyright (C) 2010, 2011, 2012, 2013 Centre National de la Recherche Scientifique
  5. @c Copyright (C) 2011 Institut National de Recherche en Informatique et Automatique
  6. @c See the file starpu.texi for copying conditions.
  7. @menu
  8. * Per-worker library initialization:: How to initialize a computation library once for each worker?
  9. * Limit memory::
  10. * Thread Binding on NetBSD::
  11. @end menu
  12. @node Per-worker library initialization
  13. @section How to initialize a computation library once for each worker?
  14. Some libraries need to be initialized once for each concurrent instance that
  15. may run on the machine. For instance, a C++ computation class which is not
  16. thread-safe by itself, but for which several instanciated objects of that class
  17. can be used concurrently. This can be used in StarPU by initializing one such
  18. object per worker. For instance, the libstarpufft example does the following to
  19. be able to use FFTW.
  20. Some global array stores the instanciated objects:
  21. @cartouche
  22. @smallexample
  23. fftw_plan plan_cpu[STARPU_NMAXWORKERS];
  24. @end smallexample
  25. @end cartouche
  26. At initialisation time of libstarpu, the objects are initialized:
  27. @cartouche
  28. @smallexample
  29. int workerid;
  30. for (workerid = 0; workerid < starpu_worker_get_count(); workerid++) @{
  31. switch (starpu_worker_get_type(workerid)) @{
  32. case STARPU_CPU_WORKER:
  33. plan_cpu[workerid] = fftw_plan(...);
  34. break;
  35. @}
  36. @}
  37. @end smallexample
  38. @end cartouche
  39. And in the codelet body, they are used:
  40. @cartouche
  41. @smallexample
  42. static void fft(void *descr[], void *_args)
  43. @{
  44. int workerid = starpu_worker_get_id();
  45. fftw_plan plan = plan_cpu[workerid];
  46. ...
  47. fftw_execute(plan, ...);
  48. @}
  49. @end smallexample
  50. @end cartouche
  51. Another way to go which may be needed is to execute some code from the workers
  52. themselves thanks to @code{starpu_execute_on_each_worker}. This may be required
  53. by CUDA to behave properly due to threading issues. For instance, StarPU's
  54. @code{starpu_cublas_init} looks like the following to call
  55. @code{cublasInit} from the workers themselves:
  56. @cartouche
  57. @smallexample
  58. static void init_cublas_func(void *args STARPU_ATTRIBUTE_UNUSED)
  59. @{
  60. cublasStatus cublasst = cublasInit();
  61. cublasSetKernelStream(starpu_cuda_get_local_stream());
  62. @}
  63. void starpu_cublas_init(void)
  64. @{
  65. starpu_execute_on_each_worker(init_cublas_func, NULL, STARPU_CUDA);
  66. @}
  67. @end smallexample
  68. @end cartouche
  69. @node Limit memory
  70. @section How to limit memory per node
  71. TODO
  72. Talk about
  73. @code{STARPU_LIMIT_CUDA_devid_MEM}, @code{STARPU_LIMIT_CUDA_MEM},
  74. @code{STARPU_LIMIT_OPENCL_devid_MEM}, @code{STARPU_LIMIT_OPENCL_MEM}
  75. and @code{STARPU_LIMIT_CPU_MEM}
  76. @code{starpu_memory_get_available}
  77. @node Thread Binding on NetBSD
  78. @section Thread Binding on NetBSD
  79. When using StarPU on a NetBSD machine, if the topology
  80. discovery library @code{hwloc} is used, thread binding will fail. To
  81. prevent the problem, you should at least use the version 1.7 of
  82. @code{hwloc}, and also issue the following call:
  83. @example
  84. $ sysctl -w security.models.extensions.user_set_cpu_affinity=1
  85. @end example
  86. Or add the following line in the file @code{/etc/sysctl.conf}
  87. @example
  88. security.models.extensions.user_set_cpu_affinity=1
  89. @end example