Remove 1L and 1UL

Summary: 1L and 1UL are problematic because sizeof(long) depends on the platform

Reviewed By: mlomeli1

Differential Revision: D49911901

fbshipit-source-id: d4e4cb1f0283a33330bf1b8ca6b7f7bf41bc6ff4
pull/3074/merge
Matthijs Douze 2023-10-04 09:11:48 -07:00 committed by Facebook GitHub Bot
parent 3f3321c446
commit 2b48901b51
6 changed files with 12 additions and 12 deletions

View File

@ -576,7 +576,7 @@ float kmeans_clustering(
const float* x, const float* x,
float* centroids) { float* centroids) {
Clustering clus(d, k); Clustering clus(d, k);
clus.verbose = d * n * k > (1L << 30); clus.verbose = d * n * k > (size_t(1) << 30);
// display logs if > 1Gflop per iteration // display logs if > 1Gflop per iteration
IndexFlatL2 index(d); IndexFlatL2 index(d);
clus.train(n, x, index); clus.train(n, x, index);

View File

@ -47,7 +47,7 @@ Index2Layer::Index2Layer(
pq(quantizer->d, M, nbit) { pq(quantizer->d, M, nbit) {
is_trained = false; is_trained = false;
for (int nbyte = 0; nbyte < 7; nbyte++) { for (int nbyte = 0; nbyte < 7; nbyte++) {
if ((1L << (8 * nbyte)) >= nlist) { if (((size_t)1 << (8 * nbyte)) >= nlist) {
code_size_1 = nbyte; code_size_1 = nbyte;
break; break;
} }
@ -179,7 +179,7 @@ struct DistanceXPQ4 : Distance2Level {
float operator()(idx_t i) override { float operator()(idx_t i) override {
#ifdef __SSE3__ #ifdef __SSE3__
const uint8_t* code = storage.codes.data() + i * storage.code_size; const uint8_t* code = storage.codes.data() + i * storage.code_size;
long key = 0; idx_t key = 0;
memcpy(&key, code, storage.code_size_1); memcpy(&key, code, storage.code_size_1);
code += storage.code_size_1; code += storage.code_size_1;
@ -225,7 +225,7 @@ struct Distance2xXPQ4 : Distance2Level {
float operator()(idx_t i) override { float operator()(idx_t i) override {
const uint8_t* code = storage.codes.data() + i * storage.code_size; const uint8_t* code = storage.codes.data() + i * storage.code_size;
long key01 = 0; int64_t key01 = 0;
memcpy(&key01, code, storage.code_size_1); memcpy(&key01, code, storage.code_size_1);
code += storage.code_size_1; code += storage.code_size_1;
#ifdef __SSE3__ #ifdef __SSE3__
@ -237,7 +237,7 @@ struct Distance2xXPQ4 : Distance2Level {
__m128 accu = _mm_setzero_ps(); __m128 accu = _mm_setzero_ps();
for (int mi_m = 0; mi_m < 2; mi_m++) { for (int mi_m = 0; mi_m < 2; mi_m++) {
long l1_idx = key01 & ((1L << mi_nbits) - 1); int64_t l1_idx = key01 & (((int64_t)1 << mi_nbits) - 1);
const __m128* pq_l1 = pq_l1_t + M_2 * l1_idx; const __m128* pq_l1 = pq_l1_t + M_2 * l1_idx;
for (int m = 0; m < M_2; m++) { for (int m = 0; m < M_2; m++) {

View File

@ -818,7 +818,7 @@ struct MinSumK {
// enqueue followers // enqueue followers
int64_t ii = ti; int64_t ii = ti;
for (int m = 0; m < M; m++) { for (int m = 0; m < M; m++) {
int64_t n = ii & ((1L << nbit) - 1); int64_t n = ii & (((int64_t)1 << nbit) - 1);
ii >>= nbit; ii >>= nbit;
if (n + 1 >= N) if (n + 1 >= N)
continue; continue;
@ -842,7 +842,7 @@ struct MinSumK {
} }
int64_t ti = 0; int64_t ti = 0;
for (int m = 0; m < M; m++) { for (int m = 0; m < M; m++) {
int64_t n = ii & ((1L << nbit) - 1); int64_t n = ii & (((int64_t)1 << nbit) - 1);
ti += int64_t(ssx[m].get_ord(n)) << (nbit * m); ti += int64_t(ssx[m].get_ord(n)) << (nbit * m);
ii >>= nbit; ii >>= nbit;
} }
@ -966,7 +966,7 @@ void MultiIndexQuantizer::search(
void MultiIndexQuantizer::reconstruct(idx_t key, float* recons) const { void MultiIndexQuantizer::reconstruct(idx_t key, float* recons) const {
int64_t jj = key; int64_t jj = key;
for (int m = 0; m < pq.M; m++) { for (int m = 0; m < pq.M; m++) {
int64_t n = jj & ((1L << pq.nbits) - 1); int64_t n = jj & (((int64_t)1 << pq.nbits) - 1);
jj >>= pq.nbits; jj >>= pq.nbits;
memcpy(recons, pq.get_centroids(m, n), sizeof(recons[0]) * pq.dsub); memcpy(recons, pq.get_centroids(m, n), sizeof(recons[0]) * pq.dsub);
recons += pq.dsub; recons += pq.dsub;
@ -1098,7 +1098,7 @@ void MultiIndexQuantizer2::search(
const idx_t* idmap0 = sub_ids.data() + i * k2; const idx_t* idmap0 = sub_ids.data() + i * k2;
int64_t ld_idmap = k2 * n; int64_t ld_idmap = k2 * n;
int64_t mask1 = ksub - 1L; int64_t mask1 = ksub - (int64_t)1;
for (int k = 0; k < K; k++) { for (int k = 0; k < K; k++) {
const idx_t* idmap = idmap0; const idx_t* idmap = idmap0;

View File

@ -42,7 +42,7 @@ int main(int argc, char** argv) {
cudaProfilerStop(); cudaProfilerStop();
auto seed = FLAGS_seed != -1L ? FLAGS_seed : time(nullptr); auto seed = FLAGS_seed != -1 ? FLAGS_seed : time(nullptr);
printf("using seed %ld\n", seed); printf("using seed %ld\n", seed);
std::vector<float> vecs((size_t)FLAGS_num * FLAGS_dim); std::vector<float> vecs((size_t)FLAGS_num * FLAGS_dim);

View File

@ -230,7 +230,7 @@ bool InterruptCallback::is_interrupted() {
size_t InterruptCallback::get_period_hint(size_t flops) { size_t InterruptCallback::get_period_hint(size_t flops) {
if (!instance.get()) { if (!instance.get()) {
return 1L << 30; // never check return (size_t)1 << 30; // never check
} }
// for 10M flops, it is reasonable to check once every 10 iterations // for 10M flops, it is reasonable to check once every 10 iterations
return std::max((size_t)10 * 10 * 1000 * 1000 / (flops + 1), (size_t)1); return std::max((size_t)10 * 10 * 1000 * 1000 / (flops + 1), (size_t)1);

View File

@ -455,7 +455,7 @@ void ZnSphereCodec::decode(uint64_t code, float* c) const {
int nnz = 0; int nnz = 0;
for (int i = 0; i < dim; i++) { for (int i = 0; i < dim; i++) {
if (c[i] != 0) { if (c[i] != 0) {
if (signs & (1UL << nnz)) { if (signs & (uint64_t(1) << nnz)) {
c[i] = -c[i]; c[i] = -c[i];
} }
nnz++; nnz++;