Revert to normal vector without allocators
Prohibit vector type in indices
This commit is contained in:
parent
ed6206b543
commit
72335f320e
@ -23,11 +23,6 @@ const static auto exe_policy = oneapi::dpl::execution::device_policy<>{
|
||||
oneapi::dpl::execution::make_device_policy(cl::sycl::default_selector{})
|
||||
};
|
||||
|
||||
template<typename T> using Allocator = sycl::usm_allocator<T, sycl::usm::alloc::shared>;
|
||||
|
||||
template<class T>
|
||||
constexpr Allocator<T> alloc_vec() { return {exe_policy.queue()}; };
|
||||
|
||||
template<typename T>
|
||||
T *alloc_raw(size_t size) { return sycl::malloc_shared<T>(size, exe_policy.queue()); }
|
||||
|
||||
@ -61,11 +56,6 @@ static constexpr auto exe_policy = std::execution::par_unseq;
|
||||
|
||||
#ifdef USE_STD_PTR_ALLOC_DEALLOC
|
||||
|
||||
template<typename T> using Allocator = std::allocator<T>;
|
||||
|
||||
template<class T>
|
||||
constexpr Allocator<T> alloc_vec() { return {}; };
|
||||
|
||||
template<typename T>
|
||||
T *alloc_raw(size_t size) { return (T *) aligned_alloc(ALIGNMENT, sizeof(T) * size); }
|
||||
|
||||
|
||||
@ -18,7 +18,7 @@ template <class T>
|
||||
STDDataStream<T>::STDDataStream(const int ARRAY_SIZE, int device)
|
||||
noexcept : array_size{ARRAY_SIZE},
|
||||
#ifdef USE_VECTOR
|
||||
a(ARRAY_SIZE, alloc_vec<T>()), b(ARRAY_SIZE, alloc_vec<T>()), c(ARRAY_SIZE, alloc_vec<T>())
|
||||
a(ARRAY_SIZE), b(ARRAY_SIZE), c(ARRAY_SIZE)
|
||||
#else
|
||||
a(alloc_raw<T>(ARRAY_SIZE)), b(alloc_raw<T>(ARRAY_SIZE)), c(alloc_raw<T>(ARRAY_SIZE))
|
||||
#endif
|
||||
@ -69,28 +69,28 @@ void STDDataStream<T>::copy()
|
||||
{
|
||||
// c[i] = a[i]
|
||||
std::copy(exe_policy, BEGIN(a), END(a), BEGIN(c));
|
||||
}
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void STDDataStream<T>::mul()
|
||||
{
|
||||
// b[i] = scalar * c[i];
|
||||
std::transform(exe_policy, BEGIN(c), END(c), BEGIN(b), [scalar = startScalar](T ci){ return scalar*ci; });
|
||||
}
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void STDDataStream<T>::add()
|
||||
{
|
||||
// c[i] = a[i] + b[i];
|
||||
std::transform(exe_policy, BEGIN(a), END(a), BEGIN(b), BEGIN(c), std::plus<T>());
|
||||
}
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void STDDataStream<T>::triad()
|
||||
{
|
||||
// a[i] = b[i] + scalar * c[i];
|
||||
std::transform(exe_policy, BEGIN(b), END(b), BEGIN(c), BEGIN(a), [scalar = startScalar](T bi, T ci){ return bi+scalar*ci; });
|
||||
}
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void STDDataStream<T>::nstream()
|
||||
@ -101,7 +101,7 @@ void STDDataStream<T>::nstream()
|
||||
// 2: a[i] += scalar * c[i];
|
||||
std::transform(exe_policy, BEGIN(a), END(a), BEGIN(b), BEGIN(a), [](T ai, T bi){ return ai + bi; });
|
||||
std::transform(exe_policy, BEGIN(a), END(a), BEGIN(c), BEGIN(a), [scalar = startScalar](T ai, T ci){ return ai + scalar*ci; });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template <class T>
|
||||
|
||||
@ -23,7 +23,7 @@ class STDDataStream : public Stream<T>
|
||||
|
||||
// Device side pointers
|
||||
#ifdef USE_VECTOR
|
||||
std::vector<T, Allocator<T>> a, b, c;
|
||||
std::vector<T> a, b, c;
|
||||
#else
|
||||
T *a, *b, *c;
|
||||
#endif
|
||||
|
||||
@ -22,11 +22,21 @@
|
||||
#define END(x) ((x) + array_size)
|
||||
#endif
|
||||
|
||||
#ifdef USE_VECTOR
|
||||
#if (defined(__NVCOMPILER) || defined(__NVCOMPILER_LLVM__))
|
||||
#error "std::vector *is* supported in NVHPC if we capture `this`, however, oneDPL (via SYCL2020) only works correctly with explicit *value* captures."
|
||||
#endif
|
||||
|
||||
#if defined(USE_ONEDPL)
|
||||
#error "std::vector is unspported: oneDPL (via SYCL2020) only works correctly with explicit *value* captures"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
template <class T>
|
||||
STDIndicesStream<T>::STDIndicesStream(const int ARRAY_SIZE, int device)
|
||||
noexcept : array_size{ARRAY_SIZE}, range(0, array_size),
|
||||
#ifdef USE_VECTOR
|
||||
a(ARRAY_SIZE, alloc_vec<T>()), b(ARRAY_SIZE, alloc_vec<T>()), c(ARRAY_SIZE, alloc_vec<T>())
|
||||
a(ARRAY_SIZE), b(ARRAY_SIZE), c(ARRAY_SIZE)
|
||||
#else
|
||||
a(alloc_raw<T>(ARRAY_SIZE)), b(alloc_raw<T>(ARRAY_SIZE)), c(alloc_raw<T>(ARRAY_SIZE))
|
||||
#endif
|
||||
@ -77,7 +87,7 @@ void STDIndicesStream<T>::copy()
|
||||
{
|
||||
// c[i] = a[i]
|
||||
std::copy(exe_policy, BEGIN(a), END(a), BEGIN(c));
|
||||
}
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void STDIndicesStream<T>::mul()
|
||||
@ -86,7 +96,7 @@ void STDIndicesStream<T>::mul()
|
||||
std::transform(exe_policy, range.begin(), range.end(), BEGIN(b), [c = this->c, scalar = startScalar](int i) {
|
||||
return scalar * c[i];
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void STDIndicesStream<T>::add()
|
||||
@ -95,7 +105,7 @@ void STDIndicesStream<T>::add()
|
||||
std::transform(exe_policy, range.begin(), range.end(), BEGIN(c), [a = this->a, b = this->b](int i) {
|
||||
return a[i] + b[i];
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void STDIndicesStream<T>::triad()
|
||||
@ -104,7 +114,7 @@ void STDIndicesStream<T>::triad()
|
||||
std::transform(exe_policy, range.begin(), range.end(), BEGIN(a), [b = this->b, c = this->c, scalar = startScalar](int i) {
|
||||
return b[i] + scalar * c[i];
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void STDIndicesStream<T>::nstream()
|
||||
@ -116,7 +126,7 @@ void STDIndicesStream<T>::nstream()
|
||||
std::transform(exe_policy, range.begin(), range.end(), BEGIN(a), [a = this->a, b = this->b, c = this->c, scalar = startScalar](int i) {
|
||||
return a[i] + b[i] + scalar * c[i];
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template <class T>
|
||||
|
||||
@ -78,7 +78,7 @@ class STDIndicesStream : public Stream<T>
|
||||
|
||||
// Device side pointers
|
||||
#ifdef USE_VECTOR
|
||||
std::vector<T, Allocator<T>> a, b, c;
|
||||
std::vector<T> a, b, c;
|
||||
#else
|
||||
T *a, *b, *c;
|
||||
#endif
|
||||
|
||||
@ -26,7 +26,7 @@ template <class T>
|
||||
STDRangesStream<T>::STDRangesStream(const int ARRAY_SIZE, int device)
|
||||
noexcept : array_size{ARRAY_SIZE},
|
||||
#ifdef USE_VECTOR
|
||||
a(ARRAY_SIZE, alloc_vec<T>()), b(ARRAY_SIZE, alloc_vec<T>()), c(ARRAY_SIZE, alloc_vec<T>())
|
||||
a(ARRAY_SIZE), b(ARRAY_SIZE), c(ARRAY_SIZE)
|
||||
#else
|
||||
a(alloc_raw<T>(ARRAY_SIZE)), b(alloc_raw<T>(ARRAY_SIZE)), c(alloc_raw<T>(ARRAY_SIZE))
|
||||
#endif
|
||||
@ -89,7 +89,7 @@ void STDRangesStream<T>::copy()
|
||||
c[i] = a[i];
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void STDRangesStream<T>::mul()
|
||||
@ -103,7 +103,7 @@ void STDRangesStream<T>::mul()
|
||||
b[i] = scalar * c[i];
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void STDRangesStream<T>::add()
|
||||
@ -115,7 +115,7 @@ void STDRangesStream<T>::add()
|
||||
c[i] = a[i] + b[i];
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void STDRangesStream<T>::triad()
|
||||
@ -129,7 +129,7 @@ void STDRangesStream<T>::triad()
|
||||
a[i] = b[i] + scalar * c[i];
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void STDRangesStream<T>::nstream()
|
||||
@ -143,7 +143,7 @@ void STDRangesStream<T>::nstream()
|
||||
a[i] += b[i] + scalar * c[i];
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
template <class T>
|
||||
T STDRangesStream<T>::dot()
|
||||
|
||||
@ -22,7 +22,7 @@ class STDRangesStream : public Stream<T>
|
||||
|
||||
// Device side pointers
|
||||
#ifdef USE_VECTOR
|
||||
std::vector<T, Allocator<T>> a, b, c;
|
||||
std::vector<T> a, b, c;
|
||||
#else
|
||||
T *a, *b, *c;
|
||||
#endif
|
||||
|
||||
Loading…
Reference in New Issue
Block a user