Skip to content

Commit c8994e0

Browse files
committed
windows fixes for cuda backend
driver version code is commented temporarily due to undefined reference
1 parent dde787f commit c8994e0

21 files changed

+205
-173
lines changed

include/af/defines.h

Lines changed: 69 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -11,76 +11,84 @@
1111

1212
#ifdef __cplusplus
1313
#include <complex>
14-
namespace af{
15-
typedef std::complex<float> af_cfloat;
16-
typedef std::complex<double> af_cdouble;
14+
15+
namespace af
16+
{
17+
typedef std::complex<float> af_cfloat;
18+
typedef std::complex<double> af_cdouble;
1719
}
20+
1821
#else
1922
typedef struct {
20-
float x;
21-
float y;
23+
float x;
24+
float y;
2225
} af_cfloat;
2326

2427
typedef struct {
25-
double x;
26-
double y;
28+
double x;
29+
double y;
2730
} af_cdouble;
31+
2832
#endif
2933

3034
typedef enum {
31-
AF_SUCCESS=0,
32-
AF_ERR_INTERNAL,
33-
AF_ERR_NOMEM,
34-
AF_ERR_DRIVER,
35-
AF_ERR_RUNTIME,
36-
AF_ERR_INVALID_ARRAY,
37-
AF_ERR_ARG,
38-
AF_ERR_SIZE,
39-
AF_ERR_DIFF_TYPE,
40-
AF_ERR_NOT_SUPPORTED,
41-
AF_ERR_INVALID_TYPE,
42-
AF_ERR_INVALID_ARG,
43-
AF_ERR_UNKNOWN
35+
AF_SUCCESS = 0,
36+
AF_ERR_INTERNAL,
37+
AF_ERR_NOMEM,
38+
AF_ERR_DRIVER,
39+
AF_ERR_RUNTIME,
40+
AF_ERR_INVALID_ARRAY,
41+
AF_ERR_ARG,
42+
AF_ERR_SIZE,
43+
AF_ERR_DIFF_TYPE,
44+
AF_ERR_NOT_SUPPORTED,
45+
AF_ERR_INVALID_TYPE,
46+
AF_ERR_INVALID_ARG,
47+
AF_ERR_UNKNOWN
4448
} af_err;
4549

4650
typedef enum {
47-
f32,
48-
c32,
49-
f64,
50-
c64,
51-
b8,
52-
s32,
53-
u32,
54-
u8,
55-
s8,
56-
u8x4,
57-
s8x4,
51+
f32,
52+
c32,
53+
f64,
54+
c64,
55+
b8,
56+
s32,
57+
u32,
58+
u8,
59+
s8,
60+
u8x4,
61+
s8x4,
5862
} af_dtype;
5963

6064
typedef enum {
61-
afDevice,
62-
afHost,
65+
afDevice,
66+
afHost,
6367
} af_source;
6468

6569
#if defined(_WIN32) || defined(_MSC_VER)
66-
// http://msdn.microsoft.com/en-us/library/b0084kay(v=VS.80).aspx
67-
// http://msdn.microsoft.com/en-us/library/3y1sfaz2%28v=VS.80%29.aspx
68-
#ifdef AFDLL // libaf
69-
#define AFAPI __declspec(dllexport) extern "C"
70-
#else
71-
#define AFAPI __declspec(dllimport)
72-
#endif
73-
74-
// bool
75-
#ifndef __cplusplus
76-
#define bool unsigned char
77-
#define false 0
78-
#define true 1
79-
#endif
80-
#define __PRETTY_FUNCTION__ __FUNCSIG__
70+
// http://msdn.microsoft.com/en-us/library/b0084kay(v=VS.80).aspx
71+
// http://msdn.microsoft.com/en-us/library/3y1sfaz2%28v=VS.80%29.aspx
72+
#ifdef AFDLL // libaf
73+
#define AFAPI __declspec(dllexport)
74+
#else
75+
#define AFAPI __declspec(dllimport)
76+
#endif
77+
78+
// bool
79+
#ifndef __cplusplus
80+
#define bool unsigned char
81+
#define false 0
82+
#define true 1
83+
#endif
84+
#define __PRETTY_FUNCTION__ __FUNCSIG__
85+
#define snprintf sprintf_s
86+
#define STATIC_ static
8187
#else
82-
#define AFAPI __attribute__((visibility("default")))
83-
#include <stdbool.h>
88+
#define AFAPI __attribute__((visibility("default")))
89+
#include <stdbool.h>
90+
#define __PRETTY_FUNCTION__ __func__
91+
#define STATIC_
8492
#endif
8593

8694
#include <cstddef>
@@ -91,24 +99,24 @@ typedef size_t af_array;
9199
typedef long long dim_type;
92100

93101
typedef struct af_seq {
94-
size_t begin, end;
95-
int step;
102+
size_t begin, end;
103+
int step;
96104
} af_seq;
97-
static const af_seq span = {1, 1, 0};
105+
static const af_seq span = { 1, 1, 0 };
98106

99107
typedef enum {
100-
AF_INTERP_NEAREST,
101-
AF_INTERP_LINEAR,
102-
AF_INTERP_BILINEAR,
103-
AF_INTERP_CUBIC
108+
AF_INTERP_NEAREST,
109+
AF_INTERP_LINEAR,
110+
AF_INTERP_BILINEAR,
111+
AF_INTERP_CUBIC
104112
} af_interp_type;
105113

106114
typedef enum {
107-
AF_ZERO = 0,
108-
AF_SYMMETRIC
115+
AF_ZERO = 0,
116+
AF_SYMMETRIC
109117
} af_pad_type;
110118

111119
typedef enum {
112-
AF_CONNECTIVITY_4 = 0,
113-
AF_CONNECTIVITY_8
120+
AF_CONNECTIVITY_4 = 0,
121+
AF_CONNECTIVITY_8
114122
} af_connectivity_type;

src/array/array.cpp

Lines changed: 41 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -63,38 +63,47 @@ namespace af
6363
initEmptyArray(&arr, ty, d0, d1, d2, d3);
6464
}
6565

