Skip to content
Open
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,7 @@ visualization/animation.gif

# FAISS third_party dependencies
!build/.gitkeep

# WINDOWS
.vs/

53 changes: 33 additions & 20 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
cmake_minimum_required (VERSION 3.20)
project(tsnecuda)
project(tsnecuda LANGUAGES CXX)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS 1) # https://stackoverflow.com/questions/37128555/getting-cmake-to-build-shared-library-for-msvc

set (CMAKE_PROJECT_VERSION 3)
set (CMAKE_PROJECT_VERSION_MAJOR 3)
set (CMAKE_PROJECT_VERSION_MINOR 0)
Expand Down Expand Up @@ -37,11 +39,11 @@ set(OPT_FLAGS
-msse4
-fPIC
-m64
-Wno-sign-compare
#-Wno-sign-compare
-g
-O3
-Wall
-Wextra
#-Wextra
-DFINTEGER=int
)
string(REPLACE ";" " " CXX_FLAGS_STR "${CMAKE_CXX_FLAGS} ${OPT_FLAGS}")
Expand Down Expand Up @@ -120,18 +122,25 @@ else()
endif()


#set(CUDA_OPTS
# -O3
# -g
# -Xptxas '-dlcm=cg'
# -Xcompiler '-O3'
# -Xcompiler '-fPIC'
# -Xcompiler '-fopenmp'
# -Xcompiler '-msse4'
# -Xcompiler '-m64'
# -Xcompiler '-mpopcnt'
# -Xcompiler '-g'
# -Xlinker 'muldefs'
#)
set(CUDA_OPTS
-O3
-g
-Xptxas '-dlcm=cg'
-Xcompiler '-O3'
-Xcompiler '-fPIC'
-Xcompiler '-fopenmp'
-Xcompiler '-msse4'
-Xcompiler '-m64'
-Xcompiler '-mpopcnt'
-Xcompiler '-g'
-Xlinker 'muldefs'
-Xptxas -dlcm=cg
-Xcompiler /DYNAMICBASE,/openmp,/arch:AVX,/Zi,/Ox #-mpopcnt,
-Xlinker muldefs
)
string (REPLACE ";" " " NVCC_FLAGS_STR "${CUDA_ARCH} ${CUDA_OPTS}")
set(CMAKE_CUDA_FLAGS "${NVCC_FLAGS_STR}")
Expand All @@ -145,9 +154,13 @@ find_package(OpenMP REQUIRED)

# GTEST Configuration
#-------------------------------------------------------------------------------
find_package(gflags REQUIRED)
find_package(GFlags REQUIRED)
include_directories(${GFLAGS_INCLUDE_DIR})

# find_package(GLog REQUIRED)
find_package(GTest REQUIRED)
include_directories(${GTEST_INCLUDE_DIR})

#-------------------------------------------------------------------------------

