Skip to content

Commit

Permalink
Add support for MacOS (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kerilk authored May 12, 2021
1 parent 2d02d58 commit 0260035
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 21 deletions.
9 changes: 7 additions & 2 deletions .github/workflows/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,15 @@ jobs:
build-and-check:
needs: pre_job
if: ${{ needs.pre_job.outputs.should_skip != 'true' }}
name: Build and Check Ubuntu
runs-on: ubuntu-latest
name: Build and Check ${{ matrix.os }} ${{ matrix.name }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
steps:
- uses: actions/checkout@v2
- run: brew install automake
if: ${{ matrix.os == 'macos-latest' }}
- run: ./bootstrap
- run: ./configure --enable-official-khronos-headers
- run: make
Expand Down
4 changes: 4 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,17 @@ install-exec-hook::
$(RM) -r $(DESTDIR)$(pkglibdir)
libdummycl_la_SOURCES = libdummy_icd.c libdummy_icd.h
nodist_libdummycl_la_SOURCES = libdummy_icd_gen.c libdummy_icd_gen.h
libdummycl_la_LDFLAGS = -module
libdummycl_noext_la_SOURCES = $(libdummycl_la_SOURCES)
nodist_libdummycl_noext_la_SOURCES = $(nodist_libdummycl_la_SOURCES)
libdummycl_noext_la_LDFLAGS = -module
libdummycl_noext_la_CPPFLAGS = $(AM_CPPFLAGS) -DICD_WITHOUT_EXTENSION
libdummycl2_la_SOURCES = $(libdummycl_la_SOURCES)
nodist_libdummycl2_la_SOURCES = $(nodist_libdummycl_la_SOURCES)
libdummycl2_la_LDFLAGS = -module
libdummycl2_la_CPPFLAGS = $(AM_CPPFLAGS) -DICD_SUFFIX=\"2\"
nodist_libdummylayer_la_SOURCES = dummy_icd_layer_gen.c
libdummylayer_la_LDFLAGS = -module

noinst_PROGRAMS=run_dummy_icd_through_our_ICDL
run_dummy_icd_through_our_ICDL_SOURCES = run_dummy_icd.c
Expand Down
12 changes: 12 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ AC_CONFIG_SRCDIR([ocl_icd_loader.c])
AC_CONFIG_AUX_DIR([build-aux])
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_MACRO_DIR([m4])
AC_CANONICAL_HOST
case $host_os in
*macos*) macos="yes" ;;
*darwin*) macos="yes" ;;
*) macos="no" ;;
esac
AM_INIT_AUTOMAKE([-Wall -Werror foreign 1.9 tar-pax check-news color-tests parallel-tests])
AMX_SILENT_RULES([AM_DEFAULT_VERBOSITY=1])
# AM_PROG_AR must be called before LT_INIT...
Expand Down Expand Up @@ -55,9 +61,11 @@ cl_h=no
case $host_os in
darwin* )
AC_CHECK_HEADER([OpenCL/opencl.h],[cl_h=yes])
AC_CHECK_HEADERS([OpenCL/cl_layer.h])
;;
* )
AC_CHECK_HEADER([CL/opencl.h],[cl_h=yes])
AC_CHECK_HEADERS([CL/cl_layer.h])
;;
esac
if test $cl_h = yes; then
Expand Down Expand Up @@ -171,7 +179,11 @@ AS_IF([test x"$OCL_ICD_VENDORDIR" = x"/etc/OpenCL/vendors" ], [
])

# always use versionned symbols (check required for MacOSX)
if test "x$macos" == xyes ; then
AM_CONDITIONAL([USE_MAP], [false])
else
AM_CONDITIONAL([USE_MAP], [true])
fi