66-
template<typename T>
67-
array::array(const dim4 &dims, const T *ptr, af_source_t src, dim_type ngfor) : arr(0), isRef(false)
68-
{
69-
initDataArray<T>(&arr, ptr, src, dims[0], dims[1], dims[2], dims[3]);
70-
}
71-
72-
template<typename T>
73-
array::array(dim_type d0, const T *ptr, af_source_t src, dim_type ngfor) : arr(0), isRef(false)
74-
{
75-
initDataArray<T>(&arr, ptr, src, d0);
76-
}
77-
78-
template<typename T>
79-
array::array(dim_type d0, dim_type d1, const T *ptr,
80-
af_source_t src, dim_type ngfor) : arr(0), isRef(false)
81-
{
82-
initDataArray<T>(&arr, ptr, src, d0, d1);
83-
}
84-
85-
template<typename T>
86-
array::array(dim_type d0, dim_type d1, dim_type d2, const T *ptr,
87-
af_source_t src, dim_type ngfor) : arr(0), isRef(false)
88-
{
89-
initDataArray<T>(&arr, ptr, src, d0, d1, d2);
90-
}
91-
92-
template<typename T>
93-
array::array(dim_type d0, dim_type d1, dim_type d2, dim_type d3,
94-
const T *ptr, af_source_t src, dim_type ngfor) : arr(0), isRef(false)
95-
{
96-
initDataArray<T>(&arr, ptr, src, d0, d1, d2, d3);
97-
}
66+
#define INSTANTIATE(T) \
67+
template<> AFAPI \
68+
array::array(const dim4 &dims, const T *ptr, af_source_t src, dim_type ngfor) \
69+
: arr(0), isRef(false) \
70+
{ \
71+
initDataArray<T>(&arr, ptr, src, dims[0], dims[1], dims[2], dims[3]); \
72+
} \
73+
template<> AFAPI \
74+
array::array(dim_type d0, const T *ptr, af_source_t src, dim_type ngfor) \
75+
: arr(0), isRef(false) \
76+
{ \
77+
initDataArray<T>(&arr, ptr, src, d0); \
78+
} \
79+
template<> AFAPI \
80+
array::array(dim_type d0, dim_type d1, const T *ptr, af_source_t src, \
81+
dim_type ngfor) : arr(0), isRef(false) \
82+
{ \
83+
initDataArray<T>(&arr, ptr, src, d0, d1); \
84+
} \
85+
template<> AFAPI \
86+
array::array(dim_type d0, dim_type d1, dim_type d2, const T *ptr, \
87+
af_source_t src, dim_type ngfor) : arr(0), isRef(false) \
88+
{ \
89+
initDataArray<T>(&arr, ptr, src, d0, d1, d2); \
90+
} \
91+
template<> AFAPI \
92+
array::array(dim_type d0, dim_type d1, dim_type d2, dim_type d3, const T *ptr, \
93+
af_source_t src, dim_type ngfor) : arr(0), isRef(false) \
94+
{ \
95+
initDataArray<T>(&arr, ptr, src, d0, d1, d2, d3); \
96+
} \
97+
98+
INSTANTIATE(af_cdouble)
99+
INSTANTIATE(af_cfloat)
100+
INSTANTIATE(double)
101+
INSTANTIATE(float)
102+
INSTANTIATE(unsigned)
103+
INSTANTIATE(int)
104+
INSTANTIATE(unsigned char)
105+
INSTANTIATE(char)
106+
#undef INSTANTIATE
98107

