diff options
author | Zack Rusin <zack@tungstengraphics.com> | 2008-12-14 12:36:43 -0500 |
---|---|---|
committer | Zack Rusin <zack@tungstengraphics.com> | 2008-12-14 12:36:43 -0500 |
commit | 6fecadca5e91deb187c4efc11e2c0a4b0e1782a8 (patch) | |
tree | d7f199d7f4bf8d62a05f616a33a4968a0d0c951c | |
parent | dd3ffb6420c99b12e6421920c050c3f7eca14c5e (diff) |
first semi working example
-rw-r--r-- | Makefile | 3 | ||||
-rw-r--r-- | configs/default | 2 | ||||
-rw-r--r-- | cpuwinsys/cpuwinsys.h | 8 | ||||
-rw-r--r-- | examples/trivial/Makefile | 40 | ||||
-rw-r--r-- | examples/trivial/basic.c | 33 | ||||
-rw-r--r-- | src/api_device.cpp | 9 |
6 files changed, 90 insertions, 5 deletions
@@ -57,7 +57,8 @@ GALLIUM_LIBS = \ $(GALLIUM)/src/gallium/auxiliary/translate/libtranslate.a \ $(GALLIUM)/src/gallium/auxiliary/cso_cache/libcso_cache.a \ $(GALLIUM)/src/gallium/auxiliary/tgsi/libtgsi.a \ - $(GALLIUM)/src/gallium/auxiliary/util/libutil.a + $(GALLIUM)/src/gallium/auxiliary/util/libutil.a \ + $(GALLIUM)/src/gallium/drivers/softpipe/libsoftpipe.a .SUFFIXES : .cpp diff --git a/configs/default b/configs/default index fb91df8..1991aca 100644 --- a/configs/default +++ b/configs/default @@ -44,7 +44,7 @@ CL_LIB = OpenCL # Library names (actual file names) CL_LIB_NAME = lib$(CL_LIB).so - +SYS_LIBS = -lstdc++ # Directories to build LIB_DIR = lib SRC_DIRS = gallium mesa gallium/winsys diff --git a/cpuwinsys/cpuwinsys.h b/cpuwinsys/cpuwinsys.h index d5f67da..5894933 100644 --- a/cpuwinsys/cpuwinsys.h +++ b/cpuwinsys/cpuwinsys.h @@ -1,8 +1,16 @@ #ifndef CPUWINSYS_H #define CPUWINSYS_H +#ifdef __cplusplus +extern "C" { +#endif + struct pipe_winsys; struct pipe_winsys *cpu_winsys(void); +#ifdef __cplusplus +} +#endif + #endif diff --git a/examples/trivial/Makefile b/examples/trivial/Makefile new file mode 100644 index 0000000..082df13 --- /dev/null +++ b/examples/trivial/Makefile @@ -0,0 +1,40 @@ +TOP = ../.. +include $(TOP)/configs/current + + +LIBS = -L$(TOP)/$(LIB_DIR) -l$(CL_LIB) $(APP_LIB_DEPS) + +SOURCES = \ + basic.c + +PROGS = $(SOURCES:%.c=%) + +INCLUDES = -I. -I$(TOP)/include -I../samples + + +##### RULES ##### + +.SUFFIXES: +.SUFFIXES: .c + +.c: + $(APP_CC) $(INCLUDES) $(CFLAGS) $(LDFLAGS) $< $(LIBS) -o $@ + +.c.o: + $(APP_CC) -c $(INCLUDES) $(CFLAGS) $(DEFINES) $< -o $@ + +.S.o: + $(APP_CC) -c $(INCLUDES) $(CFLAGS) $(DEFINES) $< -o $@ + + +##### TARGETS ##### + +default: $(PROGS) + +clean: + -rm -f $(PROGS) + -rm -f *.o + +# Emacs tags +tags: + etags `find . -name \*.[ch]` `find ../include` diff --git a/examples/trivial/basic.c b/examples/trivial/basic.c new file mode 100644 index 0000000..911b69e --- /dev/null +++ b/examples/trivial/basic.c @@ -0,0 +1,33 @@ +#include <OpenCL/cl.h> +#include <stdio.h> + +int main() +{ + cl_device_id device; + int err; + char deviceName[256], + deviceVendor[256], + deviceVersion[256]; + + err = clGetDeviceIDs(CL_DEVICE_TYPE_DEFAULT, 1, &device, NULL); + + if (err) { + fprintf(stderr, "clGetDeviceIDs failed\n"); + return -1; + } + + err = clGetDeviceInfo(device, CL_DEVICE_NAME, + sizeof(deviceName), deviceName, NULL); + err |= clGetDeviceInfo(device, CL_DEVICE_VENDOR, + sizeof(deviceVendor), deviceVendor, NULL); + err |= clGetDeviceInfo(device, CL_DEVICE_VERSION, + sizeof(deviceVersion), deviceVersion, NULL); + if (err) { + fprintf(stderr, "Unable to obtain device info"); + return -1; + } + printf("Compute Device Name = %s\n" + "Compute Device Vendor = %s\n" + "Compute Device Version = %s\n", + deviceName, deviceVendor, deviceVersion); +} diff --git a/src/api_device.cpp b/src/api_device.cpp index c9954eb..9f5f031 100644 --- a/src/api_device.cpp +++ b/src/api_device.cpp @@ -79,21 +79,24 @@ clGetDeviceIDs(cl_device_type device_type, cl_uint num_gpus = 0; create_gpu_device(devices, &num_gpus, num_entries); num_entries -= num_gpus; - *num_devices += num_gpus; + if (num_devices) + *num_devices += num_gpus; } if (cpu && num_entries > 0) { cl_uint num_cpus = 0; create_cpu_device(devices, &num_cpus, num_entries); num_entries -= num_cpus; - *num_devices += num_cpus; + if (num_devices) + *num_devices += num_cpus; } if (accelerator && num_entries) { cl_uint num_accels = 0; create_accel_device(devices, &num_accels, num_entries); num_entries -= num_accels; - *num_devices += num_accels; + if (num_devices) + *num_devices += num_accels; } if (original_num_entries == num_entries) |