AC_CONFIG_FILES([
Makefile
Expand Down
44 changes: 36 additions & 8 deletions icd_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,15 @@ def self.generate_libdummy_icd_header
libdummy_icd_structures += "};\n\n"
libdummy_icd_structures += "#pragma GCC visibility push(hidden)\n\n"
libdummy_icd_structures += "extern struct _cl_icd_dispatch master_dispatch; \n\n"
libdummy_icd_structures += "#if defined(__APPLE__) || defined(__MACOSX)\n"
$use_name_in_test.each { |k, f|
libdummy_icd_structures += "#define INT#{f} #{f}\n"
}
libdummy_icd_structures += "#else\n"
$use_name_in_test.each { |k, f|
libdummy_icd_structures += "typeof(#{f}) INT#{f};\n"
}
libdummy_icd_structures += "#endif\n"
libdummy_icd_structures += "#pragma GCC visibility pop\n\n"
return libdummy_icd_structures
end
Expand Down Expand Up @@ -351,7 +357,13 @@ def self.generate_icd_layer_source
#define CL_USE_DEPRECATED_OPENCL_2_1_APIS
#define CL_USE_DEPRECATED_OPENCL_2_2_APIS
#define CL_TARGET_OPENCL_VERSION 300
#ifdef HAVE_OPENCL_CL_LAYER_H
#include <OpenCL/cl_layer.h>
#elif defined HAVE_CL_CL_LAYER_H
#include <CL/cl_layer.h>
#else
#include "khronos-headers/CL/cl_layer.h"
#endif
static struct _cl_icd_dispatch dispatch = {NULL};
static const struct _cl_icd_dispatch *tdispatch;
Expand Down Expand Up @@ -690,11 +702,15 @@ def self.generate_get_extension_address_for_platform

def self.generate_ocl_icd_loader_gen_source
skip_funcs = $specific_loader_funcs
ocl_icd_loader_gen_source = "/**\n#{$license}\n*/\n"
ocl_icd_loader_gen_source += "#include <string.h>\n"
ocl_icd_loader_gen_source += "#include \"ocl_icd_loader.h\"\n"
ocl_icd_loader_gen_source += "#define DEBUG_OCL_ICD_PROVIDE_DUMP_FIELD\n"
ocl_icd_loader_gen_source += "#include \"ocl_icd_debug.h\"\n"
ocl_icd_loader_gen_source = <<EOF
/**\n#{$license}\n*/
#include <string.h>
#include "ocl_icd_loader.h"
#define DEBUG_OCL_ICD_PROVIDE_DUMP_FIELD
#include "ocl_icd_debug.h"
#define hidden_alias(name) \\
typeof(name) name##_hid __attribute__ ((alias (#name), visibility("hidden")))
EOF
api_proc = proc { |disp, (func_name, entry)|
next if skip_funcs.include?(func_name)
clean_entry = entry.sub(/(.*\)).*/m,'\1').gsub("/*","").gsub("*/","").gsub("\r","") + "{\n"
Expand Down Expand Up @@ -778,10 +794,22 @@ def self.generate_ocl_icd_loader_gen_source
#next if func_name.match(/EXT$/)
#next if func_name.match(/KHR$/)
if (skip_funcs.include?(func_name)) then
ocl_icd_loader_gen_source += "extern typeof(#{func_name}) #{func_name}_hid;\n"
ocl_icd_loader_gen_source += "extern typeof(#{func_name}) #{func_name}_disp;\n"
ocl_icd_loader_gen_source += <<EOF
#if defined(__APPLE__) || defined(__MACOSX)
#define #{func_name}_hid #{func_name}
#else
extern typeof(#{func_name}) #{func_name}_hid;
#endif
extern typeof(#{func_name}) #{func_name}_disp;
EOF
else
ocl_icd_loader_gen_source += "typeof(#{func_name}) #{func_name}_hid __attribute__ ((alias (\"#{func_name}\"), visibility(\"hidden\")));\n"
ocl_icd_loader_gen_source += <<EOF
#if defined(__APPLE__) || defined(__MACOSX)
#define #{func_name}_hid #{func_name}
#else
hidden_alias(#{func_name});
#endif
EOF
end
}
ocl_icd_loader_gen_source += "\n\nstruct func_desc const function_description[]= {\n"
Expand Down
50 changes: 41 additions & 9 deletions libdummy_icd.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,12 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <string.h>
#define NUM_PLATFORMS 1

#if defined(__APPLE__) || defined(__MACOSX)
#define SYMB(f)
#else
#define SYMB(f) \
typeof(INT##f) f __attribute__ ((alias ("INT" #f), visibility("default")))
#endif

#pragma GCC visibility push(hidden)

Expand All @@ -42,8 +46,8 @@ int debug_ocl_icd_mask;
cl_uint const num_master_platforms = NUM_PLATFORMS;
struct _cl_platform_id master_platforms[NUM_PLATFORMS] = { {&master_dispatch} };

static cl_int _GetPlatformIDs(
cl_uint num_entries,
static cl_int _GetPlatformIDs(
cl_uint num_entries,
cl_platform_id *platforms,
cl_uint *num_platforms) {
debug_trace();
Expand All @@ -65,20 +69,34 @@ static cl_int _GetPlatformIDs(
return CL_SUCCESS;
}

CL_API_ENTRY cl_int CL_API_CALL INTclGetPlatformIDs(
cl_uint num_entries,
#if defined(__APPLE__) || defined(__MACOSX)
CL_API_ENTRY cl_int __attribute__((visibility("default"))) CL_API_CALL clGetPlatformIDs(
cl_uint num_entries,
cl_platform_id *platforms,
cl_uint *num_platforms) {
#else
CL_API_ENTRY cl_int CL_API_CALL INTclGetPlatformIDs(
cl_uint num_entries,
cl_platform_id *platforms,
cl_uint *num_platforms) {
#endif
debug_init();
debug_trace();
return _GetPlatformIDs(num_entries, platforms, num_platforms);
}
SYMB(clGetPlatformIDs);

CL_API_ENTRY cl_int CL_API_CALL INTclIcdGetPlatformIDsKHR(
cl_uint num_entries,
#if defined(__APPLE__) || defined(__MACOSX)
CL_API_ENTRY cl_int __attribute__((visibility("default"))) CL_API_CALL clIcdGetPlatformIDsKHR(
cl_uint num_entries,
cl_platform_id *platforms,
cl_uint *num_platforms) {
#else
CL_API_ENTRY cl_int CL_API_CALL INTclIcdGetPlatformIDsKHR(
cl_uint num_entries,
cl_platform_id *platforms,
cl_uint *num_platforms) {
#endif
debug_init();
debug_trace();
return _GetPlatformIDs(num_entries, platforms, num_platforms);
Expand All @@ -90,8 +108,13 @@ SYMB(clIcdGetPlatformIDsKHR);
const char * func_name) CL_API_SUFFIX__VERSION_1_2 {
}*/

#if defined(__APPLE__) || defined(__MACOSX)
CL_API_ENTRY void * __attribute__((visibility("default"))) CL_API_CALL clGetExtensionFunctionAddress(
const char * func_name) CL_API_SUFFIX__VERSION_1_0 {
#else
CL_API_ENTRY void * CL_API_CALL INTclGetExtensionFunctionAddress(
const char * func_name) CL_API_SUFFIX__VERSION_1_0 {
#endif
debug_init();
debug_trace();
debug(D_LOG, "request address for %s", func_name);
Expand All @@ -108,17 +131,26 @@ SYMB(clGetExtensionFunctionAddress);
# define ICD_SUFFIX ""
#endif

#if defined(__APPLE__) || defined(__MACOSX)
CL_API_ENTRY cl_int __attribute__((visibility("default"))) CL_API_CALL clGetPlatformInfo(
cl_platform_id platform,
cl_platform_info param_name,
size_t param_value_size,
void * param_value,
size_t * param_value_size_ret) CL_API_SUFFIX__VERSION_1_0 {
#else
CL_API_ENTRY cl_int CL_API_CALL INTclGetPlatformInfo(
cl_platform_id platform,
cl_platform_id platform,
cl_platform_info param_name,
size_t param_value_size,
size_t param_value_size,
void * param_value,
size_t * param_value_size_ret) CL_API_SUFFIX__VERSION_1_0 {
#endif
debug_init();
debug_trace();
debug(D_LOG, "request info for 0x%x", param_name);

if (param_name==0 && param_value_size==0
if (param_name==0 && param_value_size==0
&& param_value==NULL && param_value_size_ret==NULL) {
printf("1 : ");
}
Expand Down
4 changes: 4 additions & 0 deletions ocl_icd_loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -884,8 +884,12 @@ getDefaultPlatformID() {
}

#pragma GCC visibility pop
#if defined(__APPLE__) || defined(__MACOSX)
#define hidden_alias(name)
#else
#define hidden_alias(name) \
typeof(name) name##_hid __attribute__ ((alias (#name), visibility("hidden")))
#endif

typedef enum {
CL_ICDL_OCL_VERSION=1,
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite-default-platform.at
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ AT_CHECK([env LC_ALL=C sort -u stdout], 0,
ocl-icd ICD test
ocl-icd ICD test2
])
AT_CHECK([wc -l < stdout], 0,
AT_CHECK([wc -l < stdout | sed "s/^ *//"], 0,
[4
])
AT_CLEANUP
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite-standard.at
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ AT_CHECK([run_dummy_icd_through_our_ICDL], 0, [stdout], [stderr])
AT_CHECK([grep "^-1" stdout | sort], 0, [])
AT_CHECK([grep -v '^[[0-9]]* *:' stdout ], 0, [---
])
AT_CHECK([sed -e "s/ *(expected)//" stdout | uniq -c | grep -v '^ *2 ' ], 0, [ 1 ---
AT_CHECK([sed -e "s/ *(expected)//" stdout | uniq -c | grep -v '^ *2 ' | sed "s/^ *//" ], 0, [1 ---
])
AT_CLEANUP

Expand Down

0 comments on commit 0260035

Please sign in to comment.