memory_nodes.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009-2011 Université de Bordeaux 1
  4. * Copyright (C) 2010, 2011 Centre National de la Recherche Scientifique
  5. *
  6. * StarPU is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as published by
  8. * the Free Software Foundation; either version 2.1 of the License, or (at
  9. * your option) any later version.
  10. *
  11. * StarPU is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. *
  15. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  16. */
  17. #ifndef __MEMORY_NODES_H__
  18. #define __MEMORY_NODES_H__
  19. #include <starpu.h>
  20. #include <common/config.h>
  21. #include <datawizard/coherency.h>
  22. #include <datawizard/memalloc.h>
  23. #define _STARPU_MEMORY_NODE_TUPLE(node1,node2) (node1 | (node2 << 4))
  24. #define _STARPU_MEMORY_NODE_TUPLE_FIRST(tuple) (tuple & 0x0F)
  25. #define _STARPU_MEMORY_NODE_TUPLE_SECOND(tuple) (tuple & 0xF0)
  26. struct _starpu_cond_and_mutex
  27. {
  28. pthread_cond_t *cond;
  29. pthread_mutex_t *mutex;
  30. };
  31. struct _starpu_mem_node_descr
  32. {
  33. unsigned nnodes;
  34. enum starpu_node_kind nodes[STARPU_MAXNODES];
  35. /* Get the device id associated to this node, or -1 if not applicable */
  36. int devid[STARPU_MAXNODES];
  37. unsigned nworkers[STARPU_MAXNODES];
  38. // TODO move this 2 lists outside struct _starpu_mem_node_descr
  39. /* Every worker is associated to a condition variable on which the
  40. * worker waits when there is task available. It is possible that
  41. * multiple worker share the same condition variable, so we maintain a
  42. * list of all these condition variables so that we can wake up all
  43. * worker attached to a memory node that are waiting on a task. */
  44. pthread_rwlock_t conditions_rwlock;
  45. struct _starpu_cond_and_mutex conditions_attached_to_node[STARPU_MAXNODES][STARPU_NMAXWORKERS];
  46. struct _starpu_cond_and_mutex conditions_all[STARPU_MAXNODES*STARPU_NMAXWORKERS];
  47. /* the number of queues attached to each node */
  48. unsigned total_condition_count;
  49. unsigned condition_count[STARPU_MAXNODES];
  50. };
  51. void _starpu_init_memory_nodes(void);
  52. void _starpu_deinit_memory_nodes(void);
  53. void _starpu_set_local_memory_node_key(unsigned *node);
  54. unsigned _starpu_get_local_memory_node(void);
  55. void _starpu_memory_node_worker_add(unsigned node);
  56. unsigned _starpu_memory_node_workers(unsigned node);
  57. unsigned _starpu_register_memory_node(enum starpu_node_kind kind, int devid);
  58. //void _starpu_memory_node_attach_queue(struct starpu_jobq_s *q, unsigned nodeid);
  59. void _starpu_memory_node_register_condition(pthread_cond_t *cond, pthread_mutex_t *mutex, unsigned memory_node);
  60. enum starpu_node_kind _starpu_node_get_kind(uint32_t node);
  61. int _starpu_memory_node_to_devid(unsigned node);
  62. struct _starpu_mem_node_descr *_starpu_get_memory_node_description(void);
  63. #endif // __MEMORY_NODES_H__