resource_container.h 965 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #ifndef NLP_SAFT_OPENSOURCE_DRAGNN_CORE_RESOURCE_CONTAINER_H_
  2. #define NLP_SAFT_OPENSOURCE_DRAGNN_CORE_RESOURCE_CONTAINER_H_
  3. #include <memory>
  4. #include "syntaxnet/base.h"
  5. #include "tensorflow/core/framework/resource_mgr.h"
  6. namespace syntaxnet {
  7. namespace dragnn {
  8. using tensorflow::strings::StrCat;
  9. // Wrapper to store a data type T in the ResourceMgr. There should be one per
  10. // Session->Run() call that may happen concurrently.
  11. template <class T>
  12. class ResourceContainer : public tensorflow::ResourceBase {
  13. public:
  14. explicit ResourceContainer(std::unique_ptr<T> data)
  15. : data_(std::move(data)) {}
  16. ~ResourceContainer() override {}
  17. T *get() { return data_.get(); }
  18. std::unique_ptr<T> release() { return std::move(data_); }
  19. string DebugString() override { return "ResourceContainer"; }
  20. private:
  21. std::unique_ptr<T> data_;
  22. };
  23. } // namespace dragnn
  24. } // namespace syntaxnet
  25. #endif // NLP_SAFT_OPENSOURCE_DRAGNN_CORE_RESOURCE_CONTAINER_H_