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

VS2017 compile errors resolved #16

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Next Next commit
VS2017 compile errors resolved
mshafiei committed Jun 7, 2018

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 049600af8132712f97706d34f34bccd2e8ae2064
13 changes: 8 additions & 5 deletions src/cpu_x86.h
Original file line number Diff line number Diff line change
@@ -35,13 +35,17 @@ struct cpu_x86{
static bool inline detect_OS_AVX512();
static inline uint64_t xgetbv(unsigned int x);
};
/////GCC
}
using namespace fbow;
//// MSCV
#if defined(__x86_64__) || defined(_M_X64) || defined(__i386) || defined(_M_IX86)
# if _WIN32
void cpu_x86::cpuid(int32_t out[4], int32_t x){ __cpuidex(out, x, 0); }
__int64 cpu_x86::xgetbv(unsigned int x){ return _xgetbv(x); }
uint64_t cpu_x86::xgetbv(unsigned int x){ return _xgetbv(x); }
// Detect 64-bit - Note that this snippet of code for detecting 64-bit has been copied from MSDN.
typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL);
#ifndef _M_X64
BOOL IsWow64()
{
BOOL bIsWow64 = FALSE;
@@ -50,15 +54,16 @@ BOOL IsWow64()
if (!fnIsWow64Process(GetCurrentProcess(), &bIsWow64)) return FALSE;
return bIsWow64 ;
}
#endif

bool cpu_x86::cpu_x86::detect_OS_x64(){
#ifdef _M_X64
return true;
#else
return IsWow64() != 0;
#endif
}
/////GCC
}

# elif defined(__GNUC__) || defined(__clang__)
void cpu_x86::cpuid(int32_t out[4], int32_t x){ __cpuid_count(x, 0, out[0], out[1], out[2], out[3]); }
uint64_t cpu_x86::xgetbv(unsigned int index){ uint32_t eax, edx; __asm__ __volatile__("xgetbv" : "=a"(eax), "=d"(edx) : "c"(index)); return ((uint64_t)edx << 32) | eax;}
@@ -94,6 +99,4 @@ void cpu_x86::detect_host(){ OS_x64 = detect_OS_x64(); OS_AVX = detect_OS_AV
if (nIds >= 0x00000007){ cpuid(info, 0x00000007); HW_AVX2 = (info[1] & ((int)1 << 5)) != 0; HW_BMI1 = (info[1] & ((int)1 << 3)) != 0; HW_BMI2 = (info[1] & ((int)1 << 8)) != 0; HW_ADX = (info[1] & ((int)1 << 19)) != 0; HW_MPX = (info[1] & ((int)1 << 14)) != 0; HW_SHA = (info[1] & ((int)1 << 29)) != 0; HW_PREFETCHWT1 = (info[2] & ((int)1 << 0)) != 0; HW_AVX512_F = (info[1] & ((int)1 << 16)) != 0; HW_AVX512_CD = (info[1] & ((int)1 << 28)) != 0; HW_AVX512_PF = (info[1] & ((int)1 << 26)) != 0; HW_AVX512_ER = (info[1] & ((int)1 << 27)) != 0; HW_AVX512_VL = (info[1] & ((int)1 << 31)) != 0; HW_AVX512_BW = (info[1] & ((int)1 << 30)) != 0; HW_AVX512_DQ = (info[1] & ((int)1 << 17)) != 0; HW_AVX512_IFMA = (info[1] & ((int)1 << 21)) != 0; HW_AVX512_VBMI = (info[2] & ((int)1 << 1)) != 0; }
if (nExIds >= 0x80000001){ cpuid(info, 0x80000001); HW_x64 = (info[3] & ((int)1 << 29)) != 0; HW_ABM = (info[2] & ((int)1 << 5)) != 0; HW_SSE4a = (info[2] & ((int)1 << 6)) != 0; HW_FMA4 = (info[2] & ((int)1 << 16)) != 0; HW_XOP = (info[2] & ((int)1 << 11)) != 0; }
}

}
#endif
12 changes: 11 additions & 1 deletion src/fbow.cpp
Original file line number Diff line number Diff line change
@@ -45,7 +45,11 @@ void Vocabulary::setParams(int aligment, int k, int desc_type, int desc_size, in

//give memory
_params._total_size=_params._block_size_bytes_wp*_params._nblocks;
#if _WIN32
_data = (char*)_aligned_malloc(_params._aligment, _params._total_size);
#else
_data=(char*)aligned_alloc(_params._aligment,_params._total_size);
#endif
memset( _data,0,_params._total_size);

}
@@ -147,7 +151,13 @@ void Vocabulary::fromStream(std::istream &str)throw(std::exception)
if (sig!=55824124) throw std::runtime_error("Vocabulary::fromStream invalid signature");
//read string
str.read((char*)&_params,sizeof(params));
_data=(char*)aligned_alloc(_params._aligment,_params._total_size);

#if _WIN32
_data = (char*)_aligned_malloc(_params._aligment, _params._total_size);
#else
_data = (char*)aligned_alloc(_params._aligment, _params._total_size);
#endif

if (_data==0) throw std::runtime_error("Vocabulary::fromStream Could not allocate data");
str.read(_data,_params._total_size);
}
7 changes: 6 additions & 1 deletion src/fbow.h
Original file line number Diff line number Diff line change
@@ -190,7 +190,12 @@ class FBOW_API Vocabulary
_block_desc_size_bytes_wp=block_desc_size_bytes_wp;
assert(_block_desc_size_bytes_wp%sizeof(register_type )==0);
_nwords=_block_desc_size_bytes_wp/sizeof(register_type );//number of aligned words
feature=(register_type*)aligned_alloc(aligment,_nwords*sizeof(register_type ));

#if _WIN32
feature = (register_type*)_aligned_malloc(aligment, _nwords * sizeof(register_type));
#else
feature = (register_type*)aligned_alloc(aligment, _nwords * sizeof(register_type));
#endif
memset(feature,0,_nwords*sizeof(register_type ));
}
inline void startwithfeature(const register_type *feat_ptr){memcpy(feature,feat_ptr,_desc_size);}
2 changes: 1 addition & 1 deletion tests/test_cpu_x86.cpp
Original file line number Diff line number Diff line change
@@ -75,7 +75,7 @@ void print(cpu_x86 host_info) {

int main(){

cout << "CPU Vendor String: " << cpu_x86::get_vendor_string() << endl;
cout << "CPU Vendor String: " << cpu_x86::get_vendor_string().c_str() << endl;
cout << endl;
cpu_x86 features;
features.detect_host();