util.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010,2011 University of Bordeaux
  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. int starpu_worker_get_range_by_id(int id) {
  18. int i, oid = 0;
  19. for (i=0; i<id; i++)
  20. if (starpu_worker_get_type(i) == STARPU_OPENCL_WORKER) oid++;
  21. return oid;
  22. }
  23. int starpu_worker_get_range() {
  24. int id = starpu_worker_get_id();
  25. return starpu_worker_get_range_by_id(id);
  26. }
  27. void * memdupa(const void *p, size_t size) {
  28. void * s = malloc(size);
  29. memcpy(s,p,size);
  30. return s;
  31. }
  32. void ** memdup_deep_safea(const void **p, unsigned n, size_t size) {
  33. void ** s = (void**)malloc(sizeof(void*) * n);
  34. unsigned i;
  35. for (i=0; i<n; i++) {
  36. s[i] = memdup_safe((void*)p[i], size);
  37. }
  38. return s;
  39. }
  40. void ** memdup_deep_varsize_safea(const void **p, unsigned n, size_t * size) {
  41. void ** s = (void**)malloc(sizeof(void*) * n);
  42. unsigned i;
  43. for (i=0; i<n; i++) {
  44. s[i] = memdup_safe((void*)p[i], size[i]);
  45. }
  46. return s;
  47. }
  48. cl_ulong _socl_nanotime() {
  49. struct timespec ts;
  50. clock_gettime(CLOCK_MONOTONIC, &ts);
  51. return (ts.tv_sec * 1e9 + ts.tv_nsec);
  52. }