Skip to content

Commit 3287af2

Browse files
authored
Fix some build issues (#320)
* protobuf is now a hard requirement so no need to check it for tf * fix opencl build without blas backend * cudnn_includes is for nvcc only and breaks opencl if added in includes * add default cudnn include path * use latest cl2.hpp from https://github.com/KhronosGroup/OpenCL-CLHPP/blob/master/input_cl2.hpp
1 parent 8545297 commit 3287af2

File tree

3 files changed

+42
-40
lines changed

3 files changed

+42
-40
lines changed

meson.build

+11-10
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,8 @@ if get_option('build_backends')
127127
tf_dl_lib = cc.find_library('dl', required: false)
128128
tf_tensorflow_lib = cc.find_library('libtensorflow_cc',
129129
dirs: tensorflow_libdir, required: false)
130-
tf_protobuf_lib = cc.find_library('libprotobuf',
131-
dirs: tensorflow_libdir, required: false)
132130

133-
if get_option('tensorflow') and tf_dl_lib.found() and tf_tensorflow_lib.found() and tf_protobuf_lib.found()
131+
if get_option('tensorflow') and tf_dl_lib.found() and tf_tensorflow_lib.found()
134132
includes += include_directories(
135133
tensorflow_include,
136134
tensorflow_include[0] + '/bazel-genfiles',
@@ -141,7 +139,7 @@ if get_option('build_backends')
141139
tensorflow_include[0] + '/tensorflow/contrib/makefile/gen/protobuf-host/include',
142140
is_system: true
143141
)
144-
deps += [tf_dl_lib, tf_tensorflow_lib, tf_protobuf_lib]
142+
deps += [tf_dl_lib, tf_tensorflow_lib]
145143
files += 'src/neural/network_tf.cc'
146144
has_backends = true
147145
endif
@@ -198,7 +196,14 @@ if get_option('build_backends')
198196

199197
deps += [ openblas_lib ]
200198
has_blas = true
199+
endif
201200

201+
if has_blas
202+
blas_files = [
203+
'src/neural/blas/batchnorm.cc',
204+
'src/neural/blas/fully_connected_layer.cc',
205+
'src/neural/blas/winograd_convolution3.cc'
206+
]
202207
endif
203208

204209
ispc = find_program('ispc', required: false)
@@ -239,11 +244,8 @@ if get_option('build_backends')
239244

240245
if get_option('blas') and has_blas
241246

242-
blas_files = [
243-
'src/neural/blas/batchnorm.cc',
247+
blas_files += [
244248
'src/neural/blas/convolution1.cc',
245-
'src/neural/blas/fully_connected_layer.cc',
246-
'src/neural/blas/winograd_convolution3.cc',
247249
'src/neural/blas/network_blas.cc'
248250
]
249251

@@ -290,7 +292,7 @@ if get_option('build_backends')
290292
]
291293

292294
if not get_option('blas')
293-
opencl_files += 'src/neural/blas/transforms.cc'
295+
opencl_files += blas_files
294296
endif
295297

296298
includes += include_directories(get_option('opencl_include'))
@@ -318,7 +320,6 @@ if get_option('build_backends')
318320
]
319321

320322
if get_option('cudnn') and cu_blas.found() and cu_dnn.found() and cu_dart.found() and nvcc.found()
321-
includes += include_directories(get_option('cudnn_include'))
322323
deps += [cu_blas, cu_dnn, cu_dart]
323324
cuda_arguments = ['-c', '@INPUT@', '-o', '@OUTPUT@',
324325
'-I', meson.current_source_dir() + '/src']

