Moved DEBUG option to config files
This commit is contained in:
@ -6,28 +6,35 @@ namespace fs = std::filesystem;
|
||||
//#include "config.hpp"
|
||||
|
||||
template <typename T>
|
||||
void unit_test_cpu_vs_gpu(const np::Array<T>& cpu, const np::Array<T>& gpu) noexcept {
|
||||
bool unit_test_cpu_vs_gpu(const np::Array<T>& cpu, const np::Array<T>& gpu) noexcept {
|
||||
if (cpu.shape != gpu.shape) {
|
||||
#if __DEBUG
|
||||
fprintf(stderr, "Inequal shape !\n");
|
||||
return;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
size_t eq = 0;
|
||||
const size_t length = np::prod(cpu.shape);
|
||||
for (size_t i = 0; i < length; ++i)
|
||||
if (cpu[i] == gpu[i])
|
||||
++eq;
|
||||
//else
|
||||
// std::cout << i << ": " << cpu[i] << " != " << gpu[i] << std::endl;
|
||||
|
||||
#if __DEBUG
|
||||
if (eq != length)
|
||||
printf("Incorrect results, Number of equalities : %s/%s <=> %.2f%% !\n", thousand_sep(eq).c_str(), thousand_sep(length).c_str(),
|
||||
static_cast<float64_t>(eq) / static_cast<float64_t>(length) * 100.0);
|
||||
#endif
|
||||
|
||||
return eq == length;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void unit_test_argsort_2d(const np::Array<T>& a, const np::Array<uint16_t>& indices) noexcept {
|
||||
bool unit_test_argsort_2d(const np::Array<T>& a, const np::Array<uint16_t>& indices) noexcept {
|
||||
if (a.shape != indices.shape) {
|
||||
#if __DEBUG
|
||||
fprintf(stderr, "Inequal shape !\n");
|
||||
return;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
size_t correct = a.shape[0]; // First elements are always correctly sorted
|
||||
const size_t total = np::prod(a.shape);
|
||||
@ -37,34 +44,37 @@ void unit_test_argsort_2d(const np::Array<T>& a, const np::Array<uint16_t>& indi
|
||||
if(a[i + indices[k]] <= a[i + indices[k + 1]])
|
||||
++correct;
|
||||
}
|
||||
#if __DEBUG
|
||||
if (correct != total)
|
||||
printf("Incorrect results, Number of equalities : %s/%s <=> %.2f%% !\n", thousand_sep(correct).c_str(), thousand_sep(total).c_str(),
|
||||
static_cast<float64_t>(correct) / static_cast<float64_t>(total) * 100.0);
|
||||
#endif
|
||||
return correct == total;
|
||||
}
|
||||
|
||||
template <typename T, typename F, typename... Args>
|
||||
T benchmark_function(const char* step_name, const F& fnc, Args &&...args) noexcept {
|
||||
#ifndef __DEBUG
|
||||
#if __DEBUG == false
|
||||
printf("%s...\r", step_name);
|
||||
fflush(stdout); // manual flush is mandatory, otherwise it will not be shown immediately because the output is buffered
|
||||
#endif
|
||||
const auto start = time();
|
||||
const T res = fnc(std::forward<Args>(args)...);
|
||||
const long long timespent = duration_ns(time() - start);
|
||||
printf("| %-49s | %17s | %-29s |\n", step_name, thousand_sep(timespent).c_str(), format_time_ns(timespent).c_str());
|
||||
printf("| %-49s | %18s | %-29s |\n", step_name, thousand_sep(timespent).c_str(), format_time_ns(timespent).c_str());
|
||||
return res;
|
||||
}
|
||||
|
||||
template <typename F, typename... Args>
|
||||
void benchmark_function_void(const char* step_name, const F& fnc, Args &&...args) noexcept {
|
||||
#ifndef __DEBUG
|
||||
#if __DEBUG == false
|
||||
printf("%s...\r", step_name);
|
||||
fflush(stdout); // manual flush is mandatory, otherwise it will not be shown immediately because the output is buffered
|
||||
#endif
|
||||
const auto start = time();
|
||||
fnc(std::forward<Args>(args)...);
|
||||
const long long timespent = duration_ns(time() - start);
|
||||
printf("| %-49s | %17s | %-29s |\n", step_name, thousand_sep(timespent).c_str(), format_time_ns(timespent).c_str());
|
||||
printf("| %-49s | %18s | %-29s |\n", step_name, thousand_sep(timespent).c_str(), format_time_ns(timespent).c_str());
|
||||
}
|
||||
|
||||
template <typename T, typename F, typename... Args>
|
||||
@ -76,23 +86,23 @@ np::Array<T> state_saver(const char* step_name, const char* filename, const bool
|
||||
if (!fs::exists(filepath) || force_redo) {
|
||||
bin = std::move(benchmark_function<np::Array<T>>(step_name, fnc, std::forward<Args>(args)...));
|
||||
if(save_state){
|
||||
#ifndef __DEBUG
|
||||
#if __DEBUG == false
|
||||
printf("Saving results of %s\r", step_name);
|
||||
fflush(stdout);
|
||||
#endif
|
||||
save<T>(bin, filepath);
|
||||
#ifndef __DEBUG
|
||||
#if __DEBUG == false
|
||||
printf("%*c\r", 100, ' ');
|
||||
fflush(stdout);
|
||||
#endif
|
||||
}
|
||||
} else {
|
||||
#ifndef __DEBUG
|
||||
#if __DEBUG == false
|
||||
printf("Loading results of %s\r", step_name);
|
||||
fflush(stdout);
|
||||
#endif
|
||||
bin = std::move(load<T>(filepath));
|
||||
printf("| %-49s | %17s | %-29s |\n", step_name, "None", "loaded saved state");
|
||||
printf("| %-49s | %18s | %-29s |\n", step_name, "None", "loaded saved state");
|
||||
}
|
||||
return bin;
|
||||
}
|
||||
@ -113,7 +123,7 @@ std::array<np::Array<T>, N> state_saver(const char* step_name, const std::vector
|
||||
if (abs || force_redo) {
|
||||
bin = std::move(benchmark_function<std::array<np::Array<T>, N>>(step_name, fnc, std::forward<Args>(args)...));
|
||||
if (save_state){
|
||||
#ifndef __DEBUG
|
||||
#if __DEBUG == false
|
||||
printf("Saving results of %s\r", step_name);
|
||||
fflush(stdout);
|
||||
#endif
|
||||
@ -122,13 +132,13 @@ std::array<np::Array<T>, N> state_saver(const char* step_name, const std::vector
|
||||
sprintf(filepath, "%s/%s.bin", out_dir, filename);
|
||||
save<T>(bin[i++], filepath);
|
||||
}
|
||||
#ifndef __DEBUG
|
||||
#if __DEBUG == false
|
||||
printf("%*c\r", 100, ' ');
|
||||
fflush(stdout);
|
||||
#endif
|
||||
}
|
||||
} else {
|
||||
#ifndef __DEBUG
|
||||
#if __DEBUG == false
|
||||
printf("Loading results of %s\r", step_name);
|
||||
fflush(stdout);
|
||||
#endif
|
||||
@ -137,7 +147,7 @@ std::array<np::Array<T>, N> state_saver(const char* step_name, const std::vector
|
||||
sprintf(filepath, "%s/%s.bin", out_dir, filename);
|
||||
bin[i++] = std::move(load<T>(filepath));
|
||||
}
|
||||
printf("| %-49s | %17s | %-29s |\n", step_name, "None", "loaded saved state");
|
||||
printf("| %-49s | %18s | %-29s |\n", step_name, "None", "loaded saved state");
|
||||
}
|
||||
return bin;
|
||||
}
|
||||
|
Reference in New Issue
Block a user