Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 93 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
{
"files.associations": {
"cctype": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"csetjmp": "cpp",
"csignal": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"any": "cpp",
"array": "cpp",
"atomic": "cpp",
"strstream": "cpp",
"barrier": "cpp",
"bit": "cpp",
"bitset": "cpp",
"cfenv": "cpp",
"charconv": "cpp",
"chrono": "cpp",
"cinttypes": "cpp",
"codecvt": "cpp",
"compare": "cpp",
"complex": "cpp",
"concepts": "cpp",
"condition_variable": "cpp",
"coroutine": "cpp",
"cstdint": "cpp",
"cuchar": "cpp",
"deque": "cpp",
"forward_list": "cpp",
"list": "cpp",
"map": "cpp",
"set": "cpp",
"string": "cpp",
"unordered_map": "cpp",
"unordered_set": "cpp",
"vector": "cpp",
"exception": "cpp",
"algorithm": "cpp",
"functional": "cpp",
"iterator": "cpp",
"memory": "cpp",
"memory_resource": "cpp",
"numeric": "cpp",
"optional": "cpp",
"random": "cpp",
"ratio": "cpp",
"regex": "cpp",
"source_location": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"utility": "cpp",
"fstream": "cpp",
"future": "cpp",
"initializer_list": "cpp",
"iomanip": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"istream": "cpp",
"latch": "cpp",
"limits": "cpp",
"mutex": "cpp",
"new": "cpp",
"numbers": "cpp",
"ostream": "cpp",
"ranges": "cpp",
"scoped_allocator": "cpp",
"semaphore": "cpp",
"shared_mutex": "cpp",
"span": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"stop_token": "cpp",
"streambuf": "cpp",
"syncstream": "cpp",
"thread": "cpp",
"typeindex": "cpp",
"typeinfo": "cpp",
"valarray": "cpp",
"variant": "cpp",
"expected": "cpp",
"spanstream": "cpp",
"stacktrace": "cpp"
}
}
41 changes: 25 additions & 16 deletions Test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,38 @@
# Licensed under the MIT License.

if (NOT LIBRARYONLY)
if(NOT WIN32)
ADD_DEFINITIONS(-DBOOST_TEST_DYN_LINK)
message (STATUS "BOOST_TEST_DYN_LINK")
endif()
find_package(Boost 1.66 COMPONENTS system thread serialization wserialization regex filesystem)
if (Boost_FOUND)
include_directories (${Boost_INCLUDE_DIR})
link_directories (${Boost_LIBRARY_DIR})
message (STATUS "Found Boost.")
message (STATUS "Include Path: ${Boost_INCLUDE_DIRS}")
message (STATUS "Library Path: ${Boost_LIBRARY_DIRS}")
message (STATUS "Library: ${Boost_LIBRARIES}")
else()
message (FATAL_ERROR "Could not find Boost 1.67!")
endif()

find_package(Boost 1.66 COMPONENTS system thread serialization wserialization regex filesystem unit_test_framework)
if (Boost_FOUND)
include_directories (${Boost_INCLUDE_DIR})
link_directories (${Boost_LIBRARY_DIR})
message (STATUS "Found Boost.")
message (STATUS "Include Path: ${Boost_INCLUDE_DIRS}")
message (STATUS "Library Path: ${Boost_LIBRARY_DIRS}")
message (STATUS "Library: ${Boost_LIBRARIES}")
else()
message (FATAL_ERROR "Could not find Boost 1.67!")
endif()
# GoogleTest
include(FetchContent)
find_package(GTest QUIET)
if (NOT GTest_FOUND)
message(STATUS "GTest not found; fetching googletest via FetchContent...")
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/refs/tags/v1.14.0.zip
)
# For Windows: prevent overriding the parent project's compiler/linker settings
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)
endif()

include_directories(${PROJECT_SOURCE_DIR}/AnnService ${PROJECT_SOURCE_DIR}/Test ${PROJECT_SOURCE_DIR}/ThirdParty/spdk/build/include)

file(GLOB TEST_HDR_FILES ${PROJECT_SOURCE_DIR}/Test/inc/Test.h)
file(GLOB TEST_SRC_FILES ${PROJECT_SOURCE_DIR}/Test/src/*.cpp)
add_executable(SPTAGTest ${TEST_SRC_FILES} ${TEST_HDR_FILES})
target_link_libraries(SPTAGTest SPTAGLibStatic ssdservingLib ${Boost_LIBRARIES})
target_link_libraries(SPTAGTest PRIVATE SPTAGLibStatic ssdservingLib ${Boost_LIBRARIES} GTest::gtest GTest::gtest_main)

install(TARGETS SPTAGTest
RUNTIME DESTINATION bin
Expand Down
30 changes: 14 additions & 16 deletions Test/cuda/cuda_tests.cpp
Original file line number Diff line number Diff line change
@@ -1,44 +1,42 @@
//#include "test_kernels.cu"

#define BOOST_TEST_MODULE GPU
// #include "test_kernels.cu"

#include <chrono>
#include <cstdlib>

#include "inc/Test.h"
#include <boost/filesystem.hpp>
#include <boost/test/included/unit_test.hpp>
#include <iostream>

int GPUBuildKNNTest();

BOOST_AUTO_TEST_CASE(RandomTests)
TEST(GPUTest, RandomTests)
{
BOOST_CHECK(1 == 1);
EXPECT_EQ(1, 1);

int errors = GPUBuildKNNTest();
printf("outside\n");
BOOST_CHECK(errors == 0);
EXPECT_EQ(errors, 0);
}

/*
int GPUTestDistance_All();

BOOST_AUTO_TEST_CASE(DistanceTests) {
// TEST(GPUTest, DistanceTests) {
int errs = GPUTestDistance_All();
BOOST_CHECK(errs == 0);
}
EXPECT_EQ(errs, 0);
// }

int GPUBuildTPTTest();

BOOST_AUTO_TEST_CASE(TPTreeTests) {
// TEST(GPUTest, TPTreeTests) {
int errs = GPUBuildTPTTest();
BOOST_CHECK(errs == 0);
}
EXPECT_EQ(errs, 0);
// }

int GPUBuildSSDTest_All();

BOOST_AUTO_TEST_CASE(BuildSSDTests) {
// TEST(GPUTest, BuildSSDTests) {
int errs = GPUBuildSSDTest_All();
BOOST_CHECK(errs == 0);
}
EXPECT_EQ(errs, 0);
// }
*/
31 changes: 15 additions & 16 deletions Test/cuda/pq_perf.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

//#include "../inc/Test.h"

#define BOOST_TEST_MODULE GPU
// #include "../inc/Test.h"

#include "inc/Test.h"
#include <boost/filesystem.hpp>
#include <boost/test/included/unit_test.hpp>
#include <iostream>
#include <limits>

Expand Down Expand Up @@ -82,8 +80,8 @@ std::shared_ptr<MetadataSet>& meta, std::shared_ptr<VectorSet>& queryset, int k,
std::string out, std::shared_ptr<COMMON::IQuantizer> quantizer)
{
std::shared_ptr<VectorIndex> vecIndex = SPTAG::VectorIndex::CreateInstance(algo, SPTAG::GetEnumValueType<T>());
vecIndex->SetQuantizer(quantizer);
BOOST_CHECK(nullptr != vecIndex);
vecIndex->SetQuantizer(quantizer);
ASSERT_NE(nullptr, vecIndex);

if (algo == IndexAlgoType::KDT) vecIndex->SetParameter("KDTNumber", "2");
vecIndex->SetParameter("DistCalcMethod", distCalcMethod);
Expand All @@ -92,8 +90,8 @@ std::string out, std::shared_ptr<COMMON::IQuantizer> quantizer)
vecIndex->SetParameter("MaxCheck", "4096");
vecIndex->SetParameter("MaxCheckForRefineGraph", "8192");

BOOST_CHECK(SPTAG::ErrorCode::Success == vecIndex->BuildIndex(vec, meta, true));
BOOST_CHECK(SPTAG::ErrorCode::Success == vecIndex->SaveIndex(out));
ASSERT_EQ(SPTAG::ErrorCode::Success, vecIndex->BuildIndex(vec, meta, true));
ASSERT_EQ(SPTAG::ErrorCode::Success, vecIndex->SaveIndex(out));
//Search<T>(vecIndex, queryset, k, truth);
return vecIndex;
}
Expand Down Expand Up @@ -199,10 +197,10 @@ void GenerateReconstructData(std::shared_ptr<VectorSet> &real_vecset, std::share
auto ptr = SPTAG::f_createIO();
if (ptr == nullptr || !ptr->Initialize(CODEBOOK_FILE.c_str(), std::ios::binary | std::ios::in))
{
BOOST_ASSERT("Canot Open CODEBOOK_FILE to read!" == "Error");
GTEST_FAIL() << "Cannot open CODEBOOK_FILE to read!";
}
quantizer->LoadIQuantizer(ptr);
BOOST_ASSERT(quantizer);
ASSERT_TRUE(quantizer != nullptr);

std::shared_ptr<Helper::ReaderOptions> options(
new Helper::ReaderOptions(GetEnumValueType<R>(), m, VectorFileType::DEFAULT));
Expand Down Expand Up @@ -293,17 +291,17 @@ void GenerateReconstructData(std::shared_ptr<VectorSet> &real_vecset, std::share
auto ptr = SPTAG::f_createIO();
if (ptr == nullptr || !ptr->Initialize(CODEBOOK_FILE.c_str(), std::ios::binary | std::ios::out))
{
BOOST_ASSERT("Canot Open CODEBOOK_FILE to write!" == "Error");
GTEST_FAIL() << "Cannot open CODEBOOK_FILE to write!";
}
// quantizer->SaveQuantizer(ptr);
ptr->ShutDown();

if (!ptr->Initialize(CODEBOOK_FILE.c_str(), std::ios::binary | std::ios::in))
{
BOOST_ASSERT("Canot Open CODEBOOK_FILE to read!" == "Error");
GTEST_FAIL() << "Cannot open CODEBOOK_FILE to read!";
}
quantizer->LoadIQuantizer(ptr);
BOOST_ASSERT(quantizer);
ASSERT_TRUE(quantizer != nullptr);

rec_vecset.reset(new BasicVectorSet(ByteArray::Alloc(sizeof(R) * n * m), GetEnumValueType<R>(), m, n));
quan_vecset.reset(
Expand Down Expand Up @@ -659,14 +657,15 @@ template <typename R> void DistancePerfRandomized(IndexAlgoType algo, DistCalcMe
SPTAGLIB_LOG(SPTAG::Helper::LogLevel::LL_Info, "GPU time - baseline:%0.3lf, PQ:%0.3lf\n", GPU_baseline_t, GPU_PQ_t);
}

BOOST_AUTO_TEST_SUITE(GPUPQPerfTest)
namespace GPUPQPerfTestSuite
{

BOOST_AUTO_TEST_CASE(GPUPQCosineTest)
TEST(GPUPQPerfTest, GPUPQCosineTest)
{

DistancePerfSuite<float>(IndexAlgoType::BKT, DistCalcMethod::L2);

DistancePerfRandomized<float>(IndexAlgoType::BKT, DistCalcMethod::L2);
}

BOOST_AUTO_TEST_SUITE_END()
} // namespace GPUPQPerfTestSuite
2 changes: 1 addition & 1 deletion Test/inc/Test.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
#pragma once

#include <iostream>
#include <boost/test/unit_test.hpp>
#include <gtest/gtest.h>
Loading