Skip to content

Instantly share code, notes, and snippets.

@andylshort
Created April 3, 2020 16:04
Show Gist options
  • Save andylshort/d7bbcba71365b480ea7bebf5250a9b87 to your computer and use it in GitHub Desktop.
Save andylshort/d7bbcba71365b480ea7bebf5250a9b87 to your computer and use it in GitHub Desktop.
Minimal failing example of ClangJIT and Kokkos/mdspan
#include <experimental/mdspan>
#include <iostream>
#include <cstdlib>
#include <array>
namespace stdex = std::experimental;
template<const int x, const int y>
[[clang::jit]] void
kernel(stdex::mdspan<double, x, y>& f)
{
for (int k = 0; k < y; ++k)
for (int j = 0; j < x; ++j)
f(j, k) = (j + 1) * (k + 1);
}
template<int x, int y>
[[clang::jit]]
void kernel_driver()
{
// Construct
constexpr int size = x * y;
double* d = new double[size];
for (int i=0;i<y;i++)
for(int j=0;j<x;j++)
d[i*x+j] = i * j;
stdex::mdspan<double,x,y> f = stdex::mdspan<double, x, y>(d);
// Execute
kernel<x, y>(f);
// Verify
for (int k = 0; k < y; ++k)
{
for (int j = 0; j < x; ++j)
{
std::cout << f(j, k) << " ";
}
std::cout << std::endl;
}
}
int main(int argc, char* argv[])
{
int x = std::atoi(argv[1]);
int y = std::atoi(argv[2]);
kernel_driver<x, y>();
}
/*
* compile with clang++ -fjit test.cpp -o jit
* run with ./jit 2 2
*
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
In file included from /home/aaals/test_jit/test.cpp:1:
In file included from /home/aaals/software/mdspan/include/experimental/mdspan:49:
In file included from /home/aaals/software/mdspan/include/experimental/__p0009_bits/basic_mdspan.hpp:48:
In file included from /home/aaals/software/mdspan/include/experimental/__p0009_bits/layout_right.hpp:47:
In file included from /home/aaals/software/mdspan/include/experimental/__p0009_bits/fixed_layout_impl.hpp:46:
/home/aaals/software/mdspan/include/experimental/__p0009_bits/mixed_size_storage.hpp:108:23: error:
no matching member function for call to '_select'
return Idx == N ? _select<Size, DynamicOffset>(integral_constant<bool, Size ...
^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/aaals/software/mdspan/include/experimental/__p0009_bits/mixed_size_storage.hpp:134:37: note:
in instantiation of function template specialization
'std::experimental::detail::mixed_static_and_dynamic_size_storage<std::integer_sequence<long,
2, 2>, std::integer_sequence<long, 0, 0>, std::integer_sequence<unsigned long, 0,
1> >::select_n<2, 0, 0, 0, 0>' requested here
return _MDSPAN_FOLD_PLUS_RIGHT((select_n<Sizes, DynamicOffsets, Idxs, N, 0>(...
^
/home/aaals/software/mdspan/include/experimental/__p0009_bits/extents.hpp:240:30: note:
in instantiation of function template specialization
'std::experimental::detail::mixed_static_and_dynamic_size_storage<std::integer_sequence<long,
2, 2>, std::integer_sequence<long, 0, 0>, std::integer_sequence<unsigned long, 0,
1> >::get<0>' requested here
return _storage.template get<N>();
^
/home/aaals/software/mdspan/include/experimental/__p0009_bits/fixed_layout_impl.hpp:111:93: note:
in instantiation of function template specialization
'std::experimental::extents<2, 2>::__extent<0>' requested here
...N) ? base_t::__extents.template __extent<Idxs>() : 1), //* * ... * // 1);
^
/home/aaals/software/mdspan/include/experimental/__p0009_bits/fixed_layout_impl.hpp:150:67: note:
in instantiation of function template specialization
'std::experimental::detail::stride_storage_impl<std::experimental::extents<2, 2>,
std::integer_sequence<unsigned long, 0, 1>,
std::experimental::detail::layout_right_idx_conditional>::get_stride<0>' requested
here
return _MDSPAN_FOLD_PLUS_RIGHT((idxs * this->base_t::template get_stride<Idx...
^
/home/aaals/software/mdspan/include/experimental/__p0009_bits/basic_mdspan.hpp:253:30: note:
in instantiation of function template specialization
'std::experimental::detail::fixed_layout_common_impl<std::experimental::extents<2,
2>, std::integer_sequence<unsigned long, 0, 1>,
std::experimental::detail::layout_right_idx_conditional>::operator()<long, long>'
requested here
return acc_.access(ptr_, map_(index_type(indices)...));
^
/home/aaals/test_jit/test.cpp:38:26: note: in instantiation of function template
specialization 'std::experimental::basic_mdspan<double,
std::experimental::extents<2, 2>, std::experimental::layout_right,
std::experimental::accessor_basic<double> >::operator()<int, int, 0>' requested
here
std::cout << f(j, k) << " ";
^
/home/aaals/test_jit/test.cpp:48:5: note: in instantiation of function template
specialization 'kernel_driver<2, 2>' requested here
kernel_driver<x, y>();
^
/home/aaals/test_jit/test.cpp:48:5: note: in instantiation of function template
specialization 'kernel_driver<2, 2>' requested here
/home/aaals/software/mdspan/include/experimental/__p0009_bits/mixed_size_storage.hpp:85:23: note:
candidate function template not viable: no known conversion from
'integral_constant<[...], 2L == dynamic_extent aka false>' to
'integral_constant<[...], true>' for 1st argument
constexpr ptrdiff_t _select(true_type) const noexcept { return dynamic_sizes.t...
^
/home/aaals/software/mdspan/include/experimental/__p0009_bits/mixed_size_storage.hpp:88:23: note:
candidate function template not viable: no known conversion from
'integral_constant<...>' to 'integral_constant<...>' for 1st argument
constexpr ptrdiff_t _select(false_type) const noexcept { return Size; }
^
/home/aaals/software/mdspan/include/experimental/__p0009_bits/mixed_size_storage.hpp:108:23: error:
no matching member function for call to '_select'
return Idx == N ? _select<Size, DynamicOffset>(integral_constant<bool, Size ...
^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/aaals/software/mdspan/include/experimental/__p0009_bits/mixed_size_storage.hpp:134:37: note:
in instantiation of function template specialization
'std::experimental::detail::mixed_static_and_dynamic_size_storage<std::integer_sequence<long,
2, 2>, std::integer_sequence<long, 0, 0>, std::integer_sequence<unsigned long, 0,
1> >::select_n<2, 0, 1, 0, 0>' requested here
return _MDSPAN_FOLD_PLUS_RIGHT((select_n<Sizes, DynamicOffsets, Idxs, N, 0>(...
^
/home/aaals/software/mdspan/include/experimental/__p0009_bits/extents.hpp:240:30: note:
in instantiation of function template specialization
'std::experimental::detail::mixed_static_and_dynamic_size_storage<std::integer_sequence<long,
2, 2>, std::integer_sequence<long, 0, 0>, std::integer_sequence<unsigned long, 0,
1> >::get<0>' requested here
return _storage.template get<N>();
^
/home/aaals/software/mdspan/include/experimental/__p0009_bits/fixed_layout_impl.hpp:111:93: note:
in instantiation of function template specialization
'std::experimental::extents<2, 2>::__extent<0>' requested here
...N) ? base_t::__extents.template __extent<Idxs>() : 1), /* * ... * * / 1);
^
/home/aaals/software/mdspan/include/experimental/__p0009_bits/fixed_layout_impl.hpp:150:67: note:
in instantiation of function template specialization
'std::experimental::detail::stride_storage_impl<std::experimental::extents<2, 2>,
std::integer_sequence<unsigned long, 0, 1>,
std::experimental::detail::layout_right_idx_conditional>::get_stride<0>' requested
here
return _MDSPAN_FOLD_PLUS_RIGHT((idxs * this->base_t::template get_stride<Idx...
^
/home/aaals/software/mdspan/include/experimental/__p0009_bits/basic_mdspan.hpp:253:30: note:
in instantiation of function template specialization
'std::experimental::detail::fixed_layout_common_impl<std::experimental::extents<2,
2>, std::integer_sequence<unsigned long, 0, 1>,
std::experimental::detail::layout_right_idx_conditional>::operator()<long, long>'
requested here
return acc_.access(ptr_, map_(index_type(indices)...));
^
/home/aaals/test_jit/test.cpp:38:26: note: in instantiation of function template
specialization 'std::experimental::basic_mdspan<double,
std::experimental::extents<2, 2>, std::experimental::layout_right,
std::experimental::accessor_basic<double> >::operator()<int, int, 0>' requested
here
std::cout << f(j, k) << " ";
^
/home/aaals/test_jit/test.cpp:48:5: note: in instantiation of function template
specialization 'kernel_driver<2, 2>' requested here
kernel_driver<x, y>();
^
/home/aaals/test_jit/test.cpp:48:5: note: in instantiation of function template
specialization 'kernel_driver<2, 2>' requested here
/home/aaals/software/mdspan/include/experimental/__p0009_bits/mixed_size_storage.hpp:85:23: note:
candidate function template not viable: no known conversion from
'integral_constant<[...], 2L == dynamic_extent aka false>' to
'integral_constant<[...], true>' for 1st argument
constexpr ptrdiff_t _select(true_type) const noexcept { return dynamic_sizes.t...
^
/home/aaals/software/mdspan/include/experimental/__p0009_bits/mixed_size_storage.hpp:88:23: note:
candidate function template not viable: no known conversion from
'integral_constant<...>' to 'integral_constant<...>' for 1st argument
constexpr ptrdiff_t _select(false_type) const noexcept { return Size; }
^
/home/aaals/software/mdspan/include/experimental/__p0009_bits/mixed_size_storage.hpp:108:23: error:
no matching member function for call to '_select'
return Idx == N ? _select<Size, DynamicOffset>(integral_constant<bool, Size ...
^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/aaals/software/mdspan/include/experimental/__p0009_bits/mixed_size_storage.hpp:134:37: note:
in instantiation of function template specialization
'std::experimental::detail::mixed_static_and_dynamic_size_storage<std::integer_sequence<long,
2, 2>, std::integer_sequence<long, 0, 0>, std::integer_sequence<unsigned long, 0,
1> >::select_n<2, 0, 0, 1, 0>' requested here
return _MDSPAN_FOLD_PLUS_RIGHT((select_n<Sizes, DynamicOffsets, Idxs, N, 0>(...
^
/home/aaals/software/mdspan/include/experimental/__p0009_bits/extents.hpp:240:30: note:
in instantiation of function template specialization
'std::experimental::detail::mixed_static_and_dynamic_size_storage<std::integer_sequence<long,
2, 2>, std::integer_sequence<long, 0, 0>, std::integer_sequence<unsigned long, 0,
1> >::get<1>' requested here
return _storage.template get<N>();
^
/home/aaals/software/mdspan/include/experimental/__p0009_bits/fixed_layout_impl.hpp:111:93: note:
in instantiation of function template specialization
'std::experimental::extents<2, 2>::__extent<1>' requested here
...N) ? base_t::__extents.template __extent<Idxs>() : 1), /* * ... * * / 1);
^
/home/aaals/software/mdspan/include/experimental/__p0009_bits/fixed_layout_impl.hpp:150:67: note:
in instantiation of function template specialization
'std::experimental::detail::stride_storage_impl<std::experimental::extents<2, 2>,
std::integer_sequence<unsigned long, 0, 1>,
std::experimental::detail::layout_right_idx_conditional>::get_stride<0>' requested
here
return _MDSPAN_FOLD_PLUS_RIGHT((idxs * this->base_t::template get_stride<Idx...
^
/home/aaals/software/mdspan/include/experimental/__p0009_bits/basic_mdspan.hpp:253:30: note:
in instantiation of function template specialization
'std::experimental::detail::fixed_layout_common_impl<std::experimental::extents<2,
2>, std::integer_sequence<unsigned long, 0, 1>,
std::experimental::detail::layout_right_idx_conditional>::operator()<long, long>'
requested here
return acc_.access(ptr_, map_(index_type(indices)...));
^
/home/aaals/test_jit/test.cpp:38:26: note: in instantiation of function template
specialization 'std::experimental::basic_mdspan<double,
std::experimental::extents<2, 2>, std::experimental::layout_right,
std::experimental::accessor_basic<double> >::operator()<int, int, 0>' requested
here
std::cout << f(j, k) << " ";
^
/home/aaals/test_jit/test.cpp:48:5: note: in instantiation of function template
specialization 'kernel_driver<2, 2>' requested here
kernel_driver<x, y>();
^
/home/aaals/test_jit/test.cpp:48:5: note: in instantiation of function template
specialization 'kernel_driver<2, 2>' requested here
/home/aaals/software/mdspan/include/experimental/__p0009_bits/mixed_size_storage.hpp:85:23: note:
candidate function template not viable: no known conversion from
'integral_constant<[...], 2L == dynamic_extent aka false>' to
'integral_constant<[...], true>' for 1st argument
constexpr ptrdiff_t _select(true_type) const noexcept { return dynamic_sizes.t...
^
/home/aaals/software/mdspan/include/experimental/__p0009_bits/mixed_size_storage.hpp:88:23: note:
candidate function template not viable: no known conversion from
'integral_constant<...>' to 'integral_constant<...>' for 1st argument
constexpr ptrdiff_t _select(false_type) const noexcept { return Size; }
^
/home/aaals/software/mdspan/include/experimental/__p0009_bits/mixed_size_storage.hpp:108:23: error:
no matching member function for call to '_select'
return Idx == N ? _select<Size, DynamicOffset>(integral_constant<bool, Size ...
^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/aaals/software/mdspan/include/experimental/__p0009_bits/mixed_size_storage.hpp:134:37: note:
in instantiation of function template specialization
'std::experimental::detail::mixed_static_and_dynamic_size_storage<std::integer_sequence<long,
2, 2>, std::integer_sequence<long, 0, 0>, std::integer_sequence<unsigned long, 0,
1> >::select_n<2, 0, 1, 1, 0>' requested here
return _MDSPAN_FOLD_PLUS_RIGHT((select_n<Sizes, DynamicOffsets, Idxs, N, 0>(...
^
/home/aaals/software/mdspan/include/experimental/__p0009_bits/extents.hpp:240:30: note:
in instantiation of function template specialization
'std::experimental::detail::mixed_static_and_dynamic_size_storage<std::integer_sequence<long,
2, 2>, std::integer_sequence<long, 0, 0>, std::integer_sequence<unsigned long, 0,
1> >::get<1>' requested here
return _storage.template get<N>();
^
/home/aaals/software/mdspan/include/experimental/__p0009_bits/fixed_layout_impl.hpp:111:93: note:
in instantiation of function template specialization
'std::experimental::extents<2, 2>::__extent<1>' requested here
...N) ? base_t::__extents.template __extent<Idxs>() : 1), /* * ... * * / 1);
^
/home/aaals/software/mdspan/include/experimental/__p0009_bits/fixed_layout_impl.hpp:150:67: note:
in instantiation of function template specialization
'std::experimental::detail::stride_storage_impl<std::experimental::extents<2, 2>,
std::integer_sequence<unsigned long, 0, 1>,
std::experimental::detail::layout_right_idx_conditional>::get_stride<0>' requested
here
return _MDSPAN_FOLD_PLUS_RIGHT((idxs * this->base_t::template get_stride<Idx...
^
/home/aaals/software/mdspan/include/experimental/__p0009_bits/basic_mdspan.hpp:253:30: note:
in instantiation of function template specialization
'std::experimental::detail::fixed_layout_common_impl<std::experimental::extents<2,
2>, std::integer_sequence<unsigned long, 0, 1>,
std::experimental::detail::layout_right_idx_conditional>::operator()<long, long>'
requested here
return acc_.access(ptr_, map_(index_type(indices)...));
^
/home/aaals/test_jit/test.cpp:38:26: note: in instantiation of function template
specialization 'std::experimental::basic_mdspan<double,
std::experimental::extents<2, 2>, std::experimental::layout_right,
std::experimental::accessor_basic<double> >::operator()<int, int, 0>' requested
here
std::cout << f(j, k) << " ";
^
/home/aaals/test_jit/test.cpp:48:5: note: in instantiation of function template
specialization 'kernel_driver<2, 2>' requested here
kernel_driver<x, y>();
^
/home/aaals/test_jit/test.cpp:48:5: note: in instantiation of function template
specialization 'kernel_driver<2, 2>' requested here
/home/aaals/software/mdspan/include/experimental/__p0009_bits/mixed_size_storage.hpp:85:23: note:
candidate function template not viable: no known conversion from
'integral_constant<[...], 2L == dynamic_extent aka false>' to
'integral_constant<[...], true>' for 1st argument
constexpr ptrdiff_t _select(true_type) const noexcept { return dynamic_sizes.t...
^
/home/aaals/software/mdspan/include/experimental/__p0009_bits/mixed_size_storage.hpp:88:23: note:
candidate function template not viable: no known conversion from
'integral_constant<...>' to 'integral_constant<...>' for 1st argument
constexpr ptrdiff_t _select(false_type) const noexcept { return Size; }
^
LLVM ERROR: Clang JIT failed!
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment