33 Logger::log(Logger::DEBUG,
"Bulding uncompressed inv_table...");
34 inv_table::build(max_length, use_load_balance);
37 Logger::log(Logger::DEBUG,
"Bulding compressed inv_table...");
39 std::vector<int> &inv = *(inv_table::inv());
40 std::vector<int> &invPos = *(inv_table::inv_pos());
41 std::vector<uint32_t> &compressedInv = m_comprInv;
42 std::vector<int> &compressedInvPos = m_comprInvPos;
46 std::vector<uint32_t> inv_u32(inv.begin(), inv.end());
48 uint64_t compressionStartTime =
getTime();
53 Logger::log(Logger::ALERT,
"No matching function for %s compression!",
55 throw std::logic_error(
"No compression codec available!");
58 assert(codec->decodeArrayParallel_lengthPerBlock() >= (int)max_length);
60 compressedInv.resize(inv.size()*8);
61 compressedInvPos.clear();
62 compressedInvPos.reserve(invPos.size());
63 compressedInvPos.push_back(0);
65 int compressedInvSize = 0;
66 int64_t compressedInvCapacity = compressedInv.size();
67 int badCompressedLists = 0;
69 uint32_t *out = compressedInv.data();
70 for (
int pos = 0; pos < (int)invPos.size()-1; pos++)
72 int invStart = invPos[pos];
73 int invEnd = invPos[pos+1];
74 assert(invEnd - invStart > 0 && invEnd - invStart <= (
int)max_length);
77 assert(compressedInvCapacity > 0);
80 size_t nvalue = std::min((
size_t)compressedInvCapacity, max_length);
82 uint32_t * data = inv_u32.data() + invStart;
83 codec->encodeArray(data, invEnd - invStart, out, nvalue);
87 assert(nvalue > 0 && nvalue <= max_length);
90 compressedInvCapacity -= nvalue;
91 compressedInvSize += nvalue;
93 compressedInvPos.push_back(compressedInvSize);
95 if ((
int)nvalue >= invEnd - invStart)
99 for (
size_t i = 1; i < compressedInvPos.size(); i++){
100 assert(compressedInvPos[i] > compressedInvPos[i-1]);
103 compressedInv.resize(compressedInvSize);
104 compressedInv.shrink_to_fit();
105 assert(compressedInvSize == compressedInvPos.back());
107 uint64_t compressionEndTime =
getTime();
108 double compressionRatio = 32.0 *
static_cast<double>(compressedInv.size()) / static_cast<double>(inv.size());
110 Logger::log(Logger::DEBUG,
"Done bulding compressed inv_compr_table in time %f",
111 getInterval(compressionStartTime, compressionEndTime));
113 Logger::log(Logger::INFO,
"Compression %s, codec: %s, compression ratio: %f",
116 if (compressionRatio > 16.0 || badCompressedLists)
117 Logger::log(Logger::ALERT,
"Bad compression! Bad compressed lists: %d / %d, compression ratio: %f",
118 badCompressedLists, compressedInvPos.size()-1, compressionRatio);
131 return m_compression;
137 if (this->build_status() != builded)
139 Logger::log(Logger::ALERT,
"Unknown compression ratio: table is not built!");
142 assert(m_comprInv.size());
143 assert(uncompressedInv()->size());
144 return 32.0 *
static_cast<double>(m_comprInv.size()) / static_cast<double>(uncompressedInv()->size());
150 if (this->build_status() == builded)
152 Logger::log(Logger::ALERT,
"ERROR: Attempting to change compression type on already built table!");
155 m_compression = compression;
161 return m_uncompressedInvListsMaxLength;
167 this->m_uncompressedInvListsMaxLength = length;
173 return reinterpret_cast<std::vector<int>*
>(&m_comprInv);
176 std::vector<uint32_t>*
185 return inv_table::inv();
191 return &m_comprInvPos;
196 return &m_comprInvPos;
202 return inv_table::inv_pos();;
208 return m_d_compr_inv_p;
214 if(m_d_compr_inv_p == NULL)
215 cudaCheckErrors(cudaMalloc(&m_d_compr_inv_p,
sizeof(uint32_t) * m_comprInv.size()));
216 cudaCheckErrors(cudaMemcpy(m_d_compr_inv_p, &m_comprInv[0],
sizeof(uint32_t) * m_comprInv.size(),
217 cudaMemcpyHostToDevice));
218 }
catch(std::bad_alloc &e){
231 m_comprInvPos.clear();
236 if (m_d_compr_inv_p == NULL)
239 std::cout <<
"cudaFreeTime: " ;
243 std::cout <<
getInterval(t1, t2) <<
" ms."<< std::endl;
std::vector< int > * compressedInvPos()
void setCompression(genie::compression::COMPRESSION_TYPE compression)
unsigned long long getTime()
Get system time.
virtual std::vector< int > * inv()
std::vector< uint32_t > * compressedInv()
genie::compression::COMPRESSION_TYPE getCompression() const
virtual void build(size_t max_length, bool use_load_balance)
Build the inv_table.
static std::shared_ptr< DeviceIntegerCODEC > getCodec(COMPRESSION_TYPE type)
double getCompressionRatio()
virtual std::vector< int > * inv_pos()
std::vector< int > * uncompressedInvPos()
bool cpy_data_to_gpu()
Copy vector _inv to gpu memory which is referenced by d_inv_p.
virtual ~inv_compr_table()
size_t getUncompressedPostingListMaxLength() const
Record run-time information.
void clear_gpu_mem()
clear the corresponding gpu memory referenced by d_inv_p
unsigned long long u64
A type definition for a 64-bit unsigned integer.
double getInterval(unsigned long long start, unsigned long long stop)
Calculate time interval from start to end.
Functions about getting system time.
std::vector< int > * uncompressedInv()
void setUncompressedPostingListMaxLength(size_t length)
define class inv_compre_table
uint32_t * deviceCompressedInv() const
static std::string getCompressionName(COMPRESSION_TYPE type)
#define cudaCheckErrors(err)
The wrapper function to validate CUDA calls.