forked from cms-sw/cmssw
-
Notifications
You must be signed in to change notification settings - Fork 2
Triton data converter (CMSSW_11_2_0_pre9) #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dsrankin
wants to merge
21
commits into
fastmachinelearning:master
Choose a base branch
from
dsrankin:triton_converter_11_2_0_pre9
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
2762c02
rebasing to pre9
dsrankin 05f2ca0
formatting and code checks
dsrankin b4a3f2c
cleanup, removing unused PSet arg for converter
dsrankin 5bade57
using std::any to store converter
dsrankin d9bf227
adjusting to handle possibility of multiple converters
dsrankin 920ee4f
fixing typo
dsrankin 47fb54c
removing old comment
dsrankin 70a522b
fixing another typo
dsrankin 037c8b0
adding clear for more complicated conversions
dsrankin 90ce2ed
adding override
dsrankin e653471
fixing bytesize check
dsrankin 6e336a3
removing unnecessary line
dsrankin 8ebdcd0
adding underscore, expanding to multiple converters for inputs and ou…
dsrankin 15c99a4
setting up default behavior
dsrankin 81077f0
a few optimizations
dsrankin 3231ad8
small formatting
dsrankin daabb94
removing unnecessary defs
dsrankin 2dabb92
removing unnecessary defs
dsrankin 9c14bf5
adding ability to get converter from server
dsrankin 4037115
reducing duplication
dsrankin 9faebc0
change empty check
dsrankin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
43 changes: 43 additions & 0 deletions
43
HeterogeneousCore/SonicTriton/interface/TritonConverterBase.h
This file contains hidden or 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,43 @@ | ||
#ifndef HeterogeneousCore_SonicTriton_TritonConverterBase | ||
#define HeterogeneousCore_SonicTriton_TritonConverterBase | ||
|
||
#include "FWCore/ParameterSet/interface/ParameterSet.h" | ||
#include "DataFormats/Common/interface/Handle.h" | ||
|
||
#include <string> | ||
|
||
template <typename DT> | ||
class TritonConverterBase { | ||
//class needs to be templated since the convert functions require the data type, but need to also be virtual, and virtual member function templates are not allowed in C++ | ||
public: | ||
TritonConverterBase(const std::string convName) | ||
: converterName_(convName), byteSize_(sizeof(DT)) {} | ||
TritonConverterBase(const std::string convName, size_t byteSize) | ||
: converterName_(convName), byteSize_(byteSize) {} | ||
TritonConverterBase(const TritonConverterBase&) = delete; | ||
virtual ~TritonConverterBase() = default; | ||
TritonConverterBase& operator=(const TritonConverterBase&) = delete; | ||
|
||
virtual const uint8_t* convertIn (const DT* in) const = 0; | ||
virtual const DT* convertOut (const uint8_t* in) const = 0; | ||
|
||
const int64_t byteSize() const { return byteSize_; } | ||
|
||
const std::string& name() const { return converterName_; } | ||
|
||
virtual void clear() const {} | ||
|
||
private: | ||
const std::string converterName_; | ||
const int64_t byteSize_; | ||
}; | ||
|
||
#include "FWCore/PluginManager/interface/PluginFactory.h" | ||
|
||
template <typename DT> | ||
using TritonConverterFactory = edmplugin::PluginFactory<TritonConverterBase<DT>*()>; | ||
|
||
#define DEFINE_TRITON_CONVERTER(input, type, name) DEFINE_EDM_PLUGIN(TritonConverterFactory<input>, type, name) | ||
#define DEFINE_TRITON_CONVERTER_SIMPLE(input, type) DEFINE_EDM_PLUGIN(TritonConverterFactory<input>, type, #type) | ||
|
||
#endif |
This file contains hidden or 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 hidden or 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 @@ | ||
<library name="HeterogeneousCoreSonicTritonPlugins_converters" file="converters/*.cc"> | ||
<use name="HeterogeneousCore/SonicTriton"/> | ||
<use name="hls"/> | ||
<flags EDM_PLUGIN="1"/> | ||
</library> |
44 changes: 44 additions & 0 deletions
44
HeterogeneousCore/SonicTriton/plugins/converters/FloatApFixed16Converter.cc
This file contains hidden or 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,44 @@ | ||
#include "HeterogeneousCore/SonicTriton/interface/TritonConverterBase.h" | ||
|
||
#include <string> | ||
#include "ap_fixed.h" | ||
|
||
template <int I> | ||
class FloatApFixed16Converter : public TritonConverterBase<float> { | ||
public: | ||
FloatApFixed16Converter() : TritonConverterBase<float>("FloatApFixed16F"+std::to_string(I)+"Converter", 2) {} | ||
|
||
const uint8_t* convertIn(const float* in) const override { | ||
auto temp_vec = std::make_shared<std::vector<ap_fixed<16, I>>>(std::move(this->makeVecIn(in))); | ||
inputHolder_.push_back(temp_vec); | ||
return reinterpret_cast<const uint8_t*>(temp_vec->data()); | ||
} | ||
const float* convertOut(const uint8_t* in) const override { | ||
auto temp_vec = std::make_shared<std::vector<float>>(std::move(this->makeVecOut(reinterpret_cast<const ap_fixed<16, I>*>(in)))); | ||
outputHolder_.push_back(temp_vec); | ||
return temp_vec->data(); | ||
} | ||
|
||
void clear() const override { | ||
inputHolder_.clear(); | ||
outputHolder_.clear(); | ||
} | ||
|
||
private: | ||
std::vector<ap_fixed<16, I>> makeVecIn(const float* in) const { | ||
unsigned int nfeat = sizeof(in) / sizeof(float); | ||
std::vector<ap_fixed<16, I>> temp_storage(in, in + nfeat); | ||
return temp_storage; | ||
} | ||
|
||
std::vector<float> makeVecOut(const ap_fixed<16, I>* in) const { | ||
unsigned int nfeat = sizeof(in) / sizeof(ap_fixed<16, I>); | ||
std::vector<float> temp_storage(in, in + nfeat); | ||
return temp_storage; | ||
} | ||
|
||
mutable std::vector<std::shared_ptr<std::vector<ap_fixed<16, I>>>> inputHolder_; | ||
mutable std::vector<std::shared_ptr<std::vector<float>>> outputHolder_; | ||
}; | ||
|
||
DEFINE_TRITON_CONVERTER(float, FloatApFixed16Converter<6>, "FloatApFixed16F6Converter"); |
11 changes: 11 additions & 0 deletions
11
HeterogeneousCore/SonicTriton/plugins/converters/FloatStandardConverter.cc
This file contains hidden or 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,11 @@ | ||
#include "HeterogeneousCore/SonicTriton/interface/TritonConverterBase.h" | ||
|
||
class FloatStandardConverter : public TritonConverterBase<float> { | ||
public: | ||
FloatStandardConverter() : TritonConverterBase<float>("FloatStandardConverter") {} | ||
|
||
const uint8_t* convertIn(const float* in) const override { return reinterpret_cast<const uint8_t*>(in); } | ||
const float* convertOut(const uint8_t* in) const override { return reinterpret_cast<const float*>(in); } | ||
}; | ||
|
||
DEFINE_TRITON_CONVERTER_SIMPLE(float, FloatStandardConverter); |
11 changes: 11 additions & 0 deletions
11
HeterogeneousCore/SonicTriton/plugins/converters/Int64StandardConverter.cc
This file contains hidden or 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,11 @@ | ||
#include "HeterogeneousCore/SonicTriton/interface/TritonConverterBase.h" | ||
|
||
class Int64StandardConverter : public TritonConverterBase<int64_t> { | ||
public: | ||
Int64StandardConverter() : TritonConverterBase<int64_t>("Int64StandardConverter") {} | ||
|
||
const uint8_t* convertIn(const int64_t* in) const override { return reinterpret_cast<const uint8_t*>(in); } | ||
const int64_t* convertOut(const uint8_t* in) const override { return reinterpret_cast<const int64_t*>(in); } | ||
}; | ||
|
||
DEFINE_TRITON_CONVERTER_SIMPLE(int64_t, Int64StandardConverter); |
This file contains hidden or 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 hidden or 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 hidden or 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 @@ | ||
#include "HeterogeneousCore/SonicTriton/interface/TritonConverterBase.h" | ||
|
||
EDM_REGISTER_PLUGINFACTORY(TritonConverterFactory<float>, "TritonConverterFloatFactory"); | ||
EDM_REGISTER_PLUGINFACTORY(TritonConverterFactory<int64_t>, "TritonConverterInt64Factory"); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.