util.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011-2012 Inria
  4. * Copyright (C) 2012,2015-2017 CNRS
  5. * Copyright (C) 2010-2011,2013 Université de Bordeaux
  6. *
  7. * StarPU is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU Lesser General Public License as published by
  9. * the Free Software Foundation; either version 2.1 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * StarPU is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. *
  16. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  17. */
  18. #include "socl.h"
  19. #include "common/timing.h"
  20. int starpu_worker_get_range_by_id(int id)
  21. {
  22. int i, oid = 0;
  23. for (i=0; i<id; i++)
  24. if (starpu_worker_get_type(i) == STARPU_OPENCL_WORKER) oid++;
  25. return oid;
  26. }
  27. int starpu_worker_get_range()
  28. {
  29. int id = starpu_worker_get_id_check();
  30. return starpu_worker_get_range_by_id(id);
  31. }
  32. void * memdupa(const void *p, size_t size)
  33. {
  34. void * s = malloc(size);
  35. memcpy(s,p,size);
  36. return s;
  37. }
  38. void ** memdup_deep_safea(const void **p, unsigned n, size_t size)
  39. {
  40. void ** s = (void**)malloc(sizeof(void*) * n);
  41. unsigned i;
  42. for (i=0; i<n; i++)
  43. {
  44. s[i] = memdup_safe((void*)p[i], size);
  45. }
  46. return s;
  47. }
  48. void ** memdup_deep_varsize_safea(const void **p, unsigned n, size_t * size)
  49. {
  50. void ** s = (void**)malloc(sizeof(void*) * n);
  51. unsigned i;
  52. for (i=0; i<n; i++)
  53. {
  54. s[i] = memdup_safe((void*)p[i], size[i]);
  55. }
  56. return s;
  57. }
  58. cl_ulong _socl_nanotime()
  59. {
  60. struct timespec ts;
  61. _starpu_clock_gettime(&ts);
  62. return (ts.tv_sec * 1e9 + ts.tv_nsec);
  63. }