-
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
base: master
Are you sure you want to change the base?
Changes from 13 commits
2762c02
05f2ca0
b4a3f2c
5bade57
d9bf227
920ee4f
47fb54c
70a522b
037c8b0
90ce2ed
e653471
6e336a3
8ebdcd0
15c99a4
81077f0
3231ad8
daabb94
2dabb92
9c14bf5
4037115
9faebc0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 | ||
| 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> |
| 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"); |
| 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); |
| 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); |
| 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"); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,6 +29,40 @@ | |
| "TritonGraphProducer": "gat_test", | ||
| } | ||
|
|
||
| inConvs = { | ||
| "TritonImageProducer": cms.VPSet( | ||
|
||
| cms.PSet( | ||
| converterName = cms.string("FloatStandardConverter"), | ||
| inputName = cms.string("gpu_0/data"), | ||
| ), | ||
| ), | ||
| "TritonGraphProducer": cms.VPSet( | ||
| cms.PSet( | ||
| converterName = cms.string("FloatStandardConverter"), | ||
| inputName = cms.string("x__0"), | ||
| ), | ||
| cms.PSet( | ||
| converterName = cms.string("Int64StandardConverter"), | ||
| inputName = cms.string("edgeindex__1"), | ||
| ), | ||
| ), | ||
| } | ||
|
|
||
| outConvs = { | ||
| "TritonImageProducer": cms.VPSet( | ||
| cms.PSet( | ||
| converterName = cms.string("FloatStandardConverter"), | ||
| outputName = cms.string("gpu_0/softmax"), | ||
| ), | ||
| ), | ||
| "TritonGraphProducer": cms.VPSet( | ||
| cms.PSet( | ||
| converterName = cms.string("FloatStandardConverter"), | ||
| outputName = cms.string("logits__0"), | ||
| ), | ||
| ), | ||
| } | ||
|
|
||
| if options.producer not in models: | ||
| raise ValueError("Unknown producer: "+options.producer) | ||
|
|
||
|
|
@@ -49,6 +83,8 @@ | |
| modelVersion = cms.string(""), | ||
| verbose = cms.untracked.bool(options.verbose), | ||
| allowedTries = cms.untracked.uint32(0), | ||
| inputConverters = inConvs[options.producer], | ||
| outputConverters = outConvs[options.producer], | ||
| ) | ||
| ) | ||
| if options.producer=="TritonImageProducer": | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.