source /opt/dtk/env.sh

cd /opt/dtk/.hip/
./remove_origin.sh

cd -

mkdir build -p
cd build
rm hc_* -f
export CPLUS_INCLUDE_PATH=${ROCM_PATH}/include:${ROCM_PATH}:/opencl/include
export CPLUS_INCLUDE_PATH=${ROCM_PATH}/hiprand/include/:${ROCM_PATH}/rocrand/include:$CPLUS_INCLUDE_PATH
export LD_LIBRARY_PATH=${ROCM_PATH}/hipblas/lib/:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=${ROCM_PATH}/llvm/lib:$LD_LIBRARY_PATH

#alias python='python3'

export BUILD_DIR=`pwd`

#######################
#CXX=hipcc CC=hipcc  cmake -DFAISS_ENABLE_GPU=ON -DBUILD_SHARED_LIBS=ON -DBUILD_TESTING=ON -DCMAKE_BUILD_TYPE=DEBUG -DCMAKE_MODULE_PATH="${ROCM_PATH}/hip/cmake/" -DMKL_LIBRARIES=/public/software/compiler/intel-compiler-2017.5.239/mkl/lib/intel64_lin/ ..
CXX=hipcc CC=hipcc  cmake -DFAISS_ENABLE_GPU=ON -DBUILD_SHARED_LIBS=ON -DFAISS_OPT_LEVEL=avx -DBUILD_TESTING=ON -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_MODULE_PATH="${ROCM_PATH}/hip/cmake/"  -DCMAKE_INSTALL_PREFIX=${BUILD_DIR}/install  -DMKL_LIBRARIES=/public/software/compiler/intel-compiler-2017.5.239/mkl/lib/intel64_lin/libmkl_rt.so ..

make -j32 faiss VERBOSE=1 > hc_faiss.log 2>&1 
make -j32 swigfaiss VERBOSE=1 > hc_swigfaiss.log 2>&1 

export LD_LIBRARY_PATH=${BUILD_DIR}/faiss/gpu/test/:${BUILD_DIR}/faiss/:${BUILD_DIR}/lib/:$LD_LIBRARY_PATH
make -j32 install VERBOSE=1 > hc_install.log 2>&1 

#make -j32 test VERBOSE=1 > hc_test.log 2>&1
cd -

./test_gpu.sh

cd build/faiss/python
python3 setup.py -v bdist_wheel
pip3 install dist/* --no-deps --force
cd -

./test_gpu_python.sh
