From 0c6c73b951f85bb6455eb4f8ac97adc6c93e0296 Mon Sep 17 00:00:00 2001 From: David Hilvert Date: Mon, 24 Aug 2009 03:06:18 +0000 Subject: [PATCH] src/libale: Initial implementation of C(), obtaining context from an ALE_POINTER. --- src/libale.h | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/src/libale.h b/src/libale.h index c87ae6a..98e21d0 100644 --- a/src/libale.h +++ b/src/libale.h @@ -76,6 +76,34 @@ static point point_neginf(int dim) { } /* + * Get ale_context associated with a table index from an ALE_POINTER to device + * memory. + * + * XXX: this might be better done as a table with struct { ale_context c; cl_mem m[0]; }; + */ + +typedef union { + cl_mem memory; + ale_context context; +} mem_table_entry; + +static ale_context api_to_ac(cl_long index) { + mem_table_entry *p = (mem_table_entry *) index; + + /* + * Get the slot just prior to an invalid cl_mem (marking the start of + * the cl_mem table. + */ + + while (p->memory != ((cl_mem) 0)) + p--; + + p--; + + return p->context; +} + +/* * Macro for obtaining a pointer from ALE_POINTER type. */ @@ -86,8 +114,7 @@ static point point_neginf(int dim) { * memory. */ -#warning macro to obtain an ale_context not yet defined -#define C(x) /* not yet defined */ +#define C(x) api_to_ac(x.t.index) /* * Macro for obtaining a pointer to host-mapped memory from an ALE_POINTER -- 2.11.4.GIT