Table of Contents
ecuda is a C++ wrapper around the CUDA C API designed to closely resemble and be functionally equivalent to the C++ Standard Template Library (STL). Specifically: algorithms, containers, and iterators. These elements play nice with host containers and can be used in device code.
- CUDA
sudo apt-get -y install cuda # Debian sudo pacman -S cuda # Arch
- Clone the repo
git clone https://github.com/BaderLab/ecuda- Compile and run the tests (optional)
cd ecuda
mkdir build
cmake -DECUDA_BUILD_TESTS=ON
make
ctest --output-on-failureUse FetchContent to add to your own project's CMakeLists.txt.
# the start of your CMakeLists.txt...
include( FetchContent )
FetchContent_Declare(
ecuda
GIT_REPOSITORY https://github.com/BaderLab/ecuda
GIT_TAG "master"
SOURCE_DIR "${CMAKE_BINARY_DIR}/_deps/ecuda-src"
BINARY_DIR "${CMAKE_BINARY_DIR}/_deps/ecuda-build"
)
FetchContent_MakeAvailable( ecuda )
find_package( CUDAToolkit REQUIRED )
# ... the rest of your CMakeLists.txt
target_link_libraries( YourExecutable PUBLIC ecuda::ecuda PRIVATE CUDA::cudart )#include <ecuda.hpp>template<class Container>
__global__
void
reverse_order(
typename Container::const_kernel_argument in,
typename Container::kernel_argument out
)
{
const int t = threadIdx.x;
if( t < in.size() ) {
auto value = *(in.begin()+t);
*(out.begin()+(out.size()-t-1)) = value;
}
}std::vector<double> hostVector( 1000 );
// ... fill hostVector with data
ecuda::vector<double> deviceVector1( hostVector.begin(), hostVector.end() );
ecuda::vector<double> deviceVector2( 1000 );
CUDA_CALL_KERNEL_AND_WAIT( reverse_order<<<1,1000>>>( deviceVector1, deviceVector2 ) );
ecuda::copy( deviceVector2.begin(), deviceVector2.end(), hostVector.begin() );std::vector<double> hostMatrix( 10*10 );
// ... fill hostMatrix with data
ecuda::matrix<double> deviceMatrix1( 10, 10 );
ecuda::matrix<double> deviceMatrix2( 10, 10 );
ecuda::copy( hostMatrix.begin(), hostMatrix.end(), deviceMatrix1.begin() );
CUDA_CALL_KERNEL_AND_WAIT( reverse_order<<<1,10*10>>>( deviceMatrix1, deviceMatrix2 ) );
ecuda::copy( deviceMatrix2.begin(), deviceMatrix2.end(), hostVector.begin() );std::vector<double> hostCube( 10*10*10 );
// ... fill hostCube with data
ecuda::cube<double> deviceCube1( 10, 10, 10 );
ecuda::cube<double> deviceCube2( 10, 10, 10 );
ecuda::copy( hostCube.begin(), hostCube.end(), deviceCube1.begin() );
CUDA_CALL_KERNEL_AND_WAIT( reverse_order<<<1,10*10>>>( deviceCube1, deviceCube2 ) );
ecuda::copy( deviceCube2.begin(), deviceCube2.end(), hostVector.begin() );A quick conversion to doctest for unit testing was performed but it was extremely quick and dirty. A more comprehensive testing regime is needed.
A modernization review is needed. So far only the parts of the API needed for other projects has been reviewed and tested.
See the open issues for a full list of proposed features (and known issues).
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature) - Commit your Changes (
git commit -m 'Add some AmazingFeature') - Push to the Branch (
git push origin feature/AmazingFeature) - Open a Pull Request
Distributed under the Apache 2.0 license. See LICENSE.txt for more information.
Scott D. Zuyderduyn - scott.zuyderduyn@utoronto.ca
Project Link: https://github.com/BaderLab/ecuda
- README based on the othneildrew/Best-README-Template