Skip to content

Commit

Permalink
Fix some build issues (#320)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
borg323 authored Sep 3, 2018
1 parent 8545297 commit 3287af2
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 40 deletions.
21 changes: 11 additions & 10 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,8 @@ if get_option('build_backends')
tf_dl_lib = cc.find_library('dl', required: false)
tf_tensorflow_lib = cc.find_library('libtensorflow_cc',
dirs: tensorflow_libdir, required: false)
tf_protobuf_lib = cc.find_library('libprotobuf',
dirs: tensorflow_libdir, required: false)

if get_option('tensorflow') and tf_dl_lib.found() and tf_tensorflow_lib.found() and tf_protobuf_lib.found()
if get_option('tensorflow') and tf_dl_lib.found() and tf_tensorflow_lib.found()
includes += include_directories(
tensorflow_include,
tensorflow_include[0] + '/bazel-genfiles',
Expand All @@ -141,7 +139,7 @@ if get_option('build_backends')
tensorflow_include[0] + '/tensorflow/contrib/makefile/gen/protobuf-host/include',
is_system: true
)
deps += [tf_dl_lib, tf_tensorflow_lib, tf_protobuf_lib]
deps += [tf_dl_lib, tf_tensorflow_lib]
files += 'src/neural/network_tf.cc'
has_backends = true
endif
Expand Down Expand Up @@ -198,7 +196,14 @@ if get_option('build_backends')

deps += [ openblas_lib ]
has_blas = true
endif

if has_blas
blas_files = [
'src/neural/blas/batchnorm.cc',
'src/neural/blas/fully_connected_layer.cc',
'src/neural/blas/winograd_convolution3.cc'
]
endif

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

if get_option('blas') and has_blas

blas_files = [
'src/neural/blas/batchnorm.cc',
blas_files += [
'src/neural/blas/convolution1.cc',
'src/neural/blas/fully_connected_layer.cc',
'src/neural/blas/winograd_convolution3.cc',
'src/neural/blas/network_blas.cc'
]

Expand Down Expand Up @@ -290,7 +292,7 @@ if get_option('build_backends')
]

if not get_option('blas')
opencl_files += 'src/neural/blas/transforms.cc'
opencl_files += blas_files
endif

includes += include_directories(get_option('opencl_include'))
Expand Down Expand Up @@ -318,7 +320,6 @@ if get_option('build_backends')
]

if get_option('cudnn') and cu_blas.found() and cu_dnn.found() and cu_dart.found() and nvcc.found()
includes += include_directories(get_option('cudnn_include'))
deps += [cu_blas, cu_dnn, cu_dart]
cuda_arguments = ['-c', '@INPUT@', '-o', '@OUTPUT@',
'-I', meson.current_source_dir() + '/src']
Expand Down
2 changes: 1 addition & 1 deletion meson_options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ option('mkl_include',

option('cudnn_include',
type: 'array',
value: [],
value: ['/usr/local/cuda/include/'],
description: 'Paths to cudnn include directory')

option('build_backends',
Expand Down
59 changes: 30 additions & 29 deletions src/neural/opencl/cl2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,8 @@
cl::unmapSVM(inputB);
cl::unmapSVM(output2);
cl_int error;
vectorAddKernel(
cl_int error;
vectorAddKernel(
cl::EnqueueArgs(
cl::NDRange(numElements/2),
cl::NDRange(numElements/2)),
Expand All @@ -369,7 +369,7 @@
3,
aPipe,
defaultDeviceQueue,
error
error
);
cl::copy(outputBuffer, begin(output), end(output));
Expand Down Expand Up @@ -1139,6 +1139,8 @@ inline cl_int getInfoHelper(Func f, cl_uint name, T* param, int, typename T::cl_
F(cl_device_info, CL_DEVICE_MEM_BASE_ADDR_ALIGN, cl_uint) \
F(cl_device_info, CL_DEVICE_MIN_DATA_TYPE_ALIGN_SIZE, cl_uint) \
F(cl_device_info, CL_DEVICE_SINGLE_FP_CONFIG, cl_device_fp_config) \
F(cl_device_info, CL_DEVICE_DOUBLE_FP_CONFIG, cl_device_fp_config) \
F(cl_device_info, CL_DEVICE_HALF_FP_CONFIG, cl_device_fp_config) \
F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHE_TYPE, cl_device_mem_cache_type) \
F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE, cl_uint)\
F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHE_SIZE, cl_ulong) \
Expand Down Expand Up @@ -1235,8 +1237,6 @@ inline cl_int getInfoHelper(Func f, cl_uint name, T* param, int, typename T::cl_
F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT, cl_uint) \
F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE, cl_uint) \
F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF, cl_uint) \
F(cl_device_info, CL_DEVICE_DOUBLE_FP_CONFIG, cl_device_fp_config) \
F(cl_device_info, CL_DEVICE_HALF_FP_CONFIG, cl_device_fp_config) \
F(cl_device_info, CL_DEVICE_OPENCL_C_VERSION, string) \
\
F(cl_mem_info, CL_MEM_ASSOCIATED_MEMOBJECT, cl::Memory) \
Expand Down Expand Up @@ -1830,8 +1830,6 @@ class Wrapper<cl_device_id>

cl_type get() const { return object_; }

cl_type get() { return object_; }

protected:
template<typename Func, typename U>
friend inline cl_int getInfoHelper(Func, cl_uint, U*, int, typename U::cl_type);
Expand Down Expand Up @@ -2744,7 +2742,9 @@ class Context
error = platforms[i].getDevices(type, &devices);

