Browse Source

- provide a fallback implementation for omp atomic

Olivier Aumage 11 years ago
parent
commit
dee166f9f9
3 changed files with 37 additions and 0 deletions
  1. 2 0
      include/starpu_openmp.h
  2. 32 0
      src/util/openmp_runtime_support.c
  3. 3 0
      src/util/openmp_runtime_support.h

+ 2 - 0
include/starpu_openmp.h

@@ -154,6 +154,8 @@ extern void starpu_omp_destroy_nest_lock (starpu_omp_nest_lock_t *lock) __STARPU
 extern void starpu_omp_set_nest_lock (starpu_omp_nest_lock_t *lock) __STARPU_OMP_NOTHROW;
 extern void starpu_omp_unset_nest_lock (starpu_omp_nest_lock_t *lock) __STARPU_OMP_NOTHROW;
 extern int starpu_omp_test_nest_lock (starpu_omp_nest_lock_t *lock) __STARPU_OMP_NOTHROW;
+extern void starpu_omp_atomic_fallback_start(void) __STARPU_OMP_NOTHROW;
+extern void starpu_omp_atomic_fallback_end(void) __STARPU_OMP_NOTHROW;
 extern double starpu_omp_get_wtime (void) __STARPU_OMP_NOTHROW;
 extern double starpu_omp_get_wtick (void) __STARPU_OMP_NOTHROW;
 

+ 32 - 0
src/util/openmp_runtime_support.c

@@ -193,15 +193,34 @@ static struct starpu_omp_device *create_omp_device_struct(void)
 	if (device == NULL)
 		_STARPU_ERROR("memory allocation failed");
 	memset(device, 0, sizeof(*device));
+	_starpu_spin_init(&device->atomic_lock);
 	return device;
 }
 
 static void destroy_omp_device_struct(struct starpu_omp_device *device)
 {
+	_starpu_spin_destroy(&device->atomic_lock);
 	memset(device, 0, sizeof(*device));
 	free(device);
 }
 
+static struct starpu_omp_device *get_caller_device(void)
+{
+	struct starpu_omp_task *task = _starpu_omp_get_task();
+	struct starpu_omp_device *device;
+	if (task)
+	{
+		STARPU_ASSERT(task->owner_region != NULL);
+		device = task->owner_region->owner_device;
+	}
+	else
+	{
+		device = _global_state.initial_device;
+	}
+	STARPU_ASSERT(device != NULL);
+	return device;
+}
+
 static struct starpu_omp_region *create_omp_region_struct(struct starpu_omp_region *parent_region, struct starpu_omp_device *owner_device)
 {
 	struct starpu_omp_region *region = malloc(sizeof(*region));
@@ -2220,6 +2239,19 @@ int starpu_omp_test_nest_lock (starpu_omp_nest_lock_t *nest_lock)
 	return _starpu_omp_nest_lock_test(&nest_lock->internal);
 }
 
+void starpu_omp_atomic_fallback_start(void)
+{
+	struct starpu_omp_device *device = get_caller_device();
+	_starpu_spin_lock(&device->atomic_lock);
+
+}
+
+void starpu_omp_atomic_fallback_end(void)
+{
+	struct starpu_omp_device *device = get_caller_device();
+	_starpu_spin_unlock(&device->atomic_lock);
+}
+
 /*
  * restore deprecated diagnostics (-Wdeprecated-declarations)
  */

+ 3 - 0
src/util/openmp_runtime_support.h

@@ -329,6 +329,9 @@ struct starpu_omp_region
 struct starpu_omp_device
 {
 	struct starpu_omp_device_icvs icvs;
+
+	/* atomic fallback implementation lock */
+	struct _starpu_spinlock atomic_lock;
 };
 
 struct starpu_omp_global