Skip to content

Commit 28b7118

Browse files
committed
add cmake support for precompiled headers
1 parent 062d70c commit 28b7118

File tree

9 files changed

+140
-95
lines changed

9 files changed

+140
-95
lines changed

.ci/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ jobs:
128128
ccacheDir: '$(build.binariesDirectory)/ccache'
129129
ccacheArtifactName: 'ccache-macos'
130130
ccacheArchive: '$(Build.ArtifactStagingDirectory)/ccache-$(Build.BuildId).tar'
131-
commonMacOSCMakeFlags: '-DBUILD_EXAMPLES=OFF -DBUNDLE_JSON=OFF -DBUNDLE_NLOPT=OFF -DENABLE_TESTING=ON -DENABLE_COVERAGE=OFF -DBUILD_META_EXAMPLES=OFF'
131+
commonMacOSCMakeFlags: '-DBUILD_EXAMPLES=OFF -DBUNDLE_NLOPT=OFF -DENABLE_TESTING=ON -DENABLE_COVERAGE=OFF -DBUILD_META_EXAMPLES=OFF'
132132
openMPMacOSCMakeFlags:
133133
'-DOpenMP_CXX_FLAGS="-Xpreprocessor -fopenmp"
134134
-DOpenMP_C_FLAGS="-Xpreprocessor -fopenmp"

cmake/FindCCache.cmake

+1-5
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,7 @@ endif()
1212

1313
# handle REQUIRED and QUIET options
1414
include(FindPackageHandleStandardArgs)
15-
if (CMAKE_VERSION LESS 2.8.3)
16-
find_package_handle_standard_args(CCache DEFAULT_MSG CCACHE CCACHE_VERSION)
17-
else ()
18-
find_package_handle_standard_args(CCache REQUIRED_VARS CCACHE CCACHE_VERSION)
19-
endif ()
15+
find_package_handle_standard_args(CCache REQUIRED_VARS CCACHE CCACHE_VERSION)
2016

2117
if (CCACHE_FOUND)
2218
if(${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")

src/shogun/CMakeLists.txt

+44
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,50 @@ IF(MSVC)
178178
target_link_libraries(shogun_deps INTERFACE winmm Shlwapi)
179179
ENDIF()
180180

181+
########################### PCH
182+
if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.16.0)
183+
if (CCACHE_FOUND)
184+
if (DEFINED ENV{CCACHE_SLOPPINESS})
185+
if (NOT "$ENV{CCACHE_SLOPPINESS}" MATCHES "pch_defines" OR
186+
NOT "$ENV{CCACHE_SLOPPINESS}" MATCHES "time_macros")
187+
MESSAGE (WARNING
188+
"ccache requires the environment variable CCACHE_SLOPPINESS to be set to \"pch_defines,time_macros\"."
189+
)
190+
SET(CCACHE_PCH_READY 0)
191+
else()
192+
SET(CCACHE_PCH_READY 1)
193+
endif()
194+
else()
195+
execute_process(
196+
COMMAND "${COMPILER_CACHE_EXECUTABLE}" "-p"
197+
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
198+
RESULT_VARIABLE _result
199+
OUTPUT_VARIABLE _ccacheConfig OUTPUT_STRIP_TRAILING_WHITESPACE
200+
ERROR_QUIET)
201+
if (_result)
202+
MESSAGE (WARNING "ccache configuration cannot be determined.")
203+
SET(CCACHE_PCH_READY 0)
204+
elseif (NOT _ccacheConfig MATCHES "sloppiness.*=.*time_macros" OR
205+
NOT _ccacheConfig MATCHES "sloppiness.*=.*pch_defines")
206+
MESSAGE (WARNING
207+
"ccache requires configuration setting \"sloppiness\" to be set to \"pch_defines,time_macros\"."
208+
)
209+
SET(CCACHE_PCH_READY 0)
210+
else()
211+
SET(CCACHE_PCH_READY 1)
212+
endif()
213+
endif()
214+
215+
endif()
216+
217+
if (NOT CCACHE_FOUND OR ${CCACHE_PCH_READY})
218+
# FIXME: make sure all the headers are listed that could be precompiled
219+
target_precompile_headers(libshogun
220+
PUBLIC "$<$<COMPILE_LANGUAGE:CXX>:${LIBSHOGUN_HEADERS}>")
221+
endif()
222+
endif()
223+
224+
181225
########################### compiler capabilities
182226
FIND_PACKAGE(Threads)
183227
IF (CMAKE_USE_PTHREADS_INIT)

src/shogun/distributions/DiscreteDistribution.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ class DiscreteDistribution : public Distribution
9797
*
9898
* @param alpha_k "belongingness" values of various data points
9999
*/
100-
virtual void update_params_em(const SGVector<float64_t> alpha_k)=0;
100+
virtual float64_t update_params_em(const SGVector<float64_t> alpha_k)=0;
101101
};
102102
}
103103
#endif /* _DISCRETEDISTRIBUTION_H__ */

src/shogun/io/fs/NullFileSystem.h

+12-12
Original file line numberDiff line numberDiff line change
@@ -15,50 +15,50 @@ namespace shogun
1515

1616
~NullFileSystem() override = default;
1717

18-
std::unique_ptr<RandomAccessFile> new_random_access_file(
19-
const std::string& fname) override
18+
std::error_condition new_random_access_file(
19+
const std::string& fname, std::unique_ptr<RandomAccessFile>*) const override
2020
{
2121
throw ShogunNotImplementedException("new_random_access_file unimplemented");
2222
}
2323

24-
std::unique_ptr<WritableFile> new_writable_file(
25-
const std::string& fname) override
24+
std::error_condition new_writable_file(
25+
const std::string& fname, std::unique_ptr<WritableFile>*) const override
2626
{
2727
throw ShogunNotImplementedException("NewWritableFile new_writable_file");
2828
}
2929

