diff --git a/benchs/bench_hamming_computer.cpp b/benchs/bench_hamming_computer.cpp index 0dafeb24b8..36da7a1025 100644 --- a/benchs/bench_hamming_computer.cpp +++ b/benchs/bench_hamming_computer.cpp @@ -9,7 +9,7 @@ #include #include -#include +#include #include #include @@ -24,7 +24,7 @@ struct HammingComputerM8 { const uint64_t* a; int n; - HammingComputerM8() {} + HammingComputerM8() = default; HammingComputerM8(const uint8_t* a8, int code_size) { set(a8, code_size); @@ -53,7 +53,7 @@ struct HammingComputerM4 { const uint32_t* a; int n; - HammingComputerM4() {} + HammingComputerM4() = default; HammingComputerM4(const uint8_t* a4, int code_size) { set(a4, code_size); diff --git a/demos/demo_ivfpq_indexing.cpp b/demos/demo_ivfpq_indexing.cpp index fa8687aadc..9773cac29e 100644 --- a/demos/demo_ivfpq_indexing.cpp +++ b/demos/demo_ivfpq_indexing.cpp @@ -18,7 +18,7 @@ double elapsed() { struct timeval tv; - gettimeofday(&tv, NULL); + gettimeofday(&tv, nullptr); return tv.tv_sec + tv.tv_usec * 1e-6; } diff --git a/demos/demo_weighted_kmeans.cpp b/demos/demo_weighted_kmeans.cpp index f6f89fae05..245029131f 100644 --- a/demos/demo_weighted_kmeans.cpp +++ b/demos/demo_weighted_kmeans.cpp @@ -7,6 +7,7 @@ #include #include +#include #include #include @@ -39,13 +40,13 @@ float weighted_kmeans_clustering( switch (index_num) { case WKMT_FlatL2: - index.reset(new IndexFlatL2(d)); + index = std::make_unique(d); break; case WKMT_FlatIP: - index.reset(new IndexFlatIP(d)); + index = std::make_unique(d); break; case WKMT_FlatIP_spherical: - index.reset(new IndexFlatIP(d)); + index = std::make_unique(d); clus.spherical = true; break; case WKMT_HNSW: diff --git a/faiss/AutoTune.cpp b/faiss/AutoTune.cpp index ba8e4ba5d6..7c663a1dd4 100644 --- a/faiss/AutoTune.cpp +++ b/faiss/AutoTune.cpp @@ -334,7 +334,7 @@ ParameterRange& ParameterSpace::add_range(const std::string& name) { return pr; } } - parameter_ranges.push_back(ParameterRange()); + parameter_ranges.emplace_back(); parameter_ranges.back().name = name; return parameter_ranges.back(); } diff --git a/faiss/Clustering.cpp b/faiss/Clustering.cpp index 3594a01c2b..0530b655fe 100644 --- a/faiss/Clustering.cpp +++ b/faiss/Clustering.cpp @@ -217,7 +217,7 @@ int split_clusters( for (size_t ci = 0; ci < k; ci++) { if (hassign[ci] == 0) { /* need to redefine a centroid */ size_t cj; - for (cj = 0; 1; cj = (cj + 1) % k) { + for (cj = 0; true; cj = (cj + 1) % k) { /* probability to pick this cluster for split */ float p = (hassign[cj] - 1.0) / (float)(n - k); float r = rng.rand_float(); diff --git a/faiss/Index.cpp b/faiss/Index.cpp index 204fc6dead..ce5aa956c1 100644 --- a/faiss/Index.cpp +++ b/faiss/Index.cpp @@ -18,7 +18,7 @@ namespace faiss { -Index::~Index() {} +Index::~Index() = default; void Index::train(idx_t /*n*/, const float* /*x*/) { // does nothing by default diff --git a/faiss/Index2Layer.cpp b/faiss/Index2Layer.cpp index 39291debbf..537fdca23f 100644 --- a/faiss/Index2Layer.cpp +++ b/faiss/Index2Layer.cpp @@ -10,10 +10,10 @@ #include #include -#include #include #include #include +#include #include #ifdef __SSE3__ @@ -60,7 +60,7 @@ Index2Layer::Index2Layer() { code_size = code_size_1 = code_size_2 = 0; } -Index2Layer::~Index2Layer() {} +Index2Layer::~Index2Layer() = default; void Index2Layer::train(idx_t n, const float* x) { if (verbose) { diff --git a/faiss/IndexAdditiveQuantizer.cpp b/faiss/IndexAdditiveQuantizer.cpp index ffd4c524f6..51b7979a20 100644 --- a/faiss/IndexAdditiveQuantizer.cpp +++ b/faiss/IndexAdditiveQuantizer.cpp @@ -70,7 +70,7 @@ struct AQDistanceComputerDecompress : FlatCodesDistanceComputer { return vd(q, tmp.data()); } - virtual ~AQDistanceComputerDecompress() {} + virtual ~AQDistanceComputerDecompress() = default; }; template @@ -107,7 +107,7 @@ struct AQDistanceComputerLUT : FlatCodesDistanceComputer { return bias + aq.compute_1_distance_LUT(code, LUT.data()); } - virtual ~AQDistanceComputerLUT() {} + virtual ~AQDistanceComputerLUT() = default; }; /************************************************************ diff --git a/faiss/IndexAdditiveQuantizerFastScan.cpp b/faiss/IndexAdditiveQuantizerFastScan.cpp index d549e094ce..709ccc87e2 100644 --- a/faiss/IndexAdditiveQuantizerFastScan.cpp +++ b/faiss/IndexAdditiveQuantizerFastScan.cpp @@ -7,8 +7,8 @@ #include -#include #include +#include #include #include @@ -83,7 +83,7 @@ IndexAdditiveQuantizerFastScan::IndexAdditiveQuantizerFastScan( pq4_pack_codes(orig_codes, ntotal, M, ntotal2, bbs, M2, codes.get()); } -IndexAdditiveQuantizerFastScan::~IndexAdditiveQuantizerFastScan() {} +IndexAdditiveQuantizerFastScan::~IndexAdditiveQuantizerFastScan() = default; void IndexAdditiveQuantizerFastScan::train(idx_t n, const float* x_in) { if (is_trained) { diff --git a/faiss/IndexBinary.cpp b/faiss/IndexBinary.cpp index 22d8bc5e1b..2bc7c56cc1 100644 --- a/faiss/IndexBinary.cpp +++ b/faiss/IndexBinary.cpp @@ -20,7 +20,7 @@ IndexBinary::IndexBinary(idx_t d, MetricType metric) FAISS_THROW_IF_NOT(d % 8 == 0); } -IndexBinary::~IndexBinary() {} +IndexBinary::~IndexBinary() = default; void IndexBinary::train(idx_t, const uint8_t*) { // Does nothing by default. diff --git a/faiss/IndexBinaryFromFloat.cpp b/faiss/IndexBinaryFromFloat.cpp index e396231f4c..407c919958 100644 --- a/faiss/IndexBinaryFromFloat.cpp +++ b/faiss/IndexBinaryFromFloat.cpp @@ -16,7 +16,7 @@ namespace faiss { -IndexBinaryFromFloat::IndexBinaryFromFloat() {} +IndexBinaryFromFloat::IndexBinaryFromFloat() = default; IndexBinaryFromFloat::IndexBinaryFromFloat(Index* index) : IndexBinary(index->d), index(index), own_fields(false) { diff --git a/faiss/IndexBinaryHNSW.cpp b/faiss/IndexBinaryHNSW.cpp index 9481fe67f2..e6fda8e4bf 100644 --- a/faiss/IndexBinaryHNSW.cpp +++ b/faiss/IndexBinaryHNSW.cpp @@ -20,9 +20,9 @@ #include #include -#include #include #include +#include #include #include diff --git a/faiss/IndexBinaryIVF.cpp b/faiss/IndexBinaryIVF.cpp index 0e886b47e2..f49127f6b2 100644 --- a/faiss/IndexBinaryIVF.cpp +++ b/faiss/IndexBinaryIVF.cpp @@ -36,7 +36,7 @@ IndexBinaryIVF::IndexBinaryIVF(IndexBinary* quantizer, size_t d, size_t nlist) cp.niter = 10; } -IndexBinaryIVF::IndexBinaryIVF() {} +IndexBinaryIVF::IndexBinaryIVF() = default; void IndexBinaryIVF::add(idx_t n, const uint8_t* x) { add_with_ids(n, x, nullptr); @@ -436,8 +436,8 @@ void search_knn_hamming_heap( const idx_t* ids = nullptr; if (!store_pairs) { - sids.reset( - new InvertedLists::ScopedIds(ivf->invlists, key)); + sids = std::make_unique( + ivf->invlists, key); ids = sids->get(); } diff --git a/faiss/IndexFastScan.cpp b/faiss/IndexFastScan.cpp index 4ed71aaee1..02840767d1 100644 --- a/faiss/IndexFastScan.cpp +++ b/faiss/IndexFastScan.cpp @@ -7,8 +7,8 @@ #include -#include #include +#include #include #include diff --git a/faiss/IndexHNSW.cpp b/faiss/IndexHNSW.cpp index c9b62a390a..f846223479 100644 --- a/faiss/IndexHNSW.cpp +++ b/faiss/IndexHNSW.cpp @@ -20,9 +20,9 @@ #include #include -#include #include #include +#include #include #include @@ -876,7 +876,7 @@ IndexHNSWFlat::IndexHNSWFlat(int d, int M, MetricType metric) * IndexHNSWPQ implementation **************************************************************/ -IndexHNSWPQ::IndexHNSWPQ() {} +IndexHNSWPQ::IndexHNSWPQ() = default; IndexHNSWPQ::IndexHNSWPQ(int d, int pq_m, int M, int pq_nbits) : IndexHNSW(new IndexPQ(d, pq_m, pq_nbits), M) { @@ -903,7 +903,7 @@ IndexHNSWSQ::IndexHNSWSQ( own_fields = true; } -IndexHNSWSQ::IndexHNSWSQ() {} +IndexHNSWSQ::IndexHNSWSQ() = default; /************************************************************** * IndexHNSW2Level implementation @@ -919,7 +919,7 @@ IndexHNSW2Level::IndexHNSW2Level( is_trained = false; } -IndexHNSW2Level::IndexHNSW2Level() {} +IndexHNSW2Level::IndexHNSW2Level() = default; namespace { diff --git a/faiss/IndexIDMap.cpp b/faiss/IndexIDMap.cpp index fdd7fcd734..7972bec9a0 100644 --- a/faiss/IndexIDMap.cpp +++ b/faiss/IndexIDMap.cpp @@ -9,8 +9,8 @@ #include -#include #include +#include #include #include diff --git a/faiss/IndexIVF.cpp b/faiss/IndexIVF.cpp index aeaca78011..6139ece448 100644 --- a/faiss/IndexIVF.cpp +++ b/faiss/IndexIVF.cpp @@ -11,6 +11,7 @@ #include #include +#include #include #include @@ -45,7 +46,7 @@ Level1Quantizer::Level1Quantizer(Index* quantizer, size_t nlist) cp.niter = 10; } -Level1Quantizer::Level1Quantizer() {} +Level1Quantizer::Level1Quantizer() = default; Level1Quantizer::~Level1Quantizer() { if (own_fields) { @@ -172,7 +173,7 @@ IndexIVF::IndexIVF( } } -IndexIVF::IndexIVF() {} +IndexIVF::IndexIVF() = default; void IndexIVF::add(idx_t n, const float* x) { add_with_ids(n, x, nullptr); @@ -539,7 +540,8 @@ void IndexIVF::search_preassigned( const idx_t* ids = nullptr; if (!store_pairs) { - sids.reset(new InvertedLists::ScopedIds(invlists, key)); + sids = std::make_unique( + invlists, key); ids = sids->get(); } diff --git a/faiss/IndexIVFAdditiveQuantizer.cpp b/faiss/IndexIVFAdditiveQuantizer.cpp index 54779792b8..75b8517a0a 100644 --- a/faiss/IndexIVFAdditiveQuantizer.cpp +++ b/faiss/IndexIVFAdditiveQuantizer.cpp @@ -116,7 +116,7 @@ void IndexIVFAdditiveQuantizer::sa_decode( } } -IndexIVFAdditiveQuantizer::~IndexIVFAdditiveQuantizer() {} +IndexIVFAdditiveQuantizer::~IndexIVFAdditiveQuantizer() = default; /********************************************* * AQInvertedListScanner @@ -157,7 +157,7 @@ struct AQInvertedListScanner : InvertedListScanner { } } - ~AQInvertedListScanner() {} + ~AQInvertedListScanner() = default; }; template @@ -188,7 +188,7 @@ struct AQInvertedListScannerDecompress : AQInvertedListScanner { : fvec_L2sqr(q, b.data(), aq.d); } - ~AQInvertedListScannerDecompress() override {} + ~AQInvertedListScannerDecompress() override = default; }; template @@ -231,7 +231,7 @@ struct AQInvertedListScannerLUT : AQInvertedListScanner { aq.compute_1_distance_LUT(code, LUT.data()); } - ~AQInvertedListScannerLUT() override {} + ~AQInvertedListScannerLUT() override = default; }; } // anonymous namespace @@ -310,7 +310,7 @@ IndexIVFResidualQuantizer::IndexIVFResidualQuantizer( metric, search_type) {} -IndexIVFResidualQuantizer::~IndexIVFResidualQuantizer() {} +IndexIVFResidualQuantizer::~IndexIVFResidualQuantizer() = default; /************************************************************************************** * IndexIVFLocalSearchQuantizer @@ -332,7 +332,7 @@ IndexIVFLocalSearchQuantizer::IndexIVFLocalSearchQuantizer( IndexIVFLocalSearchQuantizer::IndexIVFLocalSearchQuantizer() : IndexIVFAdditiveQuantizer(&lsq) {} -IndexIVFLocalSearchQuantizer::~IndexIVFLocalSearchQuantizer() {} +IndexIVFLocalSearchQuantizer::~IndexIVFLocalSearchQuantizer() = default; /************************************************************************************** * IndexIVFProductResidualQuantizer @@ -355,7 +355,7 @@ IndexIVFProductResidualQuantizer::IndexIVFProductResidualQuantizer( IndexIVFProductResidualQuantizer::IndexIVFProductResidualQuantizer() : IndexIVFAdditiveQuantizer(&prq) {} -IndexIVFProductResidualQuantizer::~IndexIVFProductResidualQuantizer() {} +IndexIVFProductResidualQuantizer::~IndexIVFProductResidualQuantizer() = default; /************************************************************************************** * IndexIVFProductLocalSearchQuantizer @@ -378,6 +378,7 @@ IndexIVFProductLocalSearchQuantizer::IndexIVFProductLocalSearchQuantizer( IndexIVFProductLocalSearchQuantizer::IndexIVFProductLocalSearchQuantizer() : IndexIVFAdditiveQuantizer(&plsq) {} -IndexIVFProductLocalSearchQuantizer::~IndexIVFProductLocalSearchQuantizer() {} +IndexIVFProductLocalSearchQuantizer::~IndexIVFProductLocalSearchQuantizer() = + default; } // namespace faiss diff --git a/faiss/IndexIVFAdditiveQuantizerFastScan.cpp b/faiss/IndexIVFAdditiveQuantizerFastScan.cpp index 2f41f87bcc..22f7f2e2df 100644 --- a/faiss/IndexIVFAdditiveQuantizerFastScan.cpp +++ b/faiss/IndexIVFAdditiveQuantizerFastScan.cpp @@ -125,7 +125,8 @@ IndexIVFAdditiveQuantizerFastScan::IndexIVFAdditiveQuantizerFastScan() { is_trained = false; } -IndexIVFAdditiveQuantizerFastScan::~IndexIVFAdditiveQuantizerFastScan() {} +IndexIVFAdditiveQuantizerFastScan::~IndexIVFAdditiveQuantizerFastScan() = + default; /********************************************************* * Training diff --git a/faiss/IndexIVFFastScan.cpp b/faiss/IndexIVFFastScan.cpp index 800172cc9e..46d7a2d57c 100644 --- a/faiss/IndexIVFFastScan.cpp +++ b/faiss/IndexIVFFastScan.cpp @@ -82,7 +82,7 @@ void IndexIVFFastScan::init_code_packer() { bil->packer = get_CodePacker(); } -IndexIVFFastScan::~IndexIVFFastScan() {} +IndexIVFFastScan::~IndexIVFFastScan() = default; /********************************************************* * Code management functions diff --git a/faiss/IndexIVFPQ.cpp b/faiss/IndexIVFPQ.cpp index 058798b15c..85a3671e26 100644 --- a/faiss/IndexIVFPQ.cpp +++ b/faiss/IndexIVFPQ.cpp @@ -9,10 +9,10 @@ #include -#include #include #include #include +#include #include #include diff --git a/faiss/IndexIVFSpectralHash.cpp b/faiss/IndexIVFSpectralHash.cpp index d9a51fbe64..dace151270 100644 --- a/faiss/IndexIVFSpectralHash.cpp +++ b/faiss/IndexIVFSpectralHash.cpp @@ -9,8 +9,8 @@ #include -#include #include +#include #include #include diff --git a/faiss/IndexLSH.cpp b/faiss/IndexLSH.cpp index 426b437a20..3399a8f2d8 100644 --- a/faiss/IndexLSH.cpp +++ b/faiss/IndexLSH.cpp @@ -56,7 +56,7 @@ const float* IndexLSH::apply_preprocess(idx_t n, const float* x) const { } if (train_thresholds) { - if (xt == NULL) { + if (xt == nullptr) { xt = new float[nbits * n]; memcpy(xt, x, sizeof(*x) * n * nbits); } diff --git a/faiss/IndexNSG.cpp b/faiss/IndexNSG.cpp index 654b788186..23710c4f59 100644 --- a/faiss/IndexNSG.cpp +++ b/faiss/IndexNSG.cpp @@ -286,7 +286,7 @@ IndexNSGFlat::IndexNSGFlat(int d, int R, MetricType metric) * IndexNSGPQ implementation **************************************************************/ -IndexNSGPQ::IndexNSGPQ() {} +IndexNSGPQ::IndexNSGPQ() = default; IndexNSGPQ::IndexNSGPQ(int d, int pq_m, int M, int pq_nbits) : IndexNSG(new IndexPQ(d, pq_m, pq_nbits), M) { @@ -313,6 +313,6 @@ IndexNSGSQ::IndexNSGSQ( own_fields = true; } -IndexNSGSQ::IndexNSGSQ() {} +IndexNSGSQ::IndexNSGSQ() = default; } // namespace faiss diff --git a/faiss/IndexPQ.cpp b/faiss/IndexPQ.cpp index 2986745fbc..eae77373e2 100644 --- a/faiss/IndexPQ.cpp +++ b/faiss/IndexPQ.cpp @@ -630,7 +630,7 @@ struct SemiSortedArray { int N; // type of the heap: CMax = sort ascending - typedef CMax HC; + using HC = CMax; std::vector perm; int k; // k elements are sorted @@ -724,7 +724,7 @@ struct MinSumK { * We use a heap to maintain a queue of sums, with the associated * terms involved in the sum. */ - typedef CMin HC; + using HC = CMin; size_t heap_capacity, heap_size; T* bh_val; int64_t* bh_ids; diff --git a/faiss/IndexPQFastScan.cpp b/faiss/IndexPQFastScan.cpp index ba15e87429..b8a6cdbeeb 100644 --- a/faiss/IndexPQFastScan.cpp +++ b/faiss/IndexPQFastScan.cpp @@ -7,8 +7,8 @@ #include -#include #include +#include #include #include diff --git a/faiss/IndexRefine.cpp b/faiss/IndexRefine.cpp index ccb6b61ca6..9bb63ba029 100644 --- a/faiss/IndexRefine.cpp +++ b/faiss/IndexRefine.cpp @@ -62,7 +62,7 @@ void IndexRefine::reset() { namespace { -typedef faiss::idx_t idx_t; +using idx_t = faiss::idx_t; template static void reorder_2_heaps( diff --git a/faiss/MatrixStats.cpp b/faiss/MatrixStats.cpp index 3eea7bf91f..cc87e1797c 100644 --- a/faiss/MatrixStats.cpp +++ b/faiss/MatrixStats.cpp @@ -9,7 +9,7 @@ #include -#include /* va_list, va_start, va_arg, va_end */ +#include /* va_list, va_start, va_arg, va_end */ #include #include diff --git a/faiss/MetaIndexes.cpp b/faiss/MetaIndexes.cpp index 50c7c88cb8..d3dd5b0fc6 100644 --- a/faiss/MetaIndexes.cpp +++ b/faiss/MetaIndexes.cpp @@ -9,8 +9,8 @@ #include -#include #include +#include #include #include @@ -238,6 +238,6 @@ void IndexRandom::reset() { ntotal = 0; } -IndexRandom::~IndexRandom() {} +IndexRandom::~IndexRandom() = default; } // namespace faiss diff --git a/faiss/gpu/GpuCloner.cpp b/faiss/gpu/GpuCloner.cpp index 483cc562b8..4dc51f9e83 100644 --- a/faiss/gpu/GpuCloner.cpp +++ b/faiss/gpu/GpuCloner.cpp @@ -7,6 +7,7 @@ #include #include +#include #include #include @@ -240,7 +241,7 @@ ToGpuClonerMultiple::ToGpuClonerMultiple( : GpuMultipleClonerOptions(options) { FAISS_THROW_IF_NOT(provider.size() == devices.size()); for (size_t i = 0; i < provider.size(); i++) { - sub_cloners.push_back(ToGpuCloner(provider[i], devices[i], options)); + sub_cloners.emplace_back(provider[i], devices[i], options); } } @@ -309,8 +310,8 @@ Index* ToGpuClonerMultiple::clone_Index_to_shards(const Index* index) { !dynamic_cast(quantizer)) { // then we flatten the coarse quantizer so that everything remains // on GPU - new_quantizer.reset( - new IndexFlat(quantizer->d, quantizer->metric_type)); + new_quantizer = std::make_unique( + quantizer->d, quantizer->metric_type); std::vector centroids(quantizer->d * quantizer->ntotal); quantizer->reconstruct_n(0, quantizer->ntotal, centroids.data()); new_quantizer->add(quantizer->ntotal, centroids.data()); diff --git a/faiss/gpu/GpuResources.cpp b/faiss/gpu/GpuResources.cpp index e745263dec..1ed3a6ddd5 100644 --- a/faiss/gpu/GpuResources.cpp +++ b/faiss/gpu/GpuResources.cpp @@ -158,7 +158,7 @@ GpuMemoryReservation::~GpuMemoryReservation() { // GpuResources // -GpuResources::~GpuResources() {} +GpuResources::~GpuResources() = default; cublasHandle_t GpuResources::getBlasHandleCurrentDevice() { return getBlasHandle(getCurrentDevice()); @@ -203,7 +203,7 @@ size_t GpuResources::getTempMemoryAvailableCurrentDevice() const { // GpuResourcesProvider // -GpuResourcesProvider::~GpuResourcesProvider() {} +GpuResourcesProvider::~GpuResourcesProvider() = default; // // GpuResourcesProviderFromResourceInstance @@ -213,7 +213,7 @@ GpuResourcesProviderFromInstance::GpuResourcesProviderFromInstance( std::shared_ptr p) : res_(p) {} -GpuResourcesProviderFromInstance::~GpuResourcesProviderFromInstance() {} +GpuResourcesProviderFromInstance::~GpuResourcesProviderFromInstance() = default; std::shared_ptr GpuResourcesProviderFromInstance::getResources() { return res_; diff --git a/faiss/gpu/StandardGpuResources.cpp b/faiss/gpu/StandardGpuResources.cpp index 2d4c675d64..418912aa4a 100644 --- a/faiss/gpu/StandardGpuResources.cpp +++ b/faiss/gpu/StandardGpuResources.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #endif @@ -221,11 +222,11 @@ void StandardGpuResourcesImpl::setTempMemory(size_t size) { p.second.reset(); // Allocate new - p.second = std::unique_ptr(new StackDeviceMemory( + p.second = std::make_unique( this, p.first, // adjust for this specific device - getDefaultTempMemForGPU(device, tempMemSize_))); + getDefaultTempMemForGPU(device, tempMemSize_)); } } } @@ -355,13 +356,13 @@ void StandardGpuResourcesImpl::initializeForDevice(int device) { device); // Create streams - cudaStream_t defaultStream = 0; + cudaStream_t defaultStream = nullptr; CUDA_VERIFY( cudaStreamCreateWithFlags(&defaultStream, cudaStreamNonBlocking)); defaultStreams_[device] = defaultStream; - cudaStream_t asyncCopyStream = 0; + cudaStream_t asyncCopyStream = nullptr; CUDA_VERIFY( cudaStreamCreateWithFlags(&asyncCopyStream, cudaStreamNonBlocking)); @@ -369,7 +370,7 @@ void StandardGpuResourcesImpl::initializeForDevice(int device) { std::vector deviceStreams; for (int j = 0; j < kNumStreams; ++j) { - cudaStream_t stream = 0; + cudaStream_t stream = nullptr; CUDA_VERIFY(cudaStreamCreateWithFlags(&stream, cudaStreamNonBlocking)); deviceStreams.push_back(stream); @@ -378,7 +379,7 @@ void StandardGpuResourcesImpl::initializeForDevice(int device) { alternateStreams_[device] = std::move(deviceStreams); // Create cuBLAS handle - cublasHandle_t blasHandle = 0; + cublasHandle_t blasHandle = nullptr; auto blasStatus = cublasCreate(&blasHandle); FAISS_ASSERT(blasStatus == CUBLAS_STATUS_SUCCESS); blasHandles_[device] = blasHandle; @@ -396,11 +397,11 @@ void StandardGpuResourcesImpl::initializeForDevice(int device) { allocs_[device] = std::unordered_map(); FAISS_ASSERT(tempMemory_.count(device) == 0); - auto mem = std::unique_ptr(new StackDeviceMemory( + auto mem = std::make_unique( this, device, // adjust for this specific device - getDefaultTempMemForGPU(device, tempMemSize_))); + getDefaultTempMemForGPU(device, tempMemSize_)); tempMemory_.emplace(device, std::move(mem)); } @@ -431,7 +432,7 @@ raft::device_resources& StandardGpuResourcesImpl::getRaftHandle(int device) { if (it == raftHandles_.end()) { // Make sure we are using the stream the user may have already assigned // to the current GpuResources - raftHandles_.emplace(std::make_pair(device, getDefaultStream(device))); + raftHandles_.emplace(device, getDefaultStream(device)); // Initialize cublas handle raftHandles_[device].get_cublas_handle(); @@ -651,7 +652,7 @@ StandardGpuResourcesImpl::getMemoryInfo() const { StandardGpuResources::StandardGpuResources() : res_(new StandardGpuResourcesImpl) {} -StandardGpuResources::~StandardGpuResources() {} +StandardGpuResources::~StandardGpuResources() = default; std::shared_ptr StandardGpuResources::getResources() { return res_;