Skip to content

Commit ee4b0d6

Browse files
committed
Merge branch 'Development/Robert2024_enable_cuda' of ssh://github.com/tudelft-cda-lab/FlexFringe into Development/MergeEverything
2 parents 775e9cd + e9da955 commit ee4b0d6

19 files changed

Lines changed: 500 additions & 42 deletions

CMakeLists.txt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@ endif()
1818

1919
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR})
2020

21+
2122
option(COMPILE_DOCS "This is settable from the command line" OFF)
2223
option(ENABLE_DATABASE "Set this for the database connector to work" OFF)
2324
option(ENABLE_PYTHON "Set this for python connector to work" OFF)
25+
option(ENABLE_CUDA "Enable CUDA execution for some faster data structures" OFF)
2426

2527
if (ENABLE_DATABASE)
2628
add_definitions(-D__FLEXFRINGE_DATABASE)
@@ -29,6 +31,17 @@ if (ENABLE_PYTHON)
2931
add_definitions(-D__FLEXFRINGE_PYTHON)
3032
endif()
3133

34+
if (ENABLE_CUDA)
35+
include(CheckLanguage)
36+
check_language(CUDA)
37+
if(CMAKE_CUDA_COMPILER)
38+
add_definitions(-D__FLEXFRINGE_CUDA)
39+
enable_language(CUDA)
40+
else()
41+
message(WARNING "Could not find CUDA on system. Proceeding without.")
42+
endif()
43+
endif()
44+
3245
#set(CMAKE_MESSAGE_LOG_LEVEL WARNING)
3346

3447
# Default compiler flags:
@@ -191,6 +204,11 @@ if (ENABLE_DATABASE)
191204
target_link_libraries(flexfringe libpqxx::pqxx)
192205
endif()
193206

207+
if(CMAKE_CUDA_COMPILER)
208+
find_library(CUDART_LIBRARY cudart ${CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES})
209+
target_link_libraries(ActiveLearning ${CUDART_LIBRARY})
210+
endif()
211+
194212

195213
find_package(Threads)
196214
target_link_libraries(flexfringe ${CMAKE_THREAD_LIBS_INIT}) # For pthreads

