Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ debug: install-debugc py

.PHONY: install-debugc py debug install-relc rel config

Debug:
mkdir Debug

Debug/Makefile: Debug config
Debug/Makefile: Debug Makefile.conf
mkdir -p Debug
ifndef INSTALL_PREFIX
(cd Debug && NUM_DEVS=${NUM_DEVS} DEV_NAMES=${DEV_NAMES} cmake .. -DCMAKE_BUILD_TYPE=Debug)
else
Expand All @@ -34,10 +32,8 @@ endif
install-debugc: debugc
(cd Debug && ${SUDO} make install)

Release:
mkdir Release

Release/Makefile: Release config
Release/Makefile: Makefile.conf
mkdir -p Release
ifndef INSTALL_PREFIX
(cd Release && NUM_DEVS=${NUM_DEVS} DEV_NAMES=${DEV_NAMES} cmake .. -DCMAKE_BUILD_TYPE=Release)
else
Expand All @@ -57,5 +53,5 @@ endif
install-relc: relc
(cd Release && ${SUDO} make install)

py: config
py: Makefile.conf
python setup.py build_ext --inplace
79 changes: 78 additions & 1 deletion src/loaders/dyn_load.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
#if defined(__unix__) || defined(__APPLE__)

#include <dlfcn.h>
#include <stddef.h>
#include <err.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>

void *ga_load_library(const char *name) {
void *res = dlopen(name, RTLD_LAZY|RTLD_LOCAL);
Expand All @@ -24,10 +26,50 @@ void *ga_func_ptr(void *h, const char *name) {
return res;
}

float ga_lib_version(void *h, void *sym) {
Dl_info dli;
char *real_path;
char *dot1;
char *dot2;
char *end;
float res;

if (!dladdr(sym, &dli))
return -1;

real_path = realpath(dli.dli_fname, NULL);
if (real_path == NULL)
return -1;

dot1 = strrchr(real_path, '.');
if (dot1 == NULL) {
free(real_path);
return -1;
}
dot1[0] = '\0';

dot2 = strrchr(real_path, '.');
if (dot2 == NULL) {
free(real_path);
return -1;
}
dot1[0] = '.';

res = strtof(dot2+1, &end);
if (*end != '\0') {
free(real_path);
return -1;
}

free(real_path);
return res;
}

#else

/* Should be windows */
#include <windows.h>
#pragma comment(lib,"Version.lib")

void *ga_load_library(const char *name) {
return LoadLibrary(name);
Expand All @@ -37,4 +79,39 @@ void *ga_func_ptr(void *h, const char *name) {
return (void *)GetProcAddress(h, name);
}

float ga_lib_version(void *h, void *sym) {
char fname[1024];
char *vinfo;
size_t vsize;
VS_FIXEDFILEINFO *vp;
unsigned int ui;
float res;

if (GetModuleFileName(h, fname, sizeof(fname)) == sizeof(fname))
return -1;

vsize = GetFileVersionInfoSize(fname, NULL);
if (vsize == 0)
return -1;

vinfo = malloc(vsize);
if (vinfo == NULL)
return -1;

if (!GetFileVersionInfo(fname, 0, vsize, vinfo)) {
free(vinfo);
return -1;
}

if (!VerQueryValue(vinfo, "\\", &vp, &ui)) {
free(vinfo);
return -1;
}

res = ( ((HIWORD(vp->dwFileVersionLS) - 10) * 10000) + LOWORD(vp->dwFileVersionLS) ) / 100.0;

free(vinfo);
return res;
}

#endif
1 change: 1 addition & 0 deletions src/loaders/dyn_load.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@

void *ga_load_library(const char *name);
void *ga_func_ptr(void *h, const char *name);
float ga_lib_version(void *h, void *sym);

#endif
31 changes: 30 additions & 1 deletion src/loaders/libcuda.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <stdio.h>
#include <stdlib.h>

#include "libcuda.h"
Expand All @@ -9,7 +10,7 @@
static char libname[] = "nvcuda.dll";
#else /* Unix */
#ifdef __APPLE__
static char libname[] = "CUDA.framework/CUDA";
static char libname[] = "/Library/Frameworks/CUDA.framework/CUDA";
#else
static char libname[] = "libcuda.so";
#endif
Expand Down Expand Up @@ -41,6 +42,9 @@ static int loaded = 0;

int load_libcuda(void) {
void *lib;
#ifndef __APPLE__
float v;
#endif

if (loaded)
return GA_NO_ERROR;
Expand All @@ -51,6 +55,31 @@ int load_libcuda(void) {

#include "libcuda.fn"

/*
* The blacklisted versions of cuda are not available on mac as far as I know.
*/
#ifndef __APPLE__
v = ga_lib_version(lib, cuInit);
if (v == -1)
fprintf(stderr, "WARNING: could not determine cuda driver version. Some versions return bad results, make sure your version is fine\n");
#ifdef DEBUG
fprintf(stderr, "CUDA driver version detected: %.2f\n", v);
#endif

if (v > 373.06) {
if (getenv("GPUARRAY_FORCE_CUDA_DRIVER_LOAD") != NULL) {
fprintf(stderr, "WARNING: loading blacklisted driver because the load was forced.\n");
} else {
fprintf(stderr, "ERROR: refusing to load cuda driver library "
"because the version is blacklisted. "
"Versions 373.06 and below are known to be ok.\n"
"If you want to bypass this check and force the driver load "
"define GPUARRAY_FORCE_CUDA_DRIVER_LOAD in your environement.\n");
return GA_LOAD_ERROR;
}
}
#endif

loaded = 1;
return GA_NO_ERROR;
}
2 changes: 1 addition & 1 deletion src/loaders/libopencl.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
static char libname[] = "OpenCL.dll";
#else /* Unix */
#ifdef __APPLE__
static char libname[] = "OpenCL.framework/OpenCL";
static char libname[] = "/System/Library/Frameworks/OpenCL.framework/OpenCL";
#else
static char libname[] = "libOpenCL.so";
#endif
Expand Down