util.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010,2011 University of Bordeaux
  4. * Copyright (C) 2016 CNRS
  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. #include "socl.h"
  18. #include "common/timing.h"
  19. int starpu_worker_get_range_by_id(int id) {
  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. int id = starpu_worker_get_id_check();
  27. return starpu_worker_get_range_by_id(id);
  28. }
  29. void * memdupa(const void *p, size_t size) {
  30. void * s = malloc(size);
  31. memcpy(s,p,size);
  32. return s;
  33. }
  34. void ** memdup_deep_safea(const void **p, unsigned n, size_t size) {
  35. void ** s = (void**)malloc(sizeof(void*) * n);
  36. unsigned i;
  37. for (i=0; i<n; i++) {
  38. s[i] = memdup_safe((void*)p[i], size);
  39. }
  40. return s;
  41. }
  42. void ** memdup_deep_varsize_safea(const void **p, unsigned n, size_t * size) {
  43. void ** s = (void**)malloc(sizeof(void*) * n);
  44. unsigned i;
  45. for (i=0; i<n; i++) {
  46. s[i] = memdup_safe((void*)p[i], size[i]);
  47. }
  48. return s;
  49. }
  50. cl_ulong _socl_nanotime() {
  51. struct timespec ts;
  52. _starpu_clock_gettime(&ts);
  53. return (ts.tv_sec * 1e9 + ts.tv_nsec);
  54. }