16 #ifndef TENSORFLOW_SERVING_RESOURCES_RESOURCE_UTIL_H_
17 #define TENSORFLOW_SERVING_RESOURCES_RESOURCE_UTIL_H_
22 #include "tensorflow/core/lib/core/status.h"
23 #include "tensorflow/core/platform/macros.h"
24 #include "tensorflow_serving/resources/resources.pb.h"
26 namespace tensorflow {
38 std::map<string, uint32> devices;
50 virtual Status VerifyValidity(
const ResourceAllocation& allocation)
const;
54 Status VerifyOverrideDeviceValidity(
55 const ResourceAllocation& base_allocation,
56 const ResourceAllocation& override_allocation)
const;
60 Status VerifyResourceValidity(
const Resource& resource)
const;
66 virtual ResourceAllocation Normalize(
67 const ResourceAllocation& allocation)
const;
70 virtual bool IsNormalized(
const ResourceAllocation& allocation)
const;
75 bool IsBound(
const ResourceAllocation& allocation)
const;
80 Resource CreateBoundResource(
const string& device,
const string& kind,
81 uint32 device_instance = 0)
const;
86 uint64_t GetQuantity(
const Resource& resource,
87 const ResourceAllocation& allocation)
const;
91 void SetQuantity(
const Resource& resource, uint64_t quantity,
92 ResourceAllocation* allocation)
const;
100 void Add(
const ResourceAllocation& to_add, ResourceAllocation* base)
const;
106 bool Subtract(
const ResourceAllocation& to_subtract,
107 ResourceAllocation* base)
const;
111 void Multiply(uint64_t multiplier, ResourceAllocation* base)
const;
115 bool Equal(
const ResourceAllocation& lhs,
116 const ResourceAllocation& rhs)
const;
120 bool ResourcesEqual(
const Resource& lhs,
const Resource& rhs)
const;
130 bool LessThanOrEqual(
const ResourceAllocation& lhs,
131 const ResourceAllocation& rhs)
const;
144 ResourceAllocation Overbind(
const ResourceAllocation& allocation)
const;
157 ResourceAllocation Max(
const ResourceAllocation& lhs,
158 const ResourceAllocation& rhs)
const;
171 ResourceAllocation Min(
const ResourceAllocation& lhs,
172 const ResourceAllocation& rhs)
const;
179 ResourceAllocation NormalizeResourceAllocation(
180 const ResourceAllocation& allocation)
const;
183 enum class DCHECKFailOption { kDoDCHECKFail, kDoNotDCHECKFail };
186 Status VerifyFunctionInternal(std::function<Status()> fn,
187 DCHECKFailOption dcheck_fail_option)
const;
191 Resource NormalizeResource(
const Resource& resource)
const;
194 bool IsResourceNormalized(
const Resource& resource)
const;
197 bool IsBoundNormalized(
const ResourceAllocation& allocation)
const;
201 void AddNormalized(
const ResourceAllocation& to_add,
202 ResourceAllocation* base)
const;
206 bool SubtractNormalized(
const ResourceAllocation& to_subtract,
207 ResourceAllocation* base)
const;
211 void MultiplyNormalized(uint64_t multiplier, ResourceAllocation* base)
const;
214 bool EqualNormalized(
const ResourceAllocation& lhs,
215 const ResourceAllocation& rhs)
const;
218 bool ResourcesEqualNormalized(
const Resource& lhs,
const Resource& rhs)
const;
221 bool LessThanOrEqualNormalized(
const ResourceAllocation& lhs,
222 const ResourceAllocation& rhs)
const;
226 ResourceAllocation OverbindNormalized(
227 const ResourceAllocation& allocation)
const;
231 ResourceAllocation MaxNormalized(
const ResourceAllocation& lhs,
232 const ResourceAllocation& rhs)
const;
236 ResourceAllocation MinNormalized(
const ResourceAllocation& lhs,
237 const ResourceAllocation& rhs)
const;
240 bool IsResourceAllocationNormalized(
241 const ResourceAllocation& allocation)
const;
243 const std::map<string, uint32> devices_;