diff --git a/include/glow/LLVMIRCodeGen/LLVMBackend.h b/include/glow/LLVMIRCodeGen/LLVMBackend.h index 3ae28d32d8..5dbc84f983 100644 --- a/include/glow/LLVMIRCodeGen/LLVMBackend.h +++ b/include/glow/LLVMIRCodeGen/LLVMBackend.h @@ -44,7 +44,7 @@ class LLVMBackendOptions { /// ABI to be used by this backend. std::string abi_; /// Float ABI to be used by this backend. - llvm::Optional floatABI_; + std::optional floatABI_; /// Code model used by this backend. llvm::CodeModel::Model codeModel_; /// Code model used by this backend for bundles. @@ -75,11 +75,11 @@ class LLVMBackendOptions { /// Sets ABI used by this backend. void setABIName(llvm::StringRef abi) { abi_ = abi.str(); } /// \returns Float ABI used by this backend. - llvm::Optional getFloatABI() const { + std::optional getFloatABI() const { return floatABI_; } /// Sets Float ABI used by this backend. - void setFloatABI(llvm::Optional floatABI) { + void setFloatABI(std::optional floatABI) { floatABI_ = floatABI; } /// \returns code model used by this backend. diff --git a/include/glow/Optimizer/GraphOptimizer/CompilationContext.h b/include/glow/Optimizer/GraphOptimizer/CompilationContext.h index 0c272ddbc9..b237c8bdee 100644 --- a/include/glow/Optimizer/GraphOptimizer/CompilationContext.h +++ b/include/glow/Optimizer/GraphOptimizer/CompilationContext.h @@ -21,6 +21,8 @@ #include "glow/Quantization/Base/Base.h" #include "glow/Support/Error.h" +#include + namespace glow { namespace runtime { struct PartitionConfig; @@ -273,7 +275,7 @@ struct OptimizationOptions { /// If it is true (false), perform (not perform) ASAP op placement in DAG /// optimization; If it is not set, use acc perf GFlag APLASAPPlacement to /// determine whether to perform ASAP op placement or not - llvm::Optional enableAPLASAPPlacement; + std::optional enableAPLASAPPlacement; /// If true does int64 to int32 type demotion if backend supports for specific /// nodes. @@ -311,8 +313,8 @@ struct OptimizationOptions { PRINT_VALUE(foldElemKindConversionIntoIO, dump_str) PRINT_VALUE(foldStaticPlaceholderConversions, dump_str) PRINT_VALUE(useSparseNNPartitioningScheme, dump_str) - if (enableAPLASAPPlacement.hasValue()) { - PRINT_VALUE(enableAPLASAPPlacement.getValue(), dump_str) + if (enableAPLASAPPlacement) { + PRINT_VALUE(enableAPLASAPPlacement.value(), dump_str) } PRINT_VALUE(enableTypeDemotion, dump_str) PRINT_VALUE(enableQuantParamChanges, dump_str) diff --git a/include/glow/Support/TensorPool.h b/include/glow/Support/TensorPool.h index 59c0f6aeeb..1ccf31945b 100644 --- a/include/glow/Support/TensorPool.h +++ b/include/glow/Support/TensorPool.h @@ -17,11 +17,11 @@ #define GLOW_TENSORPOOL_H #include "glow/Base/Tensor.h" -#include "llvm/ADT/Optional.h" #include #include #include +#include #include #include @@ -74,7 +74,7 @@ class TensorPool final { /// previously been added by initialize. If the pool is empty this will /// allocate a new Tensor unless preventAllocs was set true at construction /// time. - llvm::Optional get(TypeRef ty); + std::optional get(TypeRef ty); /// Return a Tensor \p t to the pool. This Tensor must have been previously /// allocated by this TensorPool. diff --git a/lib/Backends/Interpreter/InterpreterNodes.cpp b/lib/Backends/Interpreter/InterpreterNodes.cpp index 4dad851c4f..8c3ed9030c 100644 --- a/lib/Backends/Interpreter/InterpreterNodes.cpp +++ b/lib/Backends/Interpreter/InterpreterNodes.cpp @@ -1476,7 +1476,7 @@ static void fwdMaxPool(Tensor *inW, Tensor *outW, Tensor *argmaxW, ShapeHW kdim(kernelSizes); ShapeHW sdim(strides); - llvm::Optional> argmaxH; + std::optional> argmaxH; if (argmaxW) { argmaxH = argmaxW->getHandle(); } @@ -6678,7 +6678,7 @@ void BoundInterpreterFunction::fwdIntNBitSplitEmbeddingWeightedBagsImpl( auto weightsTysH = weightsTys->getHandle(); auto dimOffsetsH = dimOffsets->getHandle(); auto weightsOffsetsH = weightsOffsets->getHandle(); - llvm::Optional> indiceWeightsH; + std::optional> indiceWeightsH; if (indiceWeights) { indiceWeightsH = indiceWeights->getHandle(); } diff --git a/lib/CodeGen/MemoryAllocator.cpp b/lib/CodeGen/MemoryAllocator.cpp index 4d707d08c4..ece975dfbd 100644 --- a/lib/CodeGen/MemoryAllocator.cpp +++ b/lib/CodeGen/MemoryAllocator.cpp @@ -20,6 +20,7 @@ #include "llvm/ADT/SmallVector.h" #include "llvm/Support/Casting.h" #include "llvm/Support/Debug.h" +#include "llvm/Support/ErrorHandling.h" #include "llvm/Support/raw_ostream.h" #define DEBUG_TYPE "memory-allocator" diff --git a/lib/Graph/Log.cpp b/lib/Graph/Log.cpp index 810397d0ac..301b574f8a 100644 --- a/lib/Graph/Log.cpp +++ b/lib/Graph/Log.cpp @@ -20,6 +20,7 @@ #include "glow/Graph/Graph.h" #include "glow/Graph/Node.h" #include "glow/Graph/NodeValue.h" +#include "llvm/ADT/StringExtras.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/FormatVariadic.h" diff --git a/lib/LLVMIRCodeGen/LLVMIRGen.cpp b/lib/LLVMIRCodeGen/LLVMIRGen.cpp index 20a1831c6b..8da1963558 100644 --- a/lib/LLVMIRCodeGen/LLVMIRGen.cpp +++ b/lib/LLVMIRCodeGen/LLVMIRGen.cpp @@ -99,8 +99,8 @@ static std::mutex initTargetMutex; void LLVMIRGen::initTargetOptions(llvm::TargetOptions &targetOpts, const LLVMBackendOptions &backendOpts) { - if (backendOpts.getFloatABI().hasValue()) { - targetOpts.FloatABIType = backendOpts.getFloatABI().getValue(); + if (backendOpts.getFloatABI().has_value()) { + targetOpts.FloatABIType = backendOpts.getFloatABI().value(); } if (!backendOpts.getABIName().empty()) { targetOpts.MCOptions.ABIName = backendOpts.getABIName(); diff --git a/lib/Onnxifi/Base.cpp b/lib/Onnxifi/Base.cpp index 15f8358845..2b10449a22 100644 --- a/lib/Onnxifi/Base.cpp +++ b/lib/Onnxifi/Base.cpp @@ -347,15 +347,14 @@ onnxStatus Graph::adjustInputs(uint32_t inputsCount, continue; } - llvm::Optional inputTensorOpt = tensorPool_.get(inPhPtr->getType()); - if (!inputTensorOpt.hasValue()) { + std::optional inputTensorOpt = tensorPool_.get(inPhPtr->getType()); + if (!inputTensorOpt.has_value()) { DLOG(FATAL) << "Tensorpool tensor not found for input " << inOnnxTensor.name; return ONNXIFI_STATUS_INTERNAL_ERROR; } // We want fresh DeviceResidencyInfo for this fresh Tensor. - externalIOBindings.emplace_back(inPhPtr, - std::move(inputTensorOpt.getValue())); + externalIOBindings.emplace_back(inPhPtr, std::move(inputTensorOpt.value())); Tensor &inputTensor = externalIOBindings.back().second; inputTensor.resetDeviceInfo(); diff --git a/lib/Optimizer/GraphOptimizer/GraphOptimizer.cpp b/lib/Optimizer/GraphOptimizer/GraphOptimizer.cpp index d514c5d203..ee3548fe92 100644 --- a/lib/Optimizer/GraphOptimizer/GraphOptimizer.cpp +++ b/lib/Optimizer/GraphOptimizer/GraphOptimizer.cpp @@ -5474,9 +5474,9 @@ struct ChannelShuffleParams { /// as ReshapeNode->TransposeNode->ReshapeNode) for which \p node is the leading /// ReshapeNode. \returns The original ChannelShuffle parameters if possible and /// empty Optional otherwise. -static llvm::Optional +static std::optional getChannelShuffleParams(const ReshapeNode &node) { - auto resM = llvm::Optional(); + std::optional resM; llvm::ArrayRef inputDims = node.getInput().dims(); llvm::ArrayRef resultDims = node.getDims(); @@ -5539,7 +5539,7 @@ bool FoldChannelShuffle::run(Function *F, const CompilationContext &cctx) { // Compute the original parameters to ChannelShuffle. auto paramsM = getChannelShuffleParams(*RN1); - if (!paramsM.hasValue()) { + if (!paramsM.has_value()) { continue; } diff --git a/lib/Runtime/HostManager/HostManager.cpp b/lib/Runtime/HostManager/HostManager.cpp index f46e75a83e..bb4f30c2f0 100644 --- a/lib/Runtime/HostManager/HostManager.cpp +++ b/lib/Runtime/HostManager/HostManager.cpp @@ -901,7 +901,7 @@ Error HostManager::runNetworkBlocking( } void HostManager::dispatchNextRun() { - llvm::Optional pRequest; + std::optional pRequest; std::shared_lock networkLock(networkLock_); { // hmm this lock is hot but I still have it as a unique lock because @@ -921,8 +921,8 @@ void HostManager::dispatchNextRun() { } } - assert(pRequest.hasValue()); - InferRequest request = std::move(pRequest.getValue()); + assert(pRequest.has_value()); + InferRequest request = std::move(pRequest.value()); auto startTime = TraceEvent::now(); auto requestReceived = request.startTime; executor_->run( diff --git a/lib/Support/TensorPool/TensorPool.cpp b/lib/Support/TensorPool/TensorPool.cpp index 36cd7cafe0..36646c11b2 100644 --- a/lib/Support/TensorPool/TensorPool.cpp +++ b/lib/Support/TensorPool/TensorPool.cpp @@ -16,9 +16,11 @@ #include "glow/Support/TensorPool.h" +#include + namespace glow { -llvm::Optional TensorPool::get(TypeRef ty) { +std::optional TensorPool::get(TypeRef ty) { stats_.totalGets++; std::unique_lock l(lock_); @@ -27,7 +29,7 @@ llvm::Optional TensorPool::get(TypeRef ty) { if (it == pools_.end()) { if (preventInlineAllocs_) { - return llvm::Optional(); + return std::nullopt; } stats_.totalTypes++; @@ -36,7 +38,7 @@ llvm::Optional TensorPool::get(TypeRef ty) { if (it->second.empty()) { if (preventInlineAllocs_) { - return llvm::Optional(); + return std::nullopt; } // Don't need to alloc under the lock. diff --git a/tests/unittests/TensorPoolTest.cpp b/tests/unittests/TensorPoolTest.cpp index 98c0f8c9da..ffd65b3604 100644 --- a/tests/unittests/TensorPoolTest.cpp +++ b/tests/unittests/TensorPoolTest.cpp @@ -31,7 +31,7 @@ TEST(TensorPool, BasicTest) { Type ty(ElemKind::FloatTy, {1, 2, 3}); pool.reserve(&ty, 1); - Tensor T = std::move(pool.get(&ty).getValue()); + Tensor T = std::move(pool.get(&ty).value()); EXPECT_TRUE(T.getType().isEqual(ty)); EXPECT_EQ(T.dims(), ty.dims()); @@ -52,12 +52,12 @@ TEST(TensorPool, ReclaimAndGet) { Type ty(ElemKind::FloatTy, {1, 2, 3}); pool.reserve(&ty, 1); - Tensor T = std::move(pool.get(&ty).getValue()); + Tensor T = std::move(pool.get(&ty).value()); auto *backingPtr = T.getUnsafePtr(); pool.reclaim(std::move(T)); - Tensor T2 = std::move(pool.get(&ty).getValue()); + Tensor T2 = std::move(pool.get(&ty).value()); // They are the same buffer. EXPECT_EQ(T2.getUnsafePtr(), backingPtr); @@ -78,8 +78,8 @@ TEST(TensorPool, Extends) { Type ty(ElemKind::FloatTy, {1, 2, 3}); pool.reserve(&ty, 1); - Tensor T = std::move(pool.get(&ty).getValue()); - Tensor T2 = std::move(pool.get(&ty).getValue()); + Tensor T = std::move(pool.get(&ty).value()); + Tensor T2 = std::move(pool.get(&ty).value()); EXPECT_TRUE(T.getType().isEqual(T2.getType())); EXPECT_TRUE(T.getType().isEqual(ty)); EXPECT_TRUE(T2.getType().isEqual(ty)); @@ -105,15 +105,15 @@ TEST(TensorPool, DoesntExtend) { Type ty(ElemKind::FloatTy, {1, 2, 3}); pool.reserve(&ty, 1); - Tensor T = std::move(pool.get(&ty).getValue()); + Tensor T = std::move(pool.get(&ty).value()); Type Tt = T.getType(); auto T2opt = pool.get(&ty); - EXPECT_FALSE(T2opt.hasValue()); + EXPECT_FALSE(T2opt.has_value()); pool.reclaim(std::move(T)); - T = std::move(pool.get(&ty).getValue()); + T = std::move(pool.get(&ty).value()); EXPECT_EQ(Tt, T.getType()); const auto &stats = pool.getStats(); @@ -132,8 +132,8 @@ TEST(TensorPool, Noreserve) { TensorPool pool; Type ty(ElemKind::FloatTy, {1, 2, 3}); - Tensor T = std::move(pool.get(&ty).getValue()); - Tensor T2 = std::move(pool.get(&ty).getValue()); + Tensor T = std::move(pool.get(&ty).value()); + Tensor T2 = std::move(pool.get(&ty).value()); EXPECT_TRUE(T.getType().isEqual(T2.getType())); @@ -162,8 +162,8 @@ TEST(TensorPool, MultipleTypes) { std::vector tensors; // Ten total allocs. for (int i = 0; i < 5; ++i) { - Tensor T = std::move(pool.get(&ty).getValue()); - Tensor T2 = std::move(pool.get(&ty2).getValue()); + Tensor T = std::move(pool.get(&ty).value()); + Tensor T2 = std::move(pool.get(&ty2).value()); EXPECT_FALSE(T.getType().isEqual(T2.getType())); EXPECT_TRUE(T.getType().isEqual(ty)); EXPECT_TRUE(T2.getType().isEqual(ty2)); @@ -200,14 +200,14 @@ TEST(TensorPool, MultipleTypesReclaim) { pool.reserve(&ty, 1); pool.reserve(&ty2, 1); - Tensor T = std::move(pool.get(&ty).getValue()); - Tensor T2 = std::move(pool.get(&ty2).getValue()); + Tensor T = std::move(pool.get(&ty).value()); + Tensor T2 = std::move(pool.get(&ty2).value()); pool.reclaim(std::move(T)); pool.reclaim(std::move(T2)); - T = std::move(pool.get(&ty).getValue()); - T2 = std::move(pool.get(&ty2).getValue()); + T = std::move(pool.get(&ty).value()); + T2 = std::move(pool.get(&ty2).value()); pool.reclaim(std::move(T)); pool.reclaim(std::move(T2)); @@ -231,7 +231,7 @@ TEST(TensorPool, PlaceholderBindingsReclaim) { Module mod; auto *PH = mod.createPlaceholder(&ty, "test", false); - bindings.insert(PH, std::move(pool.get(&ty).getValue())); + bindings.insert(PH, std::move(pool.get(&ty).value())); /// Insert a non managed tensor. auto *PH2 = mod.createPlaceholder(&ty, "test2", false); @@ -249,7 +249,7 @@ TEST(TensorPool, PlaceholderBindingsReclaim) { EXPECT_EQ(stats.totalGets, 1); EXPECT_EQ(stats.totalReclaims, 1); - bindings.insert(PH, std::move(pool.get(&ty).getValue())); + bindings.insert(PH, std::move(pool.get(&ty).value())); bindings.erase(PH); const auto &stats2 = pool.getStats(); @@ -263,7 +263,7 @@ TEST(TensorPool, Clear) { TensorPool pool; Type ty(ElemKind::FloatTy, {1, 2, 3}); - Tensor T = std::move(pool.get(&ty).getValue()); + Tensor T = std::move(pool.get(&ty).value()); pool.reclaim(std::move(T)); const auto &stats = pool.getStats(); @@ -277,7 +277,7 @@ TEST(TensorPool, Clear) { pool.clear(); - T = std::move(pool.get(&ty).getValue()); + T = std::move(pool.get(&ty).value()); pool.reclaim(std::move(T)); const auto &stats2 = pool.getStats(); diff --git a/torch_glow/src/CachingGraphRunner.cpp b/torch_glow/src/CachingGraphRunner.cpp index 1c07876e48..57737801e0 100644 --- a/torch_glow/src/CachingGraphRunner.cpp +++ b/torch_glow/src/CachingGraphRunner.cpp @@ -913,13 +913,13 @@ CachingGraphRunner::convertPyTorchInputToGlowInput( // For backends that does not support partial tensor, last-element padding // based on size auto inputTensorOpt = tensorPool_.get(ty); - if (!inputTensorOpt.hasValue()) { + if (!inputTensorOpt) { std::stringstream ss; ss << "Tensorpool tensor not found for input " << ptTensor.name(); return MAKE_ERR(ss.str()); } // We want fresh DeviceResidencyInfo for this fresh Tensor. - glow::Tensor inputTensor(std::move(inputTensorOpt.getValue())); + glow::Tensor inputTensor(std::move(inputTensorOpt.value())); inputTensor.resetDeviceInfo(); if (ptTensor.data_ptr()) { auto *inTensorPtr = inputTensor.getUnsafePtr();