forked from cms-sw/cmssw
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Next prototype of the framework integration (#100)
Provide a mechanism for a chain of modules to share a resource, that can be e.g. CUDA device memory or a CUDA stream. Minimize data movements between the CPU and the device, and support multiple devices. Allow the same job configuration to be used on all hardware combinations. See HeterogeneousCore/CUDACore/README.md for a more detailed description and examples.
- Loading branch information
Showing
114 changed files
with
3,928 additions
and
1,107 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<use name="cuda-api-wrappers"/> | ||
<use name="FWCore/ServiceRegistry"/> | ||
<use name="HeterogeneousCore/CUDAServices"/> | ||
|
||
<export> | ||
<lib name="1"/> | ||
</export> |
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,51 @@ | ||
#ifndef CUDADataFormats_Common_CUDAProduct_h | ||
#define CUDADataFormats_Common_CUDAProduct_h | ||
|
||
#include <memory> | ||
|
||
#include <cuda/api_wrappers.h> | ||
|
||
#include "CUDADataFormats/Common/interface/CUDAProductBase.h" | ||
|
||
namespace edm { | ||
template <typename T> class Wrapper; | ||
} | ||
|
||
/** | ||
* The purpose of this class is to wrap CUDA data to edm::Event in a | ||
* way which forces correct use of various utilities. | ||
* | ||
* The non-default construction has to be done with CUDAScopedContext | ||
* (in order to properly register the CUDA event). | ||
* | ||
* The default constructor is needed only for the ROOT dictionary generation. | ||
* | ||
* The CUDA event is in practice needed only for stream-stream | ||
* synchronization, but someone with long-enough lifetime has to own | ||
* it. Here is a somewhat natural place. If overhead is too much, we | ||
* can e.g. make CUDAService own them (creating them on demand) and | ||
* use them only where synchronization between streams is needed. | ||
*/ | ||
template <typename T> | ||
class CUDAProduct: public CUDAProductBase { | ||
public: | ||
CUDAProduct() = default; // Needed only for ROOT dictionary generation | ||
|
||
CUDAProduct(const CUDAProduct&) = delete; | ||
CUDAProduct& operator=(const CUDAProduct&) = delete; | ||
CUDAProduct(CUDAProduct&&) = default; | ||
CUDAProduct& operator=(CUDAProduct&&) = default; | ||
|
||
private: | ||
friend class CUDAScopedContext; | ||
friend class edm::Wrapper<CUDAProduct<T>>; | ||
|
||
explicit CUDAProduct(int device, std::shared_ptr<cuda::stream_t<>> stream, T data): | ||
CUDAProductBase(device, std::move(stream)), | ||
data_(std::move(data)) | ||
{} | ||
|
||
T data_; //! | ||
}; | ||
|
||
#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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#ifndef CUDADataFormats_Common_CUDAProductBase_h | ||
#define CUDADataFormats_Common_CUDAProductBase_h | ||
|
||
#include <memory> | ||
|
||
#include <cuda/api_wrappers.h> | ||
|
||
/** | ||
* Base class for all instantiations of CUDA<T> to hold the | ||
* non-T-dependent members. | ||
*/ | ||
class CUDAProductBase { | ||
public: | ||
CUDAProductBase() = default; // Needed only for ROOT dictionary generation | ||
|
||
bool isValid() const { return stream_.get() != nullptr; } | ||
|
||
int device() const { return device_; } | ||
|
||
const cuda::stream_t<>& stream() const { return *stream_; } | ||
cuda::stream_t<>& stream() { return *stream_; } | ||
const std::shared_ptr<cuda::stream_t<>>& streamPtr() const { return stream_; } | ||
|
||
const cuda::event_t& event() const { return *event_; } | ||
cuda::event_t& event() { return *event_; } | ||
|
||
protected: | ||
explicit CUDAProductBase(int device, std::shared_ptr<cuda::stream_t<>> stream); | ||
|
||
private: | ||
// The cuda::stream_t is really shared among edm::Event products, so | ||
// using shared_ptr also here | ||
std::shared_ptr<cuda::stream_t<>> stream_; //! | ||
// shared_ptr because of caching in CUDAService | ||
std::shared_ptr<cuda::event_t> event_; //! | ||
|
||
int device_ = -1; //! | ||
}; | ||
|
||
#endif |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,19 @@ | ||
#include "CUDADataFormats/Common/interface/CUDAProductBase.h" | ||
|
||
#include "FWCore/ServiceRegistry/interface/Service.h" | ||
#include "HeterogeneousCore/CUDAServices/interface/CUDAService.h" | ||
|
||
CUDAProductBase::CUDAProductBase(int device, std::shared_ptr<cuda::stream_t<>> stream): | ||
stream_(std::move(stream)), | ||
device_(device) | ||
{ | ||
edm::Service<CUDAService> cs; | ||
event_ = cs->getCUDAEvent(); | ||
|
||
// Record CUDA event to the CUDA stream. The event will become | ||
// "occurred" after all work queued to the stream before this | ||
// point has been finished. | ||
event_->record(stream_->id()); | ||
} | ||
|
||
|
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,5 @@ | ||
<bin file="test*.cc" name="testCUDADataFormatsCommon"> | ||
<use name="HeterogeneousCore/CUDACore"/> | ||
<use name="catch2"/> | ||
<use name="cuda"/> | ||
</bin> |
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,63 @@ | ||
#include "catch.hpp" | ||
|
||
#include "CUDADataFormats/Common/interface/CUDAProduct.h" | ||
#include "HeterogeneousCore/CUDACore/interface/CUDAScopedContext.h" | ||
#include "HeterogeneousCore/CUDAUtilities/interface/cudaCheck.h" | ||
#include "HeterogeneousCore/CUDAUtilities/interface/exitSansCUDADevices.h" | ||
|
||
#include <cuda_runtime_api.h> | ||
|
||
namespace cudatest { | ||
class TestCUDAScopedContext { | ||
public: | ||
static | ||
CUDAScopedContext make(int dev) { | ||
auto device = cuda::device::get(dev); | ||
return CUDAScopedContext(dev, std::make_unique<cuda::stream_t<>>(device.create_stream(cuda::stream::implicitly_synchronizes_with_default_stream))); | ||
} | ||
}; | ||
} | ||
|
||
TEST_CASE("Use of CUDAProduct template", "[CUDACore]") { | ||
SECTION("Default constructed") { | ||
auto foo = CUDAProduct<int>(); | ||
REQUIRE(!foo.isValid()); | ||
|
||
auto bar = std::move(foo); | ||
} | ||
|
||
exitSansCUDADevices(); | ||
|
||
constexpr int defaultDevice = 0; | ||
{ | ||
auto ctx = cudatest::TestCUDAScopedContext::make(defaultDevice); | ||
std::unique_ptr<CUDAProduct<int>> dataPtr = ctx.wrap(10); | ||
auto& data = *dataPtr; | ||
|
||
SECTION("Construct from CUDAScopedContext") { | ||
REQUIRE(data.isValid()); | ||
REQUIRE(data.device() == defaultDevice); | ||
REQUIRE(data.stream().id() == ctx.stream().id()); | ||
REQUIRE(&data.event() != nullptr); | ||
} | ||
|
||
SECTION("Move constructor") { | ||
auto data2 = CUDAProduct<int>(std::move(data)); | ||
REQUIRE(data2.isValid()); | ||
REQUIRE(!data.isValid()); | ||
} | ||
|
||
SECTION("Move assignment") { | ||
CUDAProduct<int> data2; | ||
data2 = std::move(data); | ||
REQUIRE(data2.isValid()); | ||
REQUIRE(!data.isValid()); | ||
} | ||
} | ||
|
||
// Destroy and clean up all resources so that the next test can | ||
// assume to start from a clean state. | ||
cudaCheck(cudaSetDevice(defaultDevice)); | ||
cudaCheck(cudaDeviceSynchronize()); | ||
cudaDeviceReset(); | ||
} |
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,2 @@ | ||
#define CATCH_CONFIG_MAIN | ||
#include "catch.hpp" |
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,8 @@ | ||
#ifndef CUDADataFormats_SiPixelCluster_classes_h | ||
#define CUDADataFormats_SiPixelCluster_classes_h | ||
|
||
#include "CUDADataFormats/Common/interface/CUDAProduct.h" | ||
#include "CUDADataFormats/SiPixelCluster/interface/SiPixelClustersCUDA.h" | ||
#include "DataFormats/Common/interface/Wrapper.h" | ||
|
||
#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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<lcgdict> | ||
<class name="CUDAProduct<SiPixelClustersCUDA>" persistent="false"/> | ||
<class name="edm::Wrapper<CUDAProduct<SiPixelClustersCUDA>>" persistent="false"/> | ||
</lcgdict> |
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
Oops, something went wrong.