# ZMQ Configuration
Expand Down Expand Up @@ -223,17 +236,17 @@ set(PYTHON_SOURCES
add_library(tsnecuda SHARED ${SOURCES})
# set_property(TARGET tsnecuda PROPERTY POSITION_INDEPENDENT_CODE TRUE)
target_link_libraries(tsnecuda PRIVATE
gflags
gtest
${GFLAGS_LIBRARIES}
${GTEST_LIBRARIES}
CUDA::cudart
CUDA::cublas
# CUDA::cublasLt
CUDA::cufft
CUDA::cufftw
CUDA::cusparse
OpenMP::OpenMP_CXX
pthread
-Wl,--allow-multiple-definition
# pthread
# -Wl,--allow-multiple-definition
${ZMQ_LIBRARIES}
${FAISS_LIBRARIES}
)
Expand All @@ -244,7 +257,7 @@ find_package(MKL)
if(MKL_FOUND)
target_link_libraries(tsnecuda PRIVATE ${MKL_LIBRARIES})
else()
find_package(BLAS REQUIRED)
find_package(OpenBLAS REQUIRED)
target_link_libraries(tsnecuda PRIVATE ${BLAS_LIBRARIES})

find_package(LAPACK REQUIRED)
Expand All @@ -255,8 +268,8 @@ endif()
#-------------------------------------------------------------------------------
# Main executable
#-------------------------------------------------------------------------------
add_executable(tsne src/exe/main.cu)
target_link_libraries(tsne tsnecuda)
#add_executable(tsne src/exe/main.cu)
#target_link_libraries(tsne tsnecuda)

#-------------------------------------------------------------------------------
# Python library copy and build
Expand Down
10 changes: 6 additions & 4 deletions cmake/Modules/FindFAISS.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@

include(FindPackageHandleStandardArgs)

set(FAISS_ROOT_DIR "" CACHE PATH "Folder contains FAISS")
if(NOT DEFINED FAISS_ROOT_DIR)
set(FAISS_ROOT_DIR "" CACHE PATH "Folder contains FAISS")
endif()

# We are testing only a couple of files in the include directories
find_path(FAISS_INCLUDE_DIR faiss/Index.h PATHS ${FAISS_ROOT_DIR})
find_path(FAISS_GPU_INCLUDE_DIR faiss/gpu/GpuIndex.h PATHS ${FAISS_ROOT_DIR})
find_library(FAISS_LIBRARY faiss)
find_path(FAISS_INCLUDE_DIR faiss/Index.h PATHS "${FAISS_ROOT_DIR}/include")
find_path(FAISS_GPU_INCLUDE_DIR faiss/gpu/GpuIndex.h PATHS "${FAISS_ROOT_DIR}/include")
find_library(FAISS_LIBRARY faiss PATHS "${FAISS_ROOT_DIR}/lib")

find_package_handle_standard_args(FAISS DEFAULT_MSG FAISS_INCLUDE_DIR FAISS_GPU_INCLUDE_DIR FAISS_LIBRARY)

Expand Down
25 changes: 2 additions & 23 deletions cmake/Modules/FindGFlags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,8 @@ include(FindPackageHandleStandardArgs)
set(GFLAGS_ROOT_DIR "" CACHE PATH "Folder contains Gflags")

# We are testing only a couple of files in the include directories
if(WIN32)
find_path(GFLAGS_INCLUDE_DIR gflags/gflags.h
PATHS ${GFLAGS_ROOT_DIR}/src/windows)
else()
find_path(GFLAGS_INCLUDE_DIR gflags/gflags.h
PATHS ${GFLAGS_ROOT_DIR})
endif()

if(MSVC)
find_library(GFLAGS_LIBRARY_RELEASE
NAMES libgflags
PATHS ${GFLAGS_ROOT_DIR}
PATH_SUFFIXES Release)

find_library(GFLAGS_LIBRARY_DEBUG
NAMES libgflags-debug
PATHS ${GFLAGS_ROOT_DIR}
PATH_SUFFIXES Debug)

set(GFLAGS_LIBRARY optimized ${GFLAGS_LIBRARY_RELEASE} debug ${GFLAGS_LIBRARY_DEBUG})
else()
find_library(GFLAGS_LIBRARY gflags)
endif()
find_path(GFLAGS_INCLUDE_DIR gflags/gflags.h PATHS "${GFLAGS_ROOT_DIR}/include")
find_library(GFLAGS_LIBRARY gflags PATHS "${GFLAGS_ROOT_DIR}/lib")

find_package_handle_standard_args(GFlags DEFAULT_MSG GFLAGS_INCLUDE_DIR GFLAGS_LIBRARY)

Expand Down
29 changes: 29 additions & 0 deletions cmake/Modules/FindGTest.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# - Try to find GTEST
#
# The following variables are optionally searched for defaults
# GTEST_ROOT_DIR: Base directory where all GTEST components are found
#
# The following are set after configuration is done:
# GTEST_FOUND
# GTEST_INCLUDE_DIRS
# GTEST_LIBRARIES
# GTEST_LIBRARYRARY_DIRS

include(FindPackageHandleStandardArgs)

set(GTEST_ROOT_DIR "" CACHE PATH "Folder contains GTest")

# We are testing only a couple of files in the include directories
find_path(GTEST_INCLUDE_DIR gtest/gtest.h PATHS "${GTEST_ROOT_DIR}/include")
find_library(GTEST_LIBRARY gtest PATHS "${GTEST_ROOT_DIR}/lib")

find_package_handle_standard_args(GTest DEFAULT_MSG GTEST_INCLUDE_DIR GTEST_LIBRARY)


if(GTEST_FOUND)
set(GTEST_INCLUDE_DIRS ${GTEST_INCLUDE_DIR})
set(GTEST_LIBRARIES ${GTEST_LIBRARY})
message(STATUS "Found gtest (include: ${GTEST_INCLUDE_DIR}, library: ${GTEST_LIBRARY})")
mark_as_advanced(GTEST_LIBRARY_DEBUG GTEST_LIBRARY_RELEASE
GTEST_LIBRARY GTEST_INCLUDE_DIR GTEST_ROOT_DIR)
endif()
4 changes: 2 additions & 2 deletions cmake/Modules/FindMKL.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ find_path(MKL_ROOT_DIR
/opt/intel/mkl/
/opt/intel/cmkl/
/Library/Frameworks/Intel_MKL.framework/Versions/Current/lib/universal
"Program Files (x86)/Intel/ComposerXE-2011/mkl"
"C:/Program Files (x86)/Intel/oneAPI/mkl/latest"
)

#MESSAGE("-- MKL_ROOT_DIR : ${MKL_ROOT_DIR}") # for debug
MESSAGE("-- MKL_ROOT_DIR : ${MKL_ROOT_DIR}") # for debug

find_path(MKL_INCLUDE_DIR
mkl_cblas.h
Expand Down
4 changes: 3 additions & 1 deletion cmake/Modules/FindOpenBLAS.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ SET(Open_BLAS_INCLUDE_SEARCH_PATHS
/opt/OpenBLAS/include
$ENV{OpenBLAS_HOME}
$ENV{OpenBLAS_HOME}/include
./blas/include
)

SET(Open_BLAS_LIB_SEARCH_PATHS
Expand All @@ -28,10 +29,11 @@ SET(Open_BLAS_LIB_SEARCH_PATHS
$ENV{OpenBLAS}/lib
$ENV{OpenBLAS_HOME}
$ENV{OpenBLAS_HOME}/lib
./blas/lib
)

FIND_PATH(OpenBLAS_INCLUDE_DIR NAMES cblas.h PATHS ${Open_BLAS_INCLUDE_SEARCH_PATHS})
FIND_LIBRARY(OpenBLAS_LIB NAMES openblas PATHS ${Open_BLAS_LIB_SEARCH_PATHS})
FIND_LIBRARY(OpenBLAS_LIB NAMES libopenblas PATHS ${Open_BLAS_LIB_SEARCH_PATHS})

SET(OpenBLAS_FOUND ON)

Expand Down
6 changes: 3 additions & 3 deletions src/fit_tsne.cu
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ void tsnecuda::RunTsne(tsnecuda::Options &opt,
// TODO: Investigate what it takes to use unified memory + Async fetch and execution
float *knn_squared_distances = new float[num_points * num_neighbors];
memset(knn_squared_distances, 0, num_points * num_neighbors * sizeof(float));
long *knn_indices = new long[num_points * num_neighbors];
int64_t *knn_indices = new int64_t[num_points * num_neighbors];

// Set cache configs
// cudaFuncSetCacheConfig(tsnecuda::IntegrationKernel, cudaFuncCachePreferL1);
Expand All @@ -116,7 +116,7 @@ void tsnecuda::RunTsne(tsnecuda::Options &opt,
// TODO: Add suport for arbitrary metrics on GPU (Introduced by recent FAISS computation)
// TODO: Expose Multi-GPU computation (+ Add streaming memory support for GPU optimization)
tsnecuda::util::KNearestNeighbors(gpu_opt, opt, knn_indices, knn_squared_distances, high_dim_points, high_dim, num_points, num_neighbors);
thrust::device_vector<long> knn_indices_long_device(knn_indices, knn_indices + num_points * num_neighbors);
thrust::device_vector<int64_t> knn_indices_long_device(knn_indices, knn_indices + num_points * num_neighbors);
thrust::device_vector<int> pij_indices_device(num_points * num_neighbors);
tsnecuda::util::PostprocessNeighborIndices(gpu_opt, pij_indices_device, knn_indices_long_device,
num_points, num_neighbors);
Expand Down Expand Up @@ -243,7 +243,7 @@ void tsnecuda::RunTsne(tsnecuda::Options &opt,
}

// FIT-TNSE Parameters
int n_interpolation_points = 3;
const int n_interpolation_points = 3;
// float intervals_per_integer = 1;
int min_num_intervals = 125;
int N = num_points;
Expand Down
9 changes: 8 additions & 1 deletion src/include/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
#include <string.h>
#include <math.h>
#include <time.h>
#include <sys/time.h>
//#include <sys/time.h>

// C++ Library includes
#include <random>
Expand All @@ -58,3 +58,10 @@
#include <cmath>

#endif

#if defined(_MSC_VER)
# pragma warning(push)
# pragma warning(disable: 4127) // warning C4127: Conditional expression is constant
#include <BaseTsd.h>
typedef SSIZE_T ssize_t;
#endif
2 changes: 1 addition & 1 deletion src/include/util/distance_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ void KNearestNeighbors(tsnecuda::GpuOptions &gpu_opt, tsnecuda::Options &base_op

__global__ void PostprocessNeighborIndicesKernel(
volatile int *__restrict__ indices,
const long *__restrict__ long_indices,
const int64_t *__restrict__ long_indices,
const int num_points,
const int num_neighbors);

Expand Down
2 changes: 1 addition & 1 deletion src/python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
author='Chan, David M., Huang, Forrest., Rao, Roshan.',
author_email='[email protected]',
packages=['tsnecuda', 'tsnecuda.test'],
package_data={'tsnecuda': ['libtsnecuda.so']},
package_data={'tsnecuda': ['libtsnecuda.so', 'tsnecuda.dll']},
scripts=[],
url='https://github.com/CannyLab/tsne-cuda',
license='LICENSE.txt',
Expand Down
3 changes: 1 addition & 2 deletions src/python/tsnecuda/TSNE.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,7 @@ def __init__(self,

# Build the hooks for the BH T-SNE library
self._path = os.path.dirname(__file__)
self._lib = N.ctypeslib.load_library(
'libtsnecuda', self._path) # Load the ctypes library
self._lib = ctypes.CDLL('tsnecuda.dll', winmode=0)

# Hook the BH T-SNE function
self._lib.pymodule_tsne.restype = None
Expand Down
2 changes: 1 addition & 1 deletion src/util/distance_utils.cu
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ void tsnecuda::util::KNearestNeighbors(tsnecuda::GpuOptions &gpu_opt,
// TODO: Maybe think about getting FAISS to return integers (long-term todo)
__global__ void tsnecuda::util::PostprocessNeighborIndicesKernel(
volatile int *__restrict__ indices,
const long *__restrict__ long_indices,
const int64_t *__restrict__ long_indices,
const int num_points,
const int num_neighbors)
{
Expand Down
19 changes: 19 additions & 0 deletions windows.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
The CLI commands I did to compile tsne-cuda. Mind the paths, also MKL/OpenBLAS search paths are still hardcoded into CMAKE, might need to change them:

conda install conda-forge::faiss-gpu
conda install conda-forge::gflags
conda install conda-forge::gtest

cmake -G "Visual Studio 17 2022" -A x64 -DCMAKE_CONFIGURATION_TYPES:STRING="RelWithDebInfo" -DGFLAGS_ROOT_DIR="C:\Users\Michael\miniconda3\Library" -DFAISS_ROOT_DIR="C:/Users/Michael/miniconda3/Library" -DGTEST_ROOT_DIR="C:\Users\Michael\miniconda3\Library" -B "C:\Users\Michael\CProjects\tsne-cuda\build" -T cuda=11.8 "C:\Users\Michael\CProjects\tsne-cuda"

"C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\MSBuild.exe" "C:\Users\Michael\CProjects\tsne-cuda\build\tsnecuda.sln"

pip install "C:\Users\Michael\CProjects\tsne-cuda\build\RelWithDebInfo\python"

" if it failed to, copy tsnecuda.dll into "C:\Users\Michael\miniconda3\envs\transformers\Library\bin\tsnecuda.dll manually""

----Questionable things I did not find windows analogue for and commented out----
pthread
sys/time.h
cxx compiler flag -mpopcnt
-Wl,--allow-multiple-definition unrecognized options