memory_nodes.h 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009, 2010 Université de Bordeaux 1
  4. * Copyright (C) 2010 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. typedef enum {
  24. STARPU_UNUSED = 0x00,
  25. STARPU_CPU_RAM = 0x01,
  26. STARPU_CUDA_RAM = 0x02,
  27. STARPU_OPENCL_RAM = 0x03,
  28. STARPU_SPU_LS = 0x04
  29. } starpu_node_kind;
  30. typedef starpu_node_kind starpu_memory_node_tuple;
  31. #define _STARPU_MEMORY_NODE_TUPLE(node1,node2) (node1 | (node2 << 4))
  32. #define _STARPU_MEMORY_NODE_TUPLE_FIRST(tuple) (tuple & 0x0F)
  33. #define _STARPU_MEMORY_NODE_TUPLE_SECOND(tuple) (tuple & 0xF0)
  34. struct _cond_and_mutex {
  35. pthread_cond_t *cond;
  36. pthread_mutex_t *mutex;
  37. };
  38. typedef struct {
  39. unsigned nnodes;
  40. starpu_node_kind nodes[STARPU_MAXNODES];
  41. /* Get the device id associated to this node, or -1 if not applicable */
  42. int devid[STARPU_MAXNODES];
  43. // TODO move this 2 lists outside starpu_mem_node_descr
  44. /* Every worker is associated to a condition variable on which the
  45. * worker waits when there is task available. It is possible that
  46. * multiple worker share the same condition variable, so we maintain a
  47. * list of all these condition variables so that we can wake up all
  48. * worker attached to a memory node that are waiting on a task. */
  49. pthread_rwlock_t conditions_rwlock;
  50. struct _cond_and_mutex conditions_attached_to_node[STARPU_MAXNODES][STARPU_NMAXWORKERS];
  51. struct _cond_and_mutex conditions_all[STARPU_MAXNODES*STARPU_NMAXWORKERS];
  52. /* the number of queues attached to each node */
  53. unsigned total_condition_count;
  54. unsigned condition_count[STARPU_MAXNODES];
  55. } starpu_mem_node_descr;
  56. void _starpu_init_memory_nodes(void);
  57. void _starpu_deinit_memory_nodes(void);
  58. void _starpu_set_local_memory_node_key(unsigned *node);
  59. unsigned _starpu_get_local_memory_node(void);
  60. unsigned _starpu_register_memory_node(starpu_node_kind kind, int devid);
  61. //void _starpu_memory_node_attach_queue(struct starpu_jobq_s *q, unsigned nodeid);
  62. void _starpu_memory_node_register_condition(pthread_cond_t *cond, pthread_mutex_t *mutex, unsigned memory_node);
  63. starpu_node_kind _starpu_get_node_kind(uint32_t node);
  64. int starpu_memory_node_to_devid(unsigned node);
  65. unsigned _starpu_get_memory_nodes_count(void);
  66. starpu_mem_node_descr *_starpu_get_memory_node_description(void);
  67. #endif // __MEMORY_NODES_H__