#if defined(CL_HPP_ENABLE_EXCEPTIONS)
} catch (Error) {}
} catch (cl::Error& e) {
error = e.err();
}
// Catch if exceptions are enabled as we don't want to exit if first platform has no devices of type
// We do error checking next anyway, and can throw there if needed
#endif
Expand Down Expand Up @@ -3069,7 +3069,7 @@ class Event : public detail::Wrapper<cl_event>
*/
cl_int setCallback(
cl_int type,
void (CL_CALLBACK * pfn_notify)(cl_event, cl_int, void *),
void (CL_CALLBACK * pfn_notify)(cl_event, cl_int, void *),
void * user_data = NULL)
{
return detail::errHandler(
Expand Down Expand Up @@ -3258,7 +3258,7 @@ class Memory : public detail::Wrapper<cl_mem>
* value - not the Memory class instance.
*/
cl_int setDestructorCallback(
void (CL_CALLBACK * pfn_notify)(cl_mem, void *),
void (CL_CALLBACK * pfn_notify)(cl_mem, void *),
void * user_data = NULL)
{
return detail::errHandler(
Expand Down Expand Up @@ -3849,7 +3849,7 @@ class Buffer : public Memory
}

return result;
}
}
#endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
};

Expand Down Expand Up @@ -4269,7 +4269,7 @@ class Image1D : public Image
{
CL_MEM_OBJECT_IMAGE1D,
width,
0, 0, 0, 0, 0, 0, 0, {0}
0, 0, 0, 0, 0, 0, 0, 0
};
object_ = ::clCreateImage(
context(),
Expand Down Expand Up @@ -4358,7 +4358,7 @@ class Image1DBuffer : public Image
CL_MEM_OBJECT_IMAGE1D_BUFFER,
width,
0, 0, 0, 0, 0, 0, 0,
{buffer()}
buffer()
};
object_ = ::clCreateImage(
context(),
Expand Down Expand Up @@ -4446,7 +4446,7 @@ class Image1DArray : public Image
0, 0, // height, depth (unused)
arraySize,
rowPitch,
0, 0, 0, {0}
0, 0, 0, 0
};
object_ = ::clCreateImage(
context(),
Expand Down Expand Up @@ -4561,7 +4561,7 @@ class Image2D : public Image
height,
0, 0, // depth, array size (unused)
row_pitch,
0, 0, 0, {0}
0, 0, 0, 0
};
object_ = ::clCreateImage(
context(),
Expand Down Expand Up @@ -4879,7 +4879,7 @@ class Image2DArray : public Image
arraySize,
rowPitch,
slicePitch,
0, 0, {0}
0, 0, 0
};
object_ = ::clCreateImage(
context(),
Expand Down Expand Up @@ -4994,7 +4994,7 @@ class Image3D : public Image
0, // array size (unused)
row_pitch,
slice_pitch,
0, 0, {0}
0, 0, 0
};
object_ = ::clCreateImage(
context(),
Expand Down Expand Up @@ -5927,27 +5927,28 @@ class Kernel : public detail::Wrapper<cl_kernel>
);
}

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

template<int index, int ArrayLength, typename T0, typename... Ts>
template<int index, int ArrayLength, typename T0, typename T1, typename... Ts>
typename std::enable_if<std::is_pointer<T0>::value, void>::type
setSVMPointersHelper(std::array<void*, ArrayLength> &pointerList, T0 t0, Ts... ts)
setSVMPointersHelper(std::array<void*, ArrayLength> &pointerList, T0 t0, T1 t1, Ts... ts)
{
pointerList[index] = static_cast<void*>(t0);
setSVMPointersHelper<index + 1, Ts...>(ts...);
setSVMPointersHelper<index + 1, ArrayLength>(pointerList, t1, ts...);
}

template<int index, int ArrayLength, typename T0, class D>
void setSVMPointersHelper(std::array<void*, ArrayLength> &pointerList, const pointer<T0, D> &t0)
{
pointerList[index] = static_cast<void*>(t0.get());
}


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

template<typename T0, typename... Ts>
cl_int setSVMPointers(const T0 &t0, Ts... ts)
cl_int setSVMPointers(const T0 &t0, Ts & ... ts)
{
std::array<void*, 1 + sizeof...(Ts)> pointerList;

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

return err;
}

#if CL_HPP_TARGET_OPENCL_VERSION >= 110
cl_int enqueueReadBufferRect(
const Buffer& buffer,
cl_bool blocking,
Expand Down Expand Up @@ -7323,7 +7324,7 @@ class CommandQueue : public detail::Wrapper<cl_command_queue>

return err;
}

#endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
#if CL_HPP_TARGET_OPENCL_VERSION >= 120
/**
* Enqueue a command to fill a buffer object with a pattern
Expand Down Expand Up @@ -9533,7 +9534,7 @@ class KernelFunctor
}

template<typename T0, typename... T1s>
cl_int setSVMPointers(const T0 &t0, T1s... ts)
cl_int setSVMPointers(const T0 &t0, T1s &... ts)
{
return kernel_.setSVMPointers(t0, ts...);
}
Expand Down Expand Up @@ -9675,4 +9676,4 @@ namespace compatibility {

} // namespace cl

#endif // CL_HPP_
#endif // CL_HPP_

0 comments on commit 3287af2

Please sign in to comment.