Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed Windows build and instructions for windows.

This crashes in GET_EVENT_INFO: when running cl_basic:test().
  • Loading branch information...
commit eec26972ce55a366c245470660be7f701be716c5 1 parent 9d41ae5
@dgud authored tonyrog committed
View
21 README
@@ -1,8 +1,7 @@
Welcome to the Erlang OpenCL binding
-To get started you need erlang, preferably R13. You also need
-GCC and a machine with OpenCL installed. Currently only Mac Os X 10.6.x
-is known to work. Then linux support is on it's way.
+To get started you need erlang, preferably R14. You also need
+GCC and a machine with OpenCL installed.
To build: just run make
@@ -10,5 +9,21 @@ To build examples: Goto the examples directory and run make.
Make sure erlang finds the cl/ebin directory.
+Windows Users:
+I'm assuming you got an mingw environment, otherwise you are on your own.
+mkdir -p /opt/local/include/CL
+mkdir -p /opt/local/lib
+Download all headers from http://www.khronos.org/registry/cl/
+and put them in /opt/local/include/CL
+
+Find a OpenCL.lib available in Nvidia or ATI developments kits
+cp /c/CUDA/lib/OpenCL.dll /opt/local/lib
+
+Also you might need autoconf package available at:
+http://sourceforge.net/projects/mingw/files_beta/MSYS/
+
+OpenCL with ATI drivers for CPU usage don't work when erlang
+is started within a mingw shell but does if you start it from
+a Windows CMD.exe shell.
View
40 c_src/Makefile
@@ -16,6 +16,7 @@ SSE = No
SSE2 = No
SSE3 = No
SSE4 = No
+EXT = so
ifeq ($(WORDSIZE), 64)
include config.64.build
@@ -27,22 +28,22 @@ endif
ifeq ($(TYPE), debug)
OBJDIR=../obj/debug
LIBDIR=../lib/debug
-CFLAGS += -fPIC -Ddebug -DDEBUG -g -Wall -Wextra -Wswitch-default -Wswitch-enum -D_THREAD_SAFE -D_REENTRANT -fno-common
+CFLAGS += -Ddebug -DDEBUG -g -Wall -Wextra -Wswitch-default -Wswitch-enum -D_THREAD_SAFE -D_REENTRANT -fno-common
endif
ifeq ($(TYPE), release)
OBJDIR=../obj/release
LIBDIR=../lib/release
-CFLAGS += -fPIC -O3 -Wall -Wextra -Wswitch-default -Wswitch-enum -D_THREAD_SAFE -D_REENTRANT -fno-common
+CFLAGS += -O3 -Wall -Wextra -Wswitch-default -Wswitch-enum -D_THREAD_SAFE -D_REENTRANT -fno-common
endif
ifeq ($(OSNAME), Linux)
LINUX = Yes
ifeq ($(WORDSIZE), 32)
-CFLAGS += -m32 -DWORDSIZE=32
+CFLAGS += -fPIC -m32 -DWORDSIZE=32
endif
ifeq ($(WORDSIZE), 64)
-CFLAGS += -m64 -DWORDSIZE=64
+CFLAGS += -fPIC -m64 -DWORDSIZE=64
endif
LD_SHARED := $(CC) -shared -lOpenCL
endif
@@ -50,15 +51,35 @@ endif
ifeq ($(OSNAME), Darwin)
MAC_OS_X = Yes
ifeq ($(WORDSIZE), 32)
-CFLAGS += -m32 -DWORDSIZE=32 -DDARWIN -no-cpp-precomp
+CFLAGS += -fPIC -m32 -DWORDSIZE=32 -DDARWIN -no-cpp-precomp
LD_SHARED := $(CC) -m32 -bundle -flat_namespace -undefined suppress
endif
ifeq ($(WORDSIZE), 64)
-CFLAGS += -m64 -DWORDSIZE=64 -DDARWIN -no-cpp-precomp
+CFLAGS += -fPIC -m64 -DWORDSIZE=64 -DDARWIN -no-cpp-precomp
LD_SHARED := $(CC) -m64 -bundle -flat_namespace -undefined suppress
endif
endif
+ifeq ($(OSNAME), MINGW32_NT-6.0)
+MINGW = Yes
+endif
+ifeq ($(OSNAME), MINGW32_NT-6.1)
+MINGW = Yes
+endif
+
+ifeq ($(MINGW), Yes)
+WIN32 = Yes
+EXT = dll
+CFLAGS += -D__WIN32__
+ifeq ($(WORDSIZE), 32)
+CFLAGS += -shared -I/opt/local/include -m32 -DWIN32 -DWORDSIZE=32
+endif
+ifeq ($(WORDSIZE), 64)
+CFLAGS += -shared -I/opt/local/include -m64 -DWIN32 -DWORDSIZE=64
+endif
+LD_SHARED := $(CC) -shared
+endif
+
ifeq ($(MACHINE), "Power Macintosh")
ALTIVEC = Yes
endif
@@ -83,6 +104,7 @@ endif
ifeq ($(WIN32),Yes)
CFLAGS += -DWIN32
+ LDFLAGS += -Wl--enable-stdcall-fixup -L/opt/local/lib -lOpenCL
endif
ifeq ($(ALTIVEC),Yes)
@@ -107,9 +129,9 @@ ifeq ($(MMX),Yes)
SIMD_OBJS += ocl_simd_mmx.$(BIT).o
endif
-CL_DRV = $(LIBDIR)/$(WORDSIZE)/cl_drv.so
+CL_DRV = $(LIBDIR)/$(WORDSIZE)/cl_drv.$(EXT)
-CL_NIF = $(LIBDIR)/$(WORDSIZE)/cl_nif.so
+CL_NIF = $(LIBDIR)/$(WORDSIZE)/cl_nif.$(EXT)
CL_DRV_OBJS = \
$(OBJDIR)/$(WORDSIZE)/cl_drv.o \
@@ -195,7 +217,7 @@ $(OBJDIR)/$(WORDSIZE)/cl_drv.o: cbufv2.h cl_hash.h
$(OBJDIR)/$(WORDSIZE)/%.o: %.c
$(CC) -c -o $@ $(CFLAGS) -I$(ERL_C_INCLUDE_DIR) $<
- $(OBJDIR)/$(WORDSIZE)/%.s: %.c
+$(OBJDIR)/$(WORDSIZE)/%.s: %.c
$(CC) -S -o $@ $(CFLAGS) -I$(ERL_C_INCLUDE_DIR) $<
cbuf_test.o: cbuf_test.c
View
33 c_src/cbufv2.h
@@ -14,6 +14,19 @@
#endif
#define UNUSED __attribute__((unused))
+#ifdef __MINGW32__
+#undef ERROR
+#define LITTLE_ENDIAN 1234
+#define BIG_ENDIAN 4321
+#define BYTE_ORDER LITTLE_ENDIAN
+#include <windows.h>
+#ifndef u_int8_t
+typedef unsigned char u_int8_t;
+typedef unsigned short int u_int16_t;
+typedef unsigned int u_int32_t;
+typedef unsigned long long u_int64_t;
+#endif
+#endif
#define CBUF_USE_PUT_ETF // pack ETF
#define CBUF_USE_PUT_CTI // pack CTI
@@ -135,20 +148,20 @@ void cbuf_print(cbuf_t* cp,char* name)
if (cp->flags & CBUF_FLAG_BINARY) fprintf(f," binary");
if (cp->flags & CBUF_FLAG_HEAP) fprintf(f," heap");
fprintf(f,"\r\n");
- fprintf(f," iv: %lu\r\n", cp->iv);
- fprintf(f," ip: %lu\r\n", cp->ip);
- fprintf(f," vsize: %lu\r\n", cp->vsize);
- fprintf(f," vlen: %lu\r\n", cp->vlen);
+ fprintf(f," iv: %lu\r\n", (long unsigned int) cp->iv);
+ fprintf(f," ip: %lu\r\n", (long unsigned int) cp->ip);
+ fprintf(f," vsize: %lu\r\n", (long unsigned int) cp->vsize);
+ fprintf(f," vlen: %lu\r\n", (long unsigned int) cp->vlen);
fprintf(f," dv: %s\r\n", (cp->v == cp->dv) ? "true" : "false");
for (i = 0; i < cp->vlen; i++) {
- fprintf(f," v[%lu].flags:", i);
+ fprintf(f," v[%lu].flags:", (long unsigned int) i);
if (cp->v[i].flags & CBUF_FLAG_BINARY) fprintf(f," binary");
if (cp->v[i].flags & CBUF_FLAG_HEAP) fprintf(f," heap");
fprintf(f,"\r\n");
- fprintf(f," v[%lu].base = %p\r\n", i, cp->v[i].base);
- fprintf(f," v[%lu].size = %lu\r\n", i, cp->v[i].size);
- fprintf(f," v[%lu].len = %lu\r\n", i, cp->v[i].len);
- fprintf(f," v[%lu].bp = %p\r\n", i, cp->v[i].bp);
+ fprintf(f," v[%lu].base = %p\r\n", (long unsigned int) i, cp->v[i].base);
+ fprintf(f," v[%lu].size = %lu\r\n", (long unsigned int) i, (long unsigned int)cp->v[i].size);
+ fprintf(f," v[%lu].len = %lu\r\n", (long unsigned int) i, (long unsigned int) cp->v[i].len);
+ fprintf(f," v[%lu].bp = %p\r\n", (long unsigned int) i, cp->v[i].bp);
}
fprintf(f,"};\r\n");
}
@@ -176,7 +189,7 @@ static inline void* memcpy_n2b(void* dst, void* src, size_t len)
//
static inline void* memcpy_n2l(void* dst, void* src, size_t len)
{
-#if BYTE_ORDER == LITTLE_ENDIAN
+#if BYTE_ORDER == LITTLE_ENDIAN
return memcpy(dst, src, len);
#else
u_int8_t* sp = ((u_int8_t*) src) + len;
View
48 c_src/cl_drv.c
@@ -1,15 +1,23 @@
#include <stdio.h>
#include <stdlib.h>
-#include <stdint.h>
#include <stdbool.h>
#include <errno.h>
+#include <stdint.h>
+
+#ifdef __MINGW32__
+#include <winsock2.h>
+#include <ws2tcpip.h>
+#else
#include <sys/socket.h>
+#endif
+
#ifdef DARWIN
#include <OpenCL/opencl.h>
#else
#include <CL/cl.h>
#endif
+
#if WORDSIZE==32
#include "config.32.h"
#elif WORDSIZE==64
@@ -2594,40 +2602,6 @@ static int ecl_drv_ctl(ErlDrvData d,
break;
}
- case ECL_SET_QUEUE_PROPERTY: {
- // <<Queue:Ptr, Properties:32, Enable:Bool>>
- pointer_t handle;
- u_int32_t prop;
- u_int32_t enable;
- ecl_object_t* obj;
-
- if (get_pointer(&arg, &handle) &&
- get_uint32(&arg, &prop) &&
- get_uint32(&arg, &enable) &&
- cbuf_eob(&arg) &&
- ((obj = queue_object(env, handle)) != 0)) {
- cl_command_queue_properties properties = 0;
- cl_command_queue_properties old_properties;
-
- if (prop & ECL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE)
- properties |= CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE;
- if (prop & ECL_QUEUE_PROFILING_ENABLE)
- properties |= CL_QUEUE_PROFILING_ENABLE;
- err = clSetCommandQueueProperty(obj->queue, properties,
- (enable != 0),
- &old_properties);
- if (err == CL_SUCCESS) {
- cbuf_put_tuple_begin(&reply, 2);
- cbuf_put_tag_ok(&reply);
- put_element(&reply, BITFIELD, &old_properties,
- kv_command_queue_properties);
- cbuf_put_tuple_end(&reply, 2);
- goto done;
- }
- }
- break;
- }
-
case ECL_FLUSH: {
// <<Queue:Ptr>>
pointer_t handle;
@@ -3245,8 +3219,8 @@ static int ecl_drv_ctl(ErlDrvData d,
{
int i;
for (i = 0; i < (int)work_dim; i++) {
- printf("global[%d] = %ld\r\n", i, global_work_size[i]);
- printf("local[%d] = %ld\r\n", i, local_work_size[i]);
+ printf("global[%d] = %ld\r\n", i, (long int) global_work_size[i]);
+ printf("local[%d] = %ld\r\n", i, (long int) local_work_size[i]);
}
}
#endif
View
7 examples/cl_basic.erl
@@ -93,7 +93,12 @@ __kernel void program1(int n, int m) {
end, DeviceList),
ok;
Error ->
- io:format("Build Error: ~p\n", [Error])
+ io:format("\n\nBuild Error: ~p\n\n", [Error]),
+ foreach(
+ fun(Device) ->
+ {ok,BuildInfo} = cl:get_program_build_info(Program,Device),
+ io:format("BuildInfo @ ~w: ~p\n", [Device,BuildInfo])
+ end, DeviceList)
end,
cl:release_program(Program),
ok.
View
3  src/cl.erl
@@ -870,8 +870,9 @@ create_queue({object,?CONTEXT_TYPE,Context},
%% 'ok' | {'error', cl_error()}
%% @doc Function is deprecated and have been removed.
-set_queue_property({object,?QUEUE_TYPE,Queue}, Properties, Enable) ->
+set_queue_property(_Queue, _Properties, _Enable) ->
erlang:error(deprecated).
+
%%
%% @spec release_queue(Queue::cl_queue()) ->
%% 'ok' | {'error', cl_error()}
Please sign in to comment.
Something went wrong with that request. Please try again.