util.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010-2020 Université de Bordeaux, CNRS (LaBRI UMR 5800), Inria
  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. #include "socl.h"
  17. #include "common/timing.h"
  18. int starpu_worker_get_range_by_id(int id)
  19. {
  20. int i, oid = 0;
  21. for (i=0; i<id; i++)
  22. if (starpu_worker_get_type(i) == STARPU_OPENCL_WORKER) oid++;
  23. return oid;
  24. }
  25. int starpu_worker_get_range()
  26. {
  27. int id = starpu_worker_get_id_check();
  28. return starpu_worker_get_range_by_id(id);
  29. }
  30. void * memdupa(const void *p, size_t size)
  31. {
  32. void * s = malloc(size);
  33. memcpy(s,p,size);
  34. return s;
  35. }
  36. void ** memdup_deep_safea(const void **p, unsigned n, size_t size)
  37. {
  38. void ** s = (void**)malloc(sizeof(void*) * n);
  39. unsigned i;
  40. for (i=0; i<n; i++)
  41. {
  42. s[i] = memdup_safe((void*)p[i], size);
  43. }
  44. return s;
  45. }
  46. void ** memdup_deep_varsize_safea(const void **p, unsigned n, size_t * size)
  47. {
  48. void ** s = (void**)malloc(sizeof(void*) * n);
  49. unsigned i;
  50. for (i=0; i<n; i++)
  51. {
  52. s[i] = memdup_safe((void*)p[i], size[i]);
  53. }
  54. return s;
  55. }
  56. cl_ulong _socl_nanotime()
  57. {
  58. struct timespec ts;
  59. _starpu_clock_gettime(&ts);
  60. return (ts.tv_sec * 1e9 + ts.tv_nsec);
  61. }