meson_options.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ option('mkl_include',
5555

5656
option('cudnn_include',
5757
type: 'array',
58-
value: [],
58+
value: ['/usr/local/cuda/include/'],
5959
description: 'Paths to cudnn include directory')
6060

6161
option('build_backends',

src/neural/opencl/cl2.hpp

+30-29
Original file line numberDiff line numberDiff line change
@@ -357,8 +357,8 @@
357357
cl::unmapSVM(inputB);
358358
cl::unmapSVM(output2);
359359
360-
cl_int error;
361-
vectorAddKernel(
360+
cl_int error;
361+
vectorAddKernel(
362362
cl::EnqueueArgs(
363363
cl::NDRange(numElements/2),
364364
cl::NDRange(numElements/2)),
@@ -369,7 +369,7 @@
369369
3,
370370
aPipe,
371371
defaultDeviceQueue,
372-
error
372+
error
373373
);
374374
375375
cl::copy(outputBuffer, begin(output), end(output));
@@ -1139,6 +1139,8 @@ inline cl_int getInfoHelper(Func f, cl_uint name, T* param, int, typename T::cl_
11391139
F(cl_device_info, CL_DEVICE_MEM_BASE_ADDR_ALIGN, cl_uint) \
11401140
F(cl_device_info, CL_DEVICE_MIN_DATA_TYPE_ALIGN_SIZE, cl_uint) \
11411141
F(cl_device_info, CL_DEVICE_SINGLE_FP_CONFIG, cl_device_fp_config) \
1142+
F(cl_device_info, CL_DEVICE_DOUBLE_FP_CONFIG, cl_device_fp_config) \
1143+
F(cl_device_info, CL_DEVICE_HALF_FP_CONFIG, cl_device_fp_config) \
11421144
F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHE_TYPE, cl_device_mem_cache_type) \
11431145
F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE, cl_uint)\
11441146
F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHE_SIZE, cl_ulong) \
@@ -1235,8 +1237,6 @@ inline cl_int getInfoHelper(Func f, cl_uint name, T* param, int, typename T::cl_
12351237
F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT, cl_uint) \
12361238
F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE, cl_uint) \
12371239
F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF, cl_uint) \
1238-
F(cl_device_info, CL_DEVICE_DOUBLE_FP_CONFIG, cl_device_fp_config) \
1239-
F(cl_device_info, CL_DEVICE_HALF_FP_CONFIG, cl_device_fp_config) \
12401240
F(cl_device_info, CL_DEVICE_OPENCL_C_VERSION, string) \
12411241
\
12421242
F(cl_mem_info, CL_MEM_ASSOCIATED_MEMOBJECT, cl::Memory) \
@@ -1830,8 +1830,6 @@ class Wrapper<cl_device_id>
18301830

18311831
cl_type get() const { return object_; }
18321832

1833-
cl_type get() { return object_; }
1834-
18351833
protected:
18361834
template<typename Func, typename U>
18371835
friend inline cl_int getInfoHelper(Func, cl_uint, U*, int, typename U::cl_type);
@@ -2744,7 +2742,9 @@ class Context
27442742
error = platforms[i].getDevices(type, &devices);
27452743

27462744
#if defined(CL_HPP_ENABLE_EXCEPTIONS)
2747-
} catch (Error) {}
2745+
} catch (cl::Error& e) {
2746+
error = e.err();
2747+
}
27482748
// Catch if exceptions are enabled as we don't want to exit if first platform has no devices of type
27492749
// We do error checking next anyway, and can throw there if needed
27502750
#endif
@@ -3069,7 +3069,7 @@ class Event : public detail::Wrapper<cl_event>
30693069
*/
30703070
cl_int setCallback(
30713071
cl_int type,
3072-
void (CL_CALLBACK * pfn_notify)(cl_event, cl_int, void *),
3072+
void (CL_CALLBACK * pfn_notify)(cl_event, cl_int, void *),
30733073
void * user_data = NULL)
30743074
{
30753075
return detail::errHandler(
@@ -3258,7 +3258,7 @@ class Memory : public detail::Wrapper<cl_mem>
32583258
* value - not the Memory class instance.
32593259
*/
32603260
cl_int setDestructorCallback(
3261-
void (CL_CALLBACK * pfn_notify)(cl_mem, void *),
3261+
void (CL_CALLBACK * pfn_notify)(cl_mem, void *),
32623262
void * user_data = NULL)
32633263
{
32643264
return detail::errHandler(
@@ -3849,7 +3849,7 @@ class Buffer : public Memory
38493849
}
38503850

38513851
return result;
3852-
}
3852+
}
38533853
#endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
38543854
};
38553855

@@ -4269,7 +4269,7 @@ class Image1D : public Image
42694269
{
42704270
CL_MEM_OBJECT_IMAGE1D,
42714271
width,
4272-
0, 0, 0, 0, 0, 0, 0, {0}
4272+
0, 0, 0, 0, 0, 0, 0, 0
42734273
};
42744274
object_ = ::clCreateImage(
42754275
context(),
@@ -4358,7 +4358,7 @@ class Image1DBuffer : public Image
43584358
CL_MEM_OBJECT_IMAGE1D_BUFFER,
43594359
width,
43604360
0, 0, 0, 0, 0, 0, 0,
4361-
{buffer()}
4361+
buffer()
43624362
};
43634363
object_ = ::clCreateImage(
43644364
context(),
@@ -4446,7 +4446,7 @@ class Image1DArray : public Image
44464446
0, 0, // height, depth (unused)
44474447
arraySize,
44484448
rowPitch,
4449-
0, 0, 0, {0}
4449+
0, 0, 0, 0
44504450
};
44514451
object_ = ::clCreateImage(
44524452
context(),
@@ -4561,7 +4561,7 @@ class Image2D : public Image
45614561
height,
45624562
0, 0, // depth, array size (unused)
45634563
row_pitch,
4564-
0, 0, 0, {0}
4564+
0, 0, 0, 0
45654565
};
45664566
object_ = ::clCreateImage(
45674567
context(),
@@ -4879,7 +4879,7 @@ class Image2DArray : public Image
48794879
arraySize,
48804880
rowPitch,
48814881
slicePitch,
4882-
0, 0, {0}
4882+
0, 0, 0
48834883
};
48844884
object_ = ::clCreateImage(
48854885
context(),
@@ -4994,7 +4994,7 @@ class Image3D : public Image
49944994
0, // array size (unused)
49954995
row_pitch,
49964996
slice_pitch,
4997-
0, 0, {0}
4997+
0, 0, 0
49984998
};
49994999
object_ = ::clCreateImage(
50005000
context(),
@@ -5927,27 +5927,28 @@ class Kernel : public detail::Wrapper<cl_kernel>
59275927
);
59285928
}
59295929

