Skip to content

Instantly share code, notes, and snippets.

@mconcas
Last active February 19, 2021 13:20
Show Gist options
  • Save mconcas/1841e3eea674db11caf3bc22c4ce9040 to your computer and use it in GitHub Desktop.
Save mconcas/1841e3eea674db11caf3bc22c4ce9040 to your computer and use it in GitHub Desktop.
[OpenCL2.0][reproducer] error: taking address of function is not allowed
DEFINES="-DNDEBUG -D__OPENCLCPP__"
FLAGS="-Xclang -fdenormal-fp-math-f32=ieee -cl-mad-enable -cl-no-signed-zeros -ferror-limit=1000 -Xclang -finclude-default-header -Dcl_clang_storage_class_specifiers"
COMPILER=/opt/clang/bin/clang++
reproducer: reproducer.cl
$(COMPILER) -O0 -cl-std=clc++ -x cl -emit-llvm --target=spir64-unknown-unknown $(DEFINES) $(FLAGS) -c reproducer.cl -o reproducer.bc
workaround: workaround.cl
$(COMPILER) -O0 -cl-std=clc++ -x cl -emit-llvm --target=spir64-unknown-unknown $(DEFINES) $(FLAGS) -c workaround.cl -o workaround.bc
clean:
rm reproducer.bc workaround.bc
#define __OPENCL__
#pragma OPENCL EXTENSION cl_clang_storage_class_specifiers : enable
#pragma OPENCL EXTENSION __cl_clang_function_pointers : enable
typedef __SIZE_TYPE__ size_t;
void* operator new (size_t size, void *ptr);
namespace o2::gpu::gpustd
{
template <typename T, size_t N>
struct array {
T& operator[](size_t i) { return m_internal_V__[i]; }
const T& operator[](size_t i) const { return m_internal_V__[i]; }
T m_internal_V__[N];
};
template <class T, class... E>
array(T, E...)->array<T, 1 + sizeof...(E)>;
}
namespace row_offsets_utils
{
template <int...>
struct indices {
};
template <int I, class IndexTuple, int N>
struct make_indices_impl;
template <int I, int... Indices, int N>
struct make_indices_impl<I, indices<Indices...>, N> {
typedef typename make_indices_impl<I + 1, indices<Indices..., I>,
N>::type type;
};
template <int N, int... Indices>
struct make_indices_impl<N, indices<Indices...>, N> {
typedef indices<Indices...> type;
};
template <int N>
struct make_indices : make_indices_impl<0, indices<>, N> {
};
template <int I0, class F, int... I>
constexpr auto do_make(F f, indices<I...>) -> o2::gpu::gpustd::array<int, sizeof...(I)>
{
o2::gpu::gpustd::array<int, sizeof...(I)> retarr = {f(I0 + I)...};
return retarr;
}
template <int N, int I0 = 0, class F>
constexpr auto make(F f) -> o2::gpu::gpustd::array<int, N>
{
return do_make<I0>(f, typename make_indices<N>::type());
}
} // namespace row_offsets_utils
template <class T, unsigned int D>
class MatRepSymGPU
{
static constexpr int off0(int i) { return i == 0 ? 0 : off0(i - 1) + i; }
static constexpr int off2(int i, int j) { return j < i ? off0(i) + j : off0(j) + i; }
static constexpr int off1(int i) { return off2(i / D, i % D); }
static int off(int i)
{
static constexpr auto v = row_offsets_utils::make<D * D>(off1);
return v[i];
}
};
#define __OPENCL__
#pragma OPENCL EXTENSION cl_clang_storage_class_specifiers : enable
#pragma OPENCL EXTENSION __cl_clang_function_pointers : enable
typedef __SIZE_TYPE__ size_t;
void* operator new (size_t size, void *ptr);
namespace o2::gpu::gpustd
{
template <typename T, size_t N>
struct array {
T& operator[](size_t i) { return m_internal_V__[i]; }
const T& operator[](size_t i) const { return m_internal_V__[i]; }
T m_internal_V__[N];
};
template <class T, class... E>
array(T, E...)->array<T, 1 + sizeof...(E)>;
}
namespace row_offsets_utils
{
template <unsigned int D>
struct proxy_offset {
static constexpr int off0(int i) { return i == 0 ? 0 : off0(i - 1) + i; }
static constexpr int off2(int i, int j) { return j < i ? off0(i) + j : off0(j) + i; }
static constexpr int off1(int i) { return off2(i / D, i % D); }
int operator()(int i) const { return off1(i); }
};
template <int...>
struct indices {
};
template <int I, class IndexTuple, int N>
struct make_indices_impl;
template <int I, int... Indices, int N>
struct make_indices_impl<I, indices<Indices...>, N> {
typedef typename make_indices_impl<I + 1, indices<Indices..., I>,
N>::type type;
};
template <int N, int... Indices>
struct make_indices_impl<N, indices<Indices...>, N> {
typedef indices<Indices...> type;
};
template <int N>
struct make_indices : make_indices_impl<0, indices<>, N> {
};
template <int I0, class F, int... I>
constexpr auto do_make(F f, indices<I...>) -> o2::gpu::gpustd::array<int, sizeof...(I)>
{
o2::gpu::gpustd::array<int, sizeof...(I)> retarr = {f(I0 + I)...};
return retarr;
}
template <int N, int I0 = 0, class F>
constexpr auto make(F f) -> o2::gpu::gpustd::array<int, N>
{
return do_make<I0>(f, typename make_indices<N>::type());
}
} // namespace row_offsets_utils
template <class T, unsigned int D>
class MatRepSymGPU
{
static int off(int i)
{
row_offsets_utils::proxy_offset<D> proxy;
static constexpr auto v = row_offsets_utils::make<D * D>(proxy);
return v[i];
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment