Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clang-format now errors on push and PR if formatting is incorrect #236

Merged
merged 10 commits into from
Mar 17, 2023
Merged
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
6 changes: 6 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
BasedOnStyle: Microsoft
---
Language: Cpp
SortIncludes: false
...
95 changes: 0 additions & 95 deletions _clang-format

This file was deleted.

21 changes: 12 additions & 9 deletions clang-format.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,21 @@ if (NOT MSVC)
message(STATUS "Setting up `make format` and `make checkformat`")
# additional target to perform clang-format run, requires clang-format
# get all project files
file(GLOB_RECURSE ALL_SOURCE_FILES *.cpp *.h)
file(GLOB_RECURSE ALL_SOURCE_FILES include/*.h python/src/*.cpp src/*.cpp tests/*.cpp)

message(status ${ALL_SOURCE_FILES})

add_custom_target(
format
COMMAND /usr/bin/clang-format
-i
${ALL_SOURCE_FILES}
format
COMMAND /usr/bin/clang-format
-i
${ALL_SOURCE_FILES}
)
add_custom_target(
checkformat
COMMAND /usr/bin/clang-format
--dry-run
${ALL_SOURCE_FILES}
checkformat
COMMAND /usr/bin/clang-format
--Werror
--dry-run
${ALL_SOURCE_FILES}
)
endif()
140 changes: 75 additions & 65 deletions include/aligned_file_reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ typedef io_context_t IOContext;
#include <minwinbase.h>

#ifndef USE_BING_INFRA
struct IOContext {
HANDLE fhandle = NULL;
HANDLE iocp = NULL;
std::vector<OVERLAPPED> reqs;
struct IOContext
{
HANDLE fhandle = NULL;
HANDLE iocp = NULL;
std::vector<OVERLAPPED> reqs;
};
#else
#include "IDiskPriorityIO.h"
Expand All @@ -31,25 +32,32 @@ struct IOContext {
// errors.
// Because of such callous copying, we have to use ptr->atomic instead
// of atomic, as atomic is not copyable.
struct IOContext {
enum Status { READ_WAIT = 0, READ_SUCCESS, READ_FAILED, PROCESS_COMPLETE };

std::shared_ptr<ANNIndex::IDiskPriorityIO> m_pDiskIO = nullptr;
std::shared_ptr<std::vector<ANNIndex::AsyncReadRequest>> m_pRequests;
std::shared_ptr<std::vector<Status>> m_pRequestsStatus;

// waitonaddress on this memory to wait for IO completion signal
// reader should signal this memory after IO completion
// TODO: WindowsAlignedFileReader can be modified to take advantage of this
// and can largely share code with the file reader for Bing.
mutable volatile long m_completeCount = 0;

IOContext()
: m_pRequestsStatus(new std::vector<Status>()),
m_pRequests(new std::vector<ANNIndex::AsyncReadRequest>()) {
(*m_pRequestsStatus).reserve(MAX_IO_DEPTH);
(*m_pRequests).reserve(MAX_IO_DEPTH);
}
struct IOContext
{
enum Status
{
READ_WAIT = 0,
READ_SUCCESS,
READ_FAILED,
PROCESS_COMPLETE
};

std::shared_ptr<ANNIndex::IDiskPriorityIO> m_pDiskIO = nullptr;
std::shared_ptr<std::vector<ANNIndex::AsyncReadRequest>> m_pRequests;
std::shared_ptr<std::vector<Status>> m_pRequestsStatus;

// waitonaddress on this memory to wait for IO completion signal
// reader should signal this memory after IO completion
// TODO: WindowsAlignedFileReader can be modified to take advantage of this
// and can largely share code with the file reader for Bing.
mutable volatile long m_completeCount = 0;

IOContext()
: m_pRequestsStatus(new std::vector<Status>()), m_pRequests(new std::vector<ANNIndex::AsyncReadRequest>())
{
(*m_pRequestsStatus).reserve(MAX_IO_DEPTH);
(*m_pRequests).reserve(MAX_IO_DEPTH);
}
};
#endif

Expand All @@ -63,48 +71,50 @@ struct IOContext {
#include "utils.h"

// NOTE :: all 3 fields must be 512-aligned
struct AlignedRead {
uint64_t offset; // where to read from
uint64_t len; // how much to read
void* buf; // where to read into

AlignedRead() : offset(0), len(0), buf(nullptr) {
}

AlignedRead(uint64_t offset, uint64_t len, void* buf)
: offset(offset), len(len), buf(buf) {
assert(IS_512_ALIGNED(offset));
assert(IS_512_ALIGNED(len));
assert(IS_512_ALIGNED(buf));
// assert(malloc_usable_size(buf) >= len);
}
struct AlignedRead
{
uint64_t offset; // where to read from
uint64_t len; // how much to read
void *buf; // where to read into

AlignedRead() : offset(0), len(0), buf(nullptr)
{
}

AlignedRead(uint64_t offset, uint64_t len, void *buf) : offset(offset), len(len), buf(buf)
{
assert(IS_512_ALIGNED(offset));
assert(IS_512_ALIGNED(len));
assert(IS_512_ALIGNED(buf));
// assert(malloc_usable_size(buf) >= len);
}
};

class AlignedFileReader {
protected:
tsl::robin_map<std::thread::id, IOContext> ctx_map;
std::mutex ctx_mut;

public:
// returns the thread-specific context
// returns (io_context_t)(-1) if thread is not registered
virtual IOContext& get_ctx() = 0;

virtual ~AlignedFileReader(){};

// register thread-id for a context
virtual void register_thread() = 0;
// de-register thread-id for a context
virtual void deregister_thread() = 0;
virtual void deregister_all_threads() = 0;

// Open & close ops
// Blocking calls
virtual void open(const std::string& fname) = 0;
virtual void close() = 0;

// process batch of aligned requests in parallel
// NOTE :: blocking call
virtual void read(std::vector<AlignedRead>& read_reqs, IOContext& ctx,
bool async = false) = 0;
class AlignedFileReader
{
protected:
tsl::robin_map<std::thread::id, IOContext> ctx_map;
std::mutex ctx_mut;

public:
// returns the thread-specific context
// returns (io_context_t)(-1) if thread is not registered
virtual IOContext &get_ctx() = 0;

virtual ~AlignedFileReader(){};

// register thread-id for a context
virtual void register_thread() = 0;
// de-register thread-id for a context
virtual void deregister_thread() = 0;
virtual void deregister_all_threads() = 0;

// Open & close ops
// Blocking calls
virtual void open(const std::string &fname) = 0;
virtual void close() = 0;

// process batch of aligned requests in parallel
// NOTE :: blocking call
virtual void read(std::vector<AlignedRead> &read_reqs, IOContext &ctx, bool async = false) = 0;
};
36 changes: 17 additions & 19 deletions include/ann_exception.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,24 @@
#define __FUNCSIG__ __PRETTY_FUNCTION__
#endif

namespace diskann {
namespace diskann
{

class ANNException : public std::runtime_error {
public:
DISKANN_DLLEXPORT ANNException(const std::string& message, int errorCode);
DISKANN_DLLEXPORT ANNException(const std::string& message, int errorCode,
const std::string& funcSig,
const std::string& fileName,
unsigned int lineNum);
class ANNException : public std::runtime_error
{
public:
DISKANN_DLLEXPORT ANNException(const std::string &message, int errorCode);
DISKANN_DLLEXPORT ANNException(const std::string &message, int errorCode, const std::string &funcSig,
const std::string &fileName, unsigned int lineNum);

private:
private:
int _errorCode;
};
};

class FileException : public ANNException {
public:
DISKANN_DLLEXPORT FileException(const std::string& filename,
std::system_error& e,
const std::string& funcSig,
const std::string& fileName,
unsigned int lineNum);
};
} // namespace diskann
class FileException : public ANNException
{
public:
DISKANN_DLLEXPORT FileException(const std::string &filename, std::system_error &e, const std::string &funcSig,
const std::string &fileName, unsigned int lineNum);
};
} // namespace diskann
9 changes: 4 additions & 5 deletions include/boost_dynamic_bitset_fwd.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@

#pragma once

namespace boost {
namespace boost
{
#ifndef BOOST_DYNAMIC_BITSET_FWD_HPP
template<typename Block = unsigned long,
typename Allocator = std::allocator<Block>>
class dynamic_bitset;
template <typename Block = unsigned long, typename Allocator = std::allocator<Block>> class dynamic_bitset;
#endif
} // namespace boost
} // namespace boost
Loading