source/CMakeLists.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ file(WRITE "gitversion.cpp" "const char *gitversion = \"${Gitversion}\";")
2424
## create the evaluators.h file
2525
file(GLOB Files "${CMAKE_CURRENT_SOURCE_DIR}/evaluation/*.h")
2626
file(WRITE "evaluators.h" "#ifndef __ALL_HEADERS__ \n#define __ALL_HEADERS__ \n\n")
27+
2728
foreach (Filepath ${Files})
2829
get_filename_component(Filename ${Filepath} NAME)
2930
file(APPEND "evaluators.h" "#include \"${Filename}\"\n")
@@ -142,7 +143,12 @@ file(APPEND "${cmakelists_eval}" " \"../active_learning/memory/incomplete_infor
142143
file(APPEND "${cmakelists_eval}" " \"../active_learning/system_under_learning\"\n")
143144
file(APPEND "${cmakelists_eval}" " \"../active_learning/system_under_learning/neural_network_suls\"\n")
144145
file(APPEND "${cmakelists_eval}" " \"../active_learning/system_under_learning/benchmark_parsers\"\n")
145-
file(APPEND "${cmakelists_eval}" ")\n\n\n")
146+
file(APPEND "${cmakelists_eval}" ")\n\n")
147+
148+
# the cuda directives
149+
file(APPEND "${cmakelists_eval}" "if(CMAKE_CUDA_COMPILER)\n")
150+
file(APPEND "${cmakelists_eval}" " include_directories(\$\{CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES\})\n")
151+
file(APPEND "${cmakelists_eval}" "endif()\n\n")
146152

147153
# "${CMAKE_CURRENT_SOURCE_DIR}/../active_learning//oracle/cex_search_strategies"
148154
# "${CMAKE_CURRENT_SOURCE_DIR}/../active_learning//oracle/cex_conflict_search"

source/active_learning/CMakeLists.txt

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,14 @@ include_directories(
1515
"${CMAKE_CURRENT_SOURCE_DIR}/system_under_learning/benchmark_parsers"
1616
)
1717

18+
if(CMAKE_CUDA_COMPILER)
19+
include_directories(${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES}
20+
"${CMAKE_CURRENT_SOURCE_DIR}/active_learning_util/cuda"
21+
"${CMAKE_CURRENT_SOURCE_DIR}/memory/distinguishing_sequences/cuda"
22+
)
23+
endif()
1824

19-
add_library(ActiveLearning STATIC
25+
set(ACTIVE_LEARNING_FILES
2026
active_learning_mode.h
2127
active_learning_mode.cpp
2228

@@ -188,9 +194,27 @@ add_library(ActiveLearning STATIC
188194
)
189195

190196

197+
if(CMAKE_CUDA_COMPILER)
198+
set(CUDA_FILES
199+
active_learning_util/cuda/cuda_common.cuh
200+
active_learning_util/cuda/cuda_common.cu
201+
memory/distinguishing_sequences/cuda/distinguishing_sequences_gpu.cuh
202+
memory/distinguishing_sequences/cuda/distinguishing_sequences_gpu.cu
203+
)
204+
205+
set(ACTIVE_LEARNING_FILES
206+
${ACTIVE_LEARNING_FILES}
207+
${CUDA_FILES}
208+
)
209+
210+
set_source_files_properties(${CUDA_FILES} PROPERTIES LANGUAGE CUDA)
211+
endif()
212+
213+
add_library(ActiveLearning STATIC ${ACTIVE_LEARNING_FILES})
214+
191215
if (ENABLE_PYTHON)
192216
target_link_libraries(ActiveLearning ${PYTHON_LIBRARIES})
193217
endif()
194218
if (ENABLE_DATABASE)
195219
target_link_libraries(ActiveLearning libpqxx::pqxx)
196-
endif()
220+
endif()

source/active_learning/active_learning_mode.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ int active_learning_mode::run() {
7777
unique_ptr<algorithm_base> algorithm = algorithm_factory::create_algorithm_obj();
7878
algorithm->run(id);
7979

80+
#ifdef __CUDA
81+
cudaDeviceReset();
82+
#endif
8083
// Hielke: Can we we this one better? For example, we do it in the constructor of the corresponding algorithms
8184
/* LOG_S(INFO) << "Learning (partly) passively. Therefore read in input-data.";
8285
get_inputdata();

source/active_learning/active_learning_util/common_functions.cpp

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -439,15 +439,7 @@ trace* active_learning_namespace::vector_to_trace(const vector<int>& vec, inputd
439439
throw runtime_error("We should not reach here. What happened?");
440440
}*/
441441

442-
/**
443-
* @brief For debugging.
444-
*/
445-
void active_learning_namespace::print_list(const list<int>& l) {
446-
for (const auto s : l) cout << s << " ";
447-
cout << endl;
448-
}
449-
450-
void active_learning_namespace::print_vector(const vector<int>& l) {
442+
void active_learning_namespace::print_span(std::span<const int> l) {
451443
for (const auto s : l) cout << s << " ";
452444
cout << endl;
453445
}

source/active_learning/active_learning_util/common_functions.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
#include <functional>
2626
#include <list>
27+
#include <span>
2728
#include <unordered_map>
2829
#include <utility>
2930

@@ -98,9 +99,7 @@ namespace active_learning_namespace {
9899
std::cout << std::endl;
99100
}
100101

101-
[[maybe_unused]] void print_list(const std::list<int>& l);
102-
103-
void print_vector(const std::vector<int>& l);
102+
void print_span(std::span<const int> l);
104103
} // namespace active_learning_namespace
105104

106105

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* @file cuda_common.cu
3+
* @author Robert Baumgartner (r.baumgartner-1@tudelft.nl)
4+
* @brief
5+
* @version 0.1
6+
* @date 2025-07-13
7+
*
8+
* @copyright Copyright (c) 2025
9+
*
10+
*/
11+
12+
#ifndef __FLEXFRINGE_CUDA
13+
#include<type_traits>
14+
static_assert(std::integral_constant<bool, false>::value, "cuda_common.cu included even though CUDA not enabled in project.");
15+
#endif
16+
17+
#include "cuda_common.cuh"
18+
19+
#include <iostream>
20+
21+
void cuda_common::gpuAssert(cudaError_t code, const char *file, int line, bool abort)
22+
{
23+
if (code != cudaSuccess)
24+
{
25+
//fprintf(stderr,"GPUassert: %s %s %d\n", cudaGetErrorString(code), file, line);
26+
std::cerr << "GPUassert: " << cudaGetErrorString(code) << " " << file << " " << line;
27+
if (abort) exit(code);
28+
}
29+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* @file cuda_common.cuh
3+
* @author Robert Baumgartner (r.baumgartner-1@tudelft.nl)
4+
* @brief
5+
* @version 0.1
6+
* @date 2025-07-12
7+
*
8+
* @copyright Copyright (c) 2025
9+
*
10+
*/
11+
12+
#ifndef __FLEXFRINGE_CUDA
13+
#include<type_traits>
14+
static_assert(std::integral_constant<bool, false>::value, "cuda_common.cuh included even though CUDA not enabled in project.");
15+
#endif
16+
17+
#ifndef __CUDA_COMMON_CUH__
18+
#define __CUDA_COMMON_CUH__
19+
20+
#include "cuda.h"
21+
22+
namespace cuda_common {
23+
void gpuAssert(cudaError_t code, const char *file, int line, bool abort=true);
24+
}
25+
26+
#endif // __CUDA_COMMON_CUH__

source/active_learning/algorithms/paul.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@ void paul_algorithm::update_node_data(apta_node* n, std::unique_ptr<apta>& aut)
4343
ds_handler->complete_node(n, aut);
4444
}
4545

46-
if(n_data->get_predictions().size() != ds_handler->size()){
46+
//if(n->get_depth() >= 10)
47+
// return;
48+
49+
if(n_data->get_n_predictions() != ds_handler->size()){
4750
auto y_pred = ds_handler->predict_node_with_sul_layer_wise(*aut, n);
4851
n_data->set_predictions(std::move(y_pred));
4952
}
@@ -159,7 +162,8 @@ refinement* paul_algorithm::check_blue_node_for_merge_partner(apta_node* const b
159162
// continue;
160163
//}
161164
}
162-
165+
166+
//if(ds_handler->get_score() > 0)
163167
ref->score = ds_handler->get_score(); // score computed in check_consistency() or distributions_consistent()
164168
if(ref->score > 0){
165169
rs.insert(ref);
@@ -375,14 +379,14 @@ list<refinement*> paul_algorithm::find_hypothesis(list<refinement*>& previous_re
375379
} */
376380

377381
//#ifndef NDEBUG
378-
{
382+
/* {
379383
static int c = 0;
380384
merger->print_dot("after_" + to_string(c++) + ".dot");
381385
382386
if(c%10==0){
383387
output_manager::print_current_automaton(merger.get(), "model.", to_string(c) + ".intermediate");
384388
}
385-
}
389+
} */
386390

387391
//#endif
388392

0 commit comments

Comments
 (0)