99108
array::~array()
100109
{
@@ -376,27 +385,6 @@ namespace af
376385
return *this;
377386
}
378387

379-
#define INSTANTIATE(T) \
380-
template array::array<T>(const dim4 &dims, const T *ptr, af_source_t src, dim_type ngfor);\
381-
template array::array<T>(dim_type d0, const T *ptr, af_source_t src, dim_type ngfor);\
382-
template array::array<T>(dim_type d0, dim_type d1, const T *ptr, af_source_t src, dim_type ngfor);\
383-
template array::array<T>(dim_type d0, dim_type d1, dim_type d2, const T *ptr, af_source_t src, dim_type ngfor);\
384-
template array::array<T>(dim_type d0, dim_type d1, dim_type d2, dim_type d3, const T *ptr, af_source_t src, dim_type ngfor);\
385-
template T *array::host<T>() const;
386-
387-
388-
INSTANTIATE(af_cdouble)
389-
INSTANTIATE(af_cfloat)
390-
INSTANTIATE(double)
391-
INSTANTIATE(float)
392-
INSTANTIATE(unsigned)
393-
INSTANTIATE(int)
394-
INSTANTIATE(unsigned char)
395-
INSTANTIATE(char)
396-
397-
#undef INSTANTIATE
398-
399-
400388
///////////////////////////////////////////////////////////////////////////
401389
// Operator +=, -=, *=, /=
402390
///////////////////////////////////////////////////////////////////////////

src/array/convolve.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include <af/signal.h>
1111
#include "error.hpp"
12+
#include <algorithm>
1213

