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

add cmake support for precompiled headers #4763

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion .ci/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ jobs:
ccacheDir: '$(build.binariesDirectory)/ccache'
ccacheArtifactName: 'ccache-macos'
ccacheArchive: '$(Build.ArtifactStagingDirectory)/ccache-$(Build.BuildId).tar'
commonMacOSCMakeFlags: '-DBUILD_EXAMPLES=OFF -DBUNDLE_JSON=OFF -DBUNDLE_NLOPT=OFF -DENABLE_TESTING=ON -DENABLE_COVERAGE=OFF -DBUILD_META_EXAMPLES=OFF'
commonMacOSCMakeFlags: '-DBUILD_EXAMPLES=OFF -DBUNDLE_NLOPT=OFF -DENABLE_TESTING=ON -DENABLE_COVERAGE=OFF -DBUILD_META_EXAMPLES=OFF'
openMPMacOSCMakeFlags:
'-DOpenMP_CXX_FLAGS="-Xpreprocessor -fopenmp"
-DOpenMP_C_FLAGS="-Xpreprocessor -fopenmp"
Expand Down
6 changes: 1 addition & 5 deletions cmake/FindCCache.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@ endif()

# handle REQUIRED and QUIET options
include(FindPackageHandleStandardArgs)
if (CMAKE_VERSION LESS 2.8.3)
find_package_handle_standard_args(CCache DEFAULT_MSG CCACHE CCACHE_VERSION)
else ()
find_package_handle_standard_args(CCache REQUIRED_VARS CCACHE CCACHE_VERSION)
endif ()
find_package_handle_standard_args(CCache REQUIRED_VARS CCACHE CCACHE_VERSION)