5930-
template<int index, int ArrayLength, class D, typename T0, typename... Ts>
5931-
void setSVMPointersHelper(std::array<void*, ArrayLength> &pointerList, const pointer<T0, D> &t0, Ts... ts)
5930+
template<int index, int ArrayLength, class D, typename T0, typename T1, typename... Ts>
5931+
void setSVMPointersHelper(std::array<void*, ArrayLength> &pointerList, const pointer<T0, D> &t0, const pointer<T1, D> &t1, Ts & ... ts)
59325932
{
59335933
pointerList[index] = static_cast<void*>(t0.get());
5934-
setSVMPointersHelper<index + 1, Ts...>(ts...);
5934+
setSVMPointersHelper<index + 1, ArrayLength>(pointerList, t1, ts...);
59355935
}
59365936

5937-
template<int index, int ArrayLength, typename T0, typename... Ts>
5937+
template<int index, int ArrayLength, typename T0, typename T1, typename... Ts>
59385938
typename std::enable_if<std::is_pointer<T0>::value, void>::type
5939-
setSVMPointersHelper(std::array<void*, ArrayLength> &pointerList, T0 t0, Ts... ts)
5939+
setSVMPointersHelper(std::array<void*, ArrayLength> &pointerList, T0 t0, T1 t1, Ts... ts)
59405940
{
59415941
pointerList[index] = static_cast<void*>(t0);
5942-
setSVMPointersHelper<index + 1, Ts...>(ts...);
5942+
setSVMPointersHelper<index + 1, ArrayLength>(pointerList, t1, ts...);
59435943
}
5944-
5944+
59455945
template<int index, int ArrayLength, typename T0, class D>
59465946
void setSVMPointersHelper(std::array<void*, ArrayLength> &pointerList, const pointer<T0, D> &t0)
59475947
{
59485948
pointerList[index] = static_cast<void*>(t0.get());
59495949
}
59505950

5951+
59515952
template<int index, int ArrayLength, typename T0>
59525953
typename std::enable_if<std::is_pointer<T0>::value, void>::type
59535954
setSVMPointersHelper(std::array<void*, ArrayLength> &pointerList, T0 t0)
@@ -5956,7 +5957,7 @@ class Kernel : public detail::Wrapper<cl_kernel>
59565957
}
59575958

59585959
template<typename T0, typename... Ts>
5959-
cl_int setSVMPointers(const T0 &t0, Ts... ts)
5960+
cl_int setSVMPointers(const T0 &t0, Ts & ... ts)
59605961
{
59615962
std::array<void*, 1 + sizeof...(Ts)> pointerList;
59625963

@@ -7208,7 +7209,7 @@ class CommandQueue : public detail::Wrapper<cl_command_queue>
72087209

72097210
return err;
72107211
}
7211-
7212+
#if CL_HPP_TARGET_OPENCL_VERSION >= 110
72127213
cl_int enqueueReadBufferRect(
72137214
const Buffer& buffer,
72147215
cl_bool blocking,
@@ -7323,7 +7324,7 @@ class CommandQueue : public detail::Wrapper<cl_command_queue>
73237324

73247325
return err;
73257326
}
7326-
7327+
#endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
73277328
#if CL_HPP_TARGET_OPENCL_VERSION >= 120
73287329
/**
73297330
* Enqueue a command to fill a buffer object with a pattern
@@ -9533,7 +9534,7 @@ class KernelFunctor
95339534
}
95349535

95359536
template<typename T0, typename... T1s>
9536-
cl_int setSVMPointers(const T0 &t0, T1s... ts)
9537+
cl_int setSVMPointers(const T0 &t0, T1s &... ts)
95379538
{
95389539
return kernel_.setSVMPointers(t0, ts...);
95399540
}
@@ -9675,4 +9676,4 @@ namespace compatibility {
96759676

96769677
} // namespace cl
96779678

9678-
#endif // CL_HPP_
9679+
#endif // CL_HPP_

0 commit comments

Comments
 (0)