1314
namespace af
1415
{

src/backend/cpu/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ FIND_PACKAGE(FFTW REQUIRED)
66
MESSAGE(STATUS "FFTW Found ? ${FFTW_FOUND}")
77
MESSAGE(STATUS "FFTW Library: ${FFTW_LIBRARIES}")
88

9+
IF(NOT UNIX)
10+
ADD_DEFINITIONS(-DAFDLL)
11+
ENDIF()
12+
913
INCLUDE_DIRECTORIES(
1014
${CMAKE_INCLUDE_PATH}
1115
${CMAKE_SOURCE_DIR}/src/backend/cpu

src/backend/cuda/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,17 @@ INCLUDE(${CMAKE_SOURCE_DIR}/common/FindNVVM.cmake)
33
INCLUDE(${CMAKE_SOURCE_DIR}/common/CUDACheckCompute.cmake)
44

55
FIND_PACKAGE(Boost)
6-
INCLUDE_DIRECTORIES(${BOOST_INCLUDE_DIR})
6+
7+
IF(NOT UNIX)
8+
ADD_DEFINITIONS(-DAFDLL)
9+
ENDIF()
710

811
ADD_DEFINITIONS(-DAF_CUDA)
912
REMOVE_DEFINITIONS(-std=c++0x)
1013

1114
INCLUDE_DIRECTORIES(
1215
${CMAKE_INCLUDE_PATH}
16+
${Boost_INCLUDE_DIR}
1317
${CUDA_INCLUDE_DIRS}
1418
${CMAKE_SOURCE_DIR}/src/backend/cuda
1519
${CMAKE_CURRENT_BINARY_DIR}

src/backend/cuda/blas.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ Array<T>* matmul(const Array<T> &lhs, const Array<T> &rhs,
179179
&beta , out->get(), out->dims()[0]);
180180

181181
if(err != CUBLAS_STATUS_SUCCESS) {
182-
std::cout << __func__<< " ERROR: " << cublasErrorString(err) << std::endl;
182+
std::cout <<__PRETTY_FUNCTION__<< " ERROR: " << cublasErrorString(err) << std::endl;
183183
}
184184
}
185185

src/backend/cuda/complex.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
namespace cuda
1818
{
1919
template<typename T> static const char *cplx2_name() { return "___noop"; }
20-
template<> const char *cplx2_name<cfloat>() { return "___cplxCss"; }
21-
template<> const char *cplx2_name<cdouble>() { return "___cplxZdd"; }
20+
template<> STATIC_ const char *cplx2_name<cfloat>() { return "___cplxCss"; }
21+
template<> STATIC_ const char *cplx2_name<cdouble>() { return "___cplxZdd"; }
2222

2323
template<typename To, typename Ti>
2424
Array<To>* complexOp(const Array<Ti> &lhs, const Array<Ti> &rhs)

src/backend/cuda/driver.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
int nvDriverVersion(char *result, int len)
2020
{
21+
#if 0
2122
LPCTSTR lptstrFilename = "nvcuda.dll";
2223
DWORD dwLen, dwHandle;
2324
LPVOID lpData = NULL;
@@ -46,7 +47,8 @@ int nvDriverVersion(char *result, int len)
4647
snprintf(result, len, "%.2f", fversion);
4748

4849
free(lpData);
49-
50+
#endif
51+
snprintf(result, len, "%.2f", 0.0);
5052
return 1;
5153
}
5254

src/backend/cuda/err_cuda.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
cudaError_t _cuda_error = fn; \
2020
if (_cuda_error != cudaSuccess) { \
2121
char cuda_err_msg[1024]; \
22-
snprintf(cuda_err_msg, \
22+
snprintf(cuda_err_msg, \
2323
sizeof(cuda_err_msg), \
2424
"CUDA Error (%d): %s\n", \
2525
(int)(_cuda_error), \
@@ -29,4 +29,4 @@
2929
AF_ERROR(cuda_err_msg, \
3030
AF_ERR_INTERNAL); \
3131
} \
32-
} while(0)
32+
} while(0)

src/backend/cuda/jit.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ static string getKernelString(string funcName, Node *node)
160160
nvvmResult res = fn; \
161161
if (res == NVVM_SUCCESS) break; \
162162
char nvvm_err_msg[1024]; \
163-
snprintf(nvvm_err_msg, \
163+
snprintf(nvvm_err_msg, \
164164
sizeof(nvvm_err_msg), \
165165
"NVVM Error (%d): %s\n", \
166166
(int)(res), msg); \
@@ -212,7 +212,7 @@ typedef struct {
212212
CUresult res = fn; \
213213
if (res == CUDA_SUCCESS) break; \
214214
char cu_err_msg[1024]; \
215-
snprintf(cu_err_msg, \
215+
snprintf(cu_err_msg, \
216216
sizeof(cu_err_msg), \
217217
"CU Error (%d)\n", \
218218
(int)(res)); \

0 commit comments

Comments
 (0)