data_lookup.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011 Institut National de Recherche en Informatique et Automatique
  4. *
  5. * StarPU is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU Lesser General Public License as published by
  7. * the Free Software Foundation; either version 2.1 of the License, or (at
  8. * your option) any later version.
  9. *
  10. * StarPU is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. *
  14. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  15. */
  16. #undef NDEBUG
  17. #include <assert.h>
  18. #include <starpu.h>
  19. #include <stdlib.h>
  20. #include <sys/types.h>
  21. #include <stdio.h>
  22. #define VECTOR_COUNT 12
  23. #define VARIABLE_COUNT 42
  24. #define VECTOR_SIZE 123
  25. int main(int argc, char *argv[])
  26. {
  27. int err;
  28. size_t i;
  29. void *vectors[VECTOR_COUNT], *variables[VARIABLE_COUNT];
  30. starpu_data_handle vector_handles[VECTOR_COUNT];
  31. starpu_data_handle variable_handles[VARIABLE_COUNT];
  32. starpu_init(NULL);
  33. /* Register data regions. */
  34. for(i = 0; i < VARIABLE_COUNT; i++)
  35. {
  36. err = starpu_malloc(&variables[i], sizeof(float));
  37. assert(err == 0);
  38. starpu_variable_data_register(&variable_handles[i], 0,
  39. (uintptr_t)variables[i],
  40. sizeof(float));
  41. }
  42. for(i = 0; i < VECTOR_COUNT; i++)
  43. {
  44. err = starpu_malloc(&vectors[i], VECTOR_SIZE * sizeof(float));
  45. assert(err == 0);
  46. starpu_vector_data_register(&vector_handles[i], 0,
  47. (uintptr_t)vectors[i],
  48. VECTOR_SIZE, sizeof(float));
  49. }
  50. /* Look them up. */
  51. for(i = 0; i < VARIABLE_COUNT; i++)
  52. {
  53. starpu_data_handle handle;
  54. handle = starpu_data_lookup(variables[i]);
  55. assert(handle == variable_handles[i]);
  56. }
  57. for(i = 0; i < VECTOR_COUNT; i++)
  58. {
  59. starpu_data_handle handle;
  60. handle = starpu_data_lookup(vectors[i]);
  61. assert(handle == vector_handles[i]);
  62. }
  63. /* Unregister them. */
  64. for(i = 0; i < VARIABLE_COUNT; i++)
  65. {
  66. starpu_data_unregister(variable_handles[i]);
  67. }
  68. for(i = 0; i < VECTOR_COUNT; i++)
  69. {
  70. starpu_data_unregister(vector_handles[i]);
  71. }
  72. /* Make sure we can no longer find them. */
  73. for(i = 0; i < VARIABLE_COUNT; i++)
  74. {
  75. starpu_data_handle handle;
  76. handle = starpu_data_lookup(variables[i]);
  77. assert(handle == NULL);
  78. starpu_free(variables[i]);
  79. }
  80. for(i = 0; i < VECTOR_COUNT; i++)
  81. {
  82. starpu_data_handle handle;
  83. handle = starpu_data_lookup(vectors[i]);
  84. assert(handle == NULL);
  85. starpu_free(vectors[i]);
  86. }
  87. starpu_shutdown();
  88. return EXIT_SUCCESS;
  89. }