device.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. // ======================================================================== //
  2. // Copyright 2009-2019 Intel Corporation //
  3. // //
  4. // Licensed under the Apache License, Version 2.0 (the "License"); //
  5. // you may not use this file except in compliance with the License. //
  6. // You may obtain a copy of the License at //
  7. // //
  8. // http://www.apache.org/licenses/LICENSE-2.0 //
  9. // //
  10. // Unless required by applicable law or agreed to in writing, software //
  11. // distributed under the License is distributed on an "AS IS" BASIS, //
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. //
  13. // See the License for the specific language governing permissions and //
  14. // limitations under the License. //
  15. // ======================================================================== //
  16. #pragma once
  17. #include "common.h"
  18. namespace oidn {
  19. class Buffer;
  20. class Filter;
  21. class Device : public RefCount, public Verbose
  22. {
  23. private:
  24. // Thread-safety
  25. std::mutex mutex;
  26. // Error handling
  27. struct ErrorState
  28. {
  29. Error code = Error::None;
  30. std::string message;
  31. };
  32. static thread_local ErrorState globalError;
  33. ThreadLocal<ErrorState> error;
  34. ErrorFunction errorFunc = nullptr;
  35. void* errorUserPtr = nullptr;
  36. // -- GODOT start --
  37. // // Tasking
  38. // std::shared_ptr<tbb::task_arena> arena;
  39. // std::shared_ptr<PinningObserver> observer;
  40. // std::shared_ptr<ThreadAffinity> affinity;
  41. // -- GODOT end --
  42. // Parameters
  43. int numThreads = 0; // autodetect by default
  44. bool setAffinity = true;
  45. bool dirty = true;
  46. public:
  47. Device();
  48. ~Device();
  49. static void setError(Device* device, Error code, const std::string& message);
  50. static Error getError(Device* device, const char** outMessage);
  51. void setErrorFunction(ErrorFunction func, void* userPtr);
  52. int get1i(const std::string& name);
  53. void set1i(const std::string& name, int value);
  54. void commit();
  55. // -- GODOT start --
  56. // template<typename F>
  57. // void executeTask(F& f)
  58. // {
  59. // arena->execute(f);
  60. // }
  61. // template<typename F>
  62. // void executeTask(const F& f)
  63. // {
  64. // arena->execute(f);
  65. // }
  66. // -- GODOT end --
  67. Ref<Buffer> newBuffer(size_t byteSize);
  68. Ref<Buffer> newBuffer(void* ptr, size_t byteSize);
  69. Ref<Filter> newFilter(const std::string& type);
  70. __forceinline Device* getDevice() { return this; }
  71. __forceinline std::mutex& getMutex() { return mutex; }
  72. private:
  73. // -- GODOT start --
  74. //bool isCommitted() const { return bool(arena); }
  75. bool isCommitted() const { return false; }
  76. // -- GODOT end --
  77. void checkCommitted();
  78. void print();
  79. };
  80. } // namespace oidn