30-
std::unique_ptr<WritableFile> new_appendable_file(
31-
const std::string& fname) override
30+
std::error_condition new_appendable_file(
31+
const std::string& fname, std::unique_ptr<WritableFile>*) const override
3232
{
3333
throw ShogunNotImplementedException("new_appendable_file unimplemented");
3434
}
3535

36-
bool file_exists(const std::string& fname) override
36+
std::error_condition file_exists(const std::string& fname) const override
3737
{
3838
throw ShogunNotImplementedException("file_exists unimplemented");
3939
}
4040

41-
void delete_file(const std::string& fname) override
41+
std::error_condition delete_file(const std::string& fname) const override
4242
{
4343
throw ShogunNotImplementedException("delete_file unimplemented");
4444
}
4545

46-
void create_dir(const std::string& dirname) override
46+
std::error_condition create_dir(const std::string& dirname) const override
4747
{
4848
throw ShogunNotImplementedException("create_dir unimplemented");
4949
}
5050

51-
void delete_dir(const std::string& dirname) override
51+
std::error_condition delete_dir(const std::string& dirname) const override
5252
{
5353
throw ShogunNotImplementedException("delete_dir unimplemented");
5454
}
5555

56-
int64_t get_file_size(const std::string& fname) override
56+
int64_t get_file_size(const std::string& fname) const override
5757
{
5858
throw ShogunNotImplementedException("get_file_size unimplemented");
5959
}
6060

61-
void rename_file(const std::string& src, const std::string& target) override
61+
std::error_condition rename_file(const std::string& src, const std::string& target) const override
6262
{
6363
throw ShogunNotImplementedException("rename_file unimplemented");
6464
}

src/shogun/io/stream/BufferedOutputStream.h

+50-47
Original file line numberDiff line numberDiff line change
@@ -11,64 +11,67 @@
1111

1212
namespace shogun
1313
{
14-
IGNORE_IN_CLASSLIST class BufferedOutputStream : public OutputStream
14+
namespace io
1515
{
16-
public:
17-
/**
18-
* Construct a buffered output stream
19-
*
20-
* @param os
21-
* @param buffer_bytes
22-
*/
23-
BufferedOutputStream(std::shared_ptr<OutputStream> os, index_t buffer_bytes = 4096):
24-
OutputStream(), m_os(std::move(os))
16+
IGNORE_IN_CLASSLIST class BufferedOutputStream : public OutputStream
2517
{
18+
public:
19+
/**
20+
* Construct a buffered output stream
21+
*
22+
* @param os
23+
* @param buffer_bytes
24+
*/
25+
BufferedOutputStream(std::shared_ptr<OutputStream> os, index_t buffer_bytes = 4096):
26+
OutputStream(), m_os(std::move(os))
27+
{
2628

27-
}
29+
}
2830

29-
BufferedOutputStream(BufferedOutputStream&& src):
30-
OutputStream(), m_os(std::move(src.m_os))
31-
{
32-
src.m_os = nullptr;
33-
}
31+
BufferedOutputStream(BufferedOutputStream&& src):
32+
OutputStream(), m_os(std::move(src.m_os))
33+
{
34+
src.m_os = nullptr;
35+
}
3436

35-
BufferedOutputStream& operator=(BufferedOutputStream&& src)
36-
{
37-
m_os = std::move(src.m_os);
38-
return *this;
39-
}
37+
BufferedOutputStream& operator=(BufferedOutputStream&& src)
38+
{
39+
m_os = std::move(src.m_os);
40+
return *this;
41+
}
4042

41-
~BufferedOutputStream() override
42-
{
43-
m_os->flush();
44-
m_os->close();
45-
}
43+
~BufferedOutputStream() override
44+
{
45+
m_os->flush();
46+
m_os->close();
47+
}
4648

47-
std::error_condition write(void* buffer, int64_t size) override
48-
{
49-
m_os->write(buffer, size);
50-
}
49+
std::error_condition write(const void* buffer, int64_t size) override
50+
{
51+
m_os->write(buffer, size);
52+
}
5153

52-
std::error_condition close() override
53-
{
54-
m_os->close();
55-
}
54+
std::error_condition close() override
55+
{
56+
m_os->close();
57+
}
5658

57-
std::error_condition flush() override
58-
{
59-
m_os->flush();
60-
}
59+
std::error_condition flush() override
60+
{
61+
m_os->flush();
62+
}
6163

62-
const char* get_name() const override
63-
{
64-
return "BufferedOutputStream";
65-
}
64+
const char* get_name() const override
65+
{
66+
return "BufferedOutputStream";
67+
}
6668

67-
private:
68-
std::shared_ptr<OutputStream> m_os;
69+
private:
70+
std::shared_ptr<OutputStream> m_os;
6971

70-
SG_DELETE_COPY_AND_ASSIGN(BufferedOutputStream);
71-
};
72-
}
72+
SG_DELETE_COPY_AND_ASSIGN(BufferedOutputStream);
73+
};
74+
} // namespace io
75+
} // namespace shogun
7376

7477
#endif /* __BUFFERED_OUTPUT_STREAM_H__ */

src/shogun/lib/external/falconn/ffht/fht_impl.h

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#ifndef _FHT_IMPL_H
2+
#define _FHT_IMPL_H
3+
14
#ifdef __AVX__
25
#include <immintrin.h>
36
#endif
@@ -544,3 +547,4 @@ void FHTFloatIterativeLongHelperAVX(float *buffer, int len, int logLen) {
544547
}
545548

546549
#endif
550+
#endif

0 commit comments

Comments
 (0)