if (CCACHE_FOUND)
if(${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")
Expand Down
62 changes: 62 additions & 0 deletions src/shogun/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,68 @@ IF(MSVC)
target_link_libraries(shogun_deps INTERFACE winmm Shlwapi)
ENDIF()

########################### PCH
if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.16.0)
if (CCACHE_FOUND)
if (DEFINED ENV{CCACHE_SLOPPINESS})
if (NOT "$ENV{CCACHE_SLOPPINESS}" MATCHES "pch_defines" OR
NOT "$ENV{CCACHE_SLOPPINESS}" MATCHES "time_macros")
MESSAGE (WARNING
"ccache requires the environment variable CCACHE_SLOPPINESS to be set to \"pch_defines,time_macros\"."
)
SET(CCACHE_PCH_READY 0)
else()
SET(CCACHE_PCH_READY 1)
endif()
else()
execute_process(
COMMAND "${COMPILER_CACHE_EXECUTABLE}" "-p"
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
RESULT_VARIABLE _result
OUTPUT_VARIABLE _ccacheConfig OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET)
if (_result)
MESSAGE (WARNING "ccache configuration cannot be determined.")
SET(CCACHE_PCH_READY 0)
elseif (NOT _ccacheConfig MATCHES "sloppiness.*=.*time_macros" OR
NOT _ccacheConfig MATCHES "sloppiness.*=.*pch_defines")
MESSAGE (WARNING
"ccache requires configuration setting \"sloppiness\" to be set to \"pch_defines,time_macros\"."
)
SET(CCACHE_PCH_READY 0)
else()
SET(CCACHE_PCH_READY 1)
endif()
endif()

endif()

if (NOT CCACHE_FOUND OR CCACHE_PCH_READY)
message(STATUS "Using precompiled headers")
# FIXME: make sure all the headers are listed that could be precompiled
target_precompile_headers(libshogun
PUBLIC "$<$<COMPILE_LANGUAGE:CXX>:${LIBSHOGUN_HEADERS}>"
PRIVATE
$<$<COMPILE_LANGUAGE:CXX>:<algorithm$<ANGLE-R>>
$<$<COMPILE_LANGUAGE:CXX>:<initializer_list$<ANGLE-R>>
$<$<COMPILE_LANGUAGE:CXX>:<functional$<ANGLE-R>>
$<$<COMPILE_LANGUAGE:CXX>:<map$<ANGLE-R>>
$<$<COMPILE_LANGUAGE:CXX>:<memory$<ANGLE-R>>
$<$<COMPILE_LANGUAGE:CXX>:<set$<ANGLE-R>>
$<$<COMPILE_LANGUAGE:CXX>:<sstream$<ANGLE-R>>
$<$<COMPILE_LANGUAGE:CXX>:<string$<ANGLE-R>>
$<$<COMPILE_LANGUAGE:CXX>:<string_view$<ANGLE-R>>
$<$<COMPILE_LANGUAGE:CXX>:<unordered_map$<ANGLE-R>>
$<$<COMPILE_LANGUAGE:CXX>:<unordered_set$<ANGLE-R>>
$<$<COMPILE_LANGUAGE:CXX>:<utility$<ANGLE-R>>
$<$<COMPILE_LANGUAGE:CXX>:<vector$<ANGLE-R>>
$<$<COMPILE_LANGUAGE:CXX>:<Eigen/Dense$<ANGLE-R>>
$<$<COMPILE_LANGUAGE:CXX>:<Eigen/Sparse$<ANGLE-R>>
$<$<COMPILE_LANGUAGE:CXX>:<Eigen/SVD$<ANGLE-R>>)
endif()
endif()


########################### compiler capabilities
FIND_PACKAGE(Threads)
IF (CMAKE_USE_PTHREADS_INIT)
Expand Down
27 changes: 14 additions & 13 deletions src/shogun/classifier/mkl/MKLMulticlass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <shogun/labels/MulticlassLabels.h>

#include <shogun/lib/Signal.h>
#include <memory>
#include <utility>
#include <vector>

Expand Down Expand Up @@ -137,7 +138,7 @@ bool MKLMulticlass::evaluatefinishcriterion(const int32_t

wold=weightshistory[ weightshistory.size()-2 ];
wnew=weightshistory.back();
float64_t delta=0;
float64_t _delta=0;

ASSERT (wold.size()==wnew.size())

Expand All @@ -146,23 +147,23 @@ bool MKLMulticlass::evaluatefinishcriterion(const int32_t
{
//check dual gap part for mkl

delta=oldalphaterm-curalphaterm;
_delta=oldalphaterm-curalphaterm;

int32_t maxind=0;
float64_t maxval=normweightssquared[maxind];
for (size_t i=0;i< wnew.size();++i)
{
delta+=-0.5*oldnormweightssquared[i]*wold[i];
_delta+=-0.5*oldnormweightssquared[i]*wold[i];
if(normweightssquared[i]>maxval)
{
maxind=i;
maxval=normweightssquared[i];
}
}
delta+=0.5*normweightssquared[maxind];
//delta=fabs(delta);
io::info("L1 Norm chosen, MKL part of duality gap {} ",delta);
if( (delta < mkl_eps) && (numberofsilpiterations>=1) )
_delta+=0.5*normweightssquared[maxind];
//_delta=fabs(_delta);
io::info("L1 Norm chosen, MKL part of duality gap {} ",_delta);
if( (_delta < mkl_eps) && (numberofsilpiterations>=1) )
{
return true;
}
Expand All @@ -172,27 +173,27 @@ bool MKLMulticlass::evaluatefinishcriterion(const int32_t
}
else
{
delta=0;
_delta=0;

float64_t deltaold=oldalphaterm,deltanew=curalphaterm;
for (size_t i=0;i< wnew.size();++i)
{
delta+=(wold[i]-wnew[i])*(wold[i]-wnew[i]);
_delta+=(wold[i]-wnew[i])*(wold[i]-wnew[i]);
deltaold+= -0.5*oldnormweightssquared[i]*wold[i];
deltanew+= -0.5*normweightssquared[i]*wnew[i];
}
if(deltanew>0)
{
delta=1-deltanew/deltaold;
_delta=1-deltanew/deltaold;
}
else
{
io::warn("MKLMulticlass::evaluatefinishcriterion(...): deltanew<=0.Switching back to weight norsm difference as criterion.");
delta=sqrt(delta);
_delta=sqrt(_delta);
}
io::info("weight delta {} ",delta);
io::info("weight delta {} ",_delta);

if( (delta < mkl_eps) && (numberofsilpiterations>=1) )
if( (_delta < mkl_eps) && (numberofsilpiterations>=1) )
{
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/shogun/distributions/DiscreteDistribution.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class DiscreteDistribution : public Distribution
*
* @param alpha_k "belongingness" values of various data points
*/
virtual void update_params_em(const SGVector<float64_t> alpha_k)=0;
virtual float64_t update_params_em(const SGVector<float64_t> alpha_k)=0;
};
}
#endif /* _DISCRETEDISTRIBUTION_H__ */
24 changes: 12 additions & 12 deletions src/shogun/io/fs/NullFileSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,50 +15,50 @@ namespace shogun

~NullFileSystem() override = default;

std::unique_ptr<RandomAccessFile> new_random_access_file(
const std::string& fname) override
std::error_condition new_random_access_file(
const std::string& fname, std::unique_ptr<RandomAccessFile>*) const override
{
throw ShogunNotImplementedException("new_random_access_file unimplemented");
}

std::unique_ptr<WritableFile> new_writable_file(
const std::string& fname) override
std::error_condition new_writable_file(
const std::string& fname, std::unique_ptr<WritableFile>*) const override
{
throw ShogunNotImplementedException("NewWritableFile new_writable_file");
}

std::unique_ptr<WritableFile> new_appendable_file(
const std::string& fname) override
std::error_condition new_appendable_file(
const std::string& fname, std::unique_ptr<WritableFile>*) const override
{
throw ShogunNotImplementedException("new_appendable_file unimplemented");
}

bool file_exists(const std::string& fname) override
std::error_condition file_exists(const std::string& fname) const override
{
throw ShogunNotImplementedException("file_exists unimplemented");
}

void delete_file(const std::string& fname) override
std::error_condition delete_file(const std::string& fname) const override
{
throw ShogunNotImplementedException("delete_file unimplemented");
}

void create_dir(const std::string& dirname) override
std::error_condition create_dir(const std::string& dirname) const override
{
throw ShogunNotImplementedException("create_dir unimplemented");
}

void delete_dir(const std::string& dirname) override
std::error_condition delete_dir(const std::string& dirname) const override
{
throw ShogunNotImplementedException("delete_dir unimplemented");
}

int64_t get_file_size(const std::string& fname) override
int64_t get_file_size(const std::string& fname) const override
{
throw ShogunNotImplementedException("get_file_size unimplemented");
}

void rename_file(const std::string& src, const std::string& target) override
std::error_condition rename_file(const std::string& src, const std::string& target) const override
{
throw ShogunNotImplementedException("rename_file unimplemented");
}
Expand Down
97 changes: 50 additions & 47 deletions src/shogun/io/stream/BufferedOutputStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,64 +11,67 @@

namespace shogun
{
IGNORE_IN_CLASSLIST class BufferedOutputStream : public OutputStream
namespace io
{
public:
/**
* Construct a buffered output stream
*
* @param os
* @param buffer_bytes
*/
BufferedOutputStream(std::shared_ptr<OutputStream> os, index_t buffer_bytes = 4096):
OutputStream(), m_os(std::move(os))
IGNORE_IN_CLASSLIST class BufferedOutputStream : public OutputStream
{
public:
/**
* Construct a buffered output stream
*
* @param os
* @param buffer_bytes
*/
BufferedOutputStream(std::shared_ptr<OutputStream> os, index_t buffer_bytes = 4096):
OutputStream(), m_os(std::move(os))
{

}
}

BufferedOutputStream(BufferedOutputStream&& src):
OutputStream(), m_os(std::move(src.m_os))
{
src.m_os = nullptr;
}
BufferedOutputStream(BufferedOutputStream&& src):
OutputStream(), m_os(std::move(src.m_os))
{
src.m_os = nullptr;
}

BufferedOutputStream& operator=(BufferedOutputStream&& src)
{
m_os = std::move(src.m_os);
return *this;
}
BufferedOutputStream& operator=(BufferedOutputStream&& src)
{
m_os = std::move(src.m_os);
return *this;
}

~BufferedOutputStream() override
{
m_os->flush();
m_os->close();
}
~BufferedOutputStream() override
{
m_os->flush();
m_os->close();
}

std::error_condition write(void* buffer, int64_t size) override
{
m_os->write(buffer, size);
}
std::error_condition write(const void* buffer, int64_t size) override
{
m_os->write(buffer, size);
}

std::error_condition close() override
{
m_os->close();
}
std::error_condition close() override
{
m_os->close();
}

std::error_condition flush() override
{
m_os->flush();
}
std::error_condition flush() override
{
m_os->flush();
}

const char* get_name() const override
{
return "BufferedOutputStream";
}
const char* get_name() const override
{
return "BufferedOutputStream";
}

private:
std::shared_ptr<OutputStream> m_os;
private:
std::shared_ptr<OutputStream> m_os;

SG_DELETE_COPY_AND_ASSIGN(BufferedOutputStream);
};
}
SG_DELETE_COPY_AND_ASSIGN(BufferedOutputStream);
};
} // namespace io
} // namespace shogun

#endif /* __BUFFERED_OUTPUT_STREAM_H__ */
4 changes: 4 additions & 0 deletions src/shogun/lib/external/falconn/ffht/fht_impl.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#ifndef _FHT_IMPL_H
#define _FHT_IMPL_H

#ifdef __AVX__
#include <immintrin.h>
#endif
Expand Down Expand Up @@ -544,3 +547,4 @@ void FHTFloatIterativeLongHelperAVX(float *buffer, int len, int logLen) {
}

#endif
#endif
Loading