-
Notifications
You must be signed in to change notification settings - Fork 403
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added skeleton of batch based GPU assignment
- Loading branch information
1 parent
ae52796
commit 1904331
Showing
9 changed files
with
220 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
#ifndef XTENSOR_DEVICE_HPP | ||
#define XTENSOR_DEVICE_HPP | ||
|
||
#include <memory> | ||
#include <algorithm> | ||
#include <functional> | ||
#include <vector> | ||
|
||
namespace xt{ | ||
namespace detail{ | ||
|
||
} | ||
/** | ||
* Device implementation for the various operations. All device specific code goes in here disabled via macro | ||
* for invalid syntax which might be needed for Sycl or CUDA. | ||
*/ | ||
//#ifdef XTENSOR_DEVICE_ASSIGN | ||
template<class T> | ||
class host_device_batch | ||
{ | ||
public: | ||
host_device_batch(const T* ptr, std::size_t size) | ||
{ | ||
//copy the data to the device | ||
//CUDA Impl = Nearly identical | ||
m_data.resize(size); | ||
std::copy(ptr, ptr + size, std::begin(m_data)); | ||
} | ||
template<class A> | ||
host_device_batch& operator+(const host_device_batch<A>& rhs) | ||
{ | ||
//CUDA impl = thrust::transform(m_data.begin(), m_data.end(), rhs.m_data().begin(), m_data.end(), thrust::plus<T>{}); | ||
std::transform(std::begin(m_data), std::end(m_data), std::begin(rhs.m_data), std::begin(m_data), std::plus<T>{}); | ||
return *this; | ||
} | ||
template<class A> | ||
host_device_batch& operator-(const host_device_batch<A>& rhs) | ||
{ | ||
std::transform(std::begin(m_data), std::end(m_data), std::begin(rhs.m_data), std::begin(m_data), std::minus<T>{}); | ||
return *this; | ||
} | ||
template<class A> | ||
host_device_batch& operator*(const host_device_batch<A>& rhs) | ||
{ | ||
std::transform(std::begin(m_data), std::end(m_data), std::begin(rhs.m_data), std::begin(m_data), std::multiplies<T>{}); | ||
return *this; | ||
} | ||
template<class A> | ||
host_device_batch& operator/(const host_device_batch<A>& rhs) | ||
{ | ||
std::transform(std::begin(m_data), std::end(m_data), std::begin(rhs.m_data), std::begin(m_data), std::divides<T>{}); | ||
return *this; | ||
} | ||
void store_host(T* dst) | ||
{ | ||
std::copy(std::begin(m_data), std::end(m_data), dst); | ||
} | ||
private: | ||
//CUDA impl = thrust::device_vector<T> m_data; | ||
std::vector<T> m_data; | ||
}; | ||
//#endif | ||
|
||
// template<class T> | ||
// class cuda_device_batch : public batch<host_device_batch<T>> | ||
// { | ||
// public: | ||
|
||
// }; | ||
|
||
// template<class T> | ||
// class intel_device_batch : public batch<host_device_batch<T>> | ||
// { | ||
// public: | ||
|
||
// }; | ||
|
||
// template<class T> | ||
// class opencl_device_batch : public batch<host_device_batch<T>> | ||
// { | ||
// public: | ||
|
||
// }; | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/*************************************************************************** | ||
* Copyright (c) Johan Mabille, Sylvain Corlay and Wolf Vollprecht * | ||
* Copyright (c) QuantStack * | ||
* * | ||
* Distributed under the terms of the BSD 3-Clause License. * | ||
* * | ||
* The full license is in the file LICENSE, distributed with this software. * | ||
****************************************************************************/ | ||
// This file is generated from test/files/cppy_source/test_extended_broadcast_view.cppy by preprocess.py! | ||
// Warning: This file should not be modified directly! Instead, modify the `*.cppy` file. | ||
|
||
|
||
#include <algorithm> | ||
|
||
#include "xtensor/xarray.hpp" | ||
#include "xtensor/xfixed.hpp" | ||
#include "xtensor/xnoalias.hpp" | ||
#include "xtensor/xstrided_view.hpp" | ||
#include "xtensor/xtensor.hpp" | ||
#include "xtensor/xview.hpp" | ||
|
||
#include "test_common_macros.hpp" | ||
|
||
namespace xt | ||
{ | ||
TEST(test_xdevice, basic_xfunction) | ||
{ | ||
std::vector<double> expectation = {2,3,4,5,6}; | ||
|
||
xt::xarray<float> a = {1., 2., 3., 4., 5.}; | ||
xt::xarray<float> b = xt::ones_like(a); | ||
auto c = xt::xtensor<float, 1>::from_shape(a.shape()); | ||
c = a + b; | ||
for(size_t i = 0; i < expectation.size(); i++) | ||
{ | ||
ASSERT_EQ(c(i), expectation.at(i)); | ||
} | ||
} | ||
} |