clad icon indicating copy to clipboard operation
clad copied to clipboard

Make clad headers work with Google Benchmark

Open vgvassilev opened this issue 2 years ago • 4 comments

When clad visits the google benchmark headers we get tons of errors. For example:

diff --git a/benchmark/Simple.cpp b/benchmark/Simple.cpp
index 5787d2b..30b1475 100644
--- a/benchmark/Simple.cpp
+++ b/benchmark/Simple.cpp
@@ -1,8 +1,9 @@
-#include "benchmark/benchmark.h"
 
 // FIXME: If we move this before benchmark.h we have tons of errors due to a bug
 #include "clad/Differentiator/Differentiator.h"
 
+#include "benchmark/benchmark.h"
+
 #include "BenchmarkedFunctions.h"
 
 // Benchmark calling via CladFunction::execute

shows

In file included from /home/vvassilev/workspace/sources/clad/benchmark/Simple.cpp:5:
In file included from /home/vvassilev/workspace/builds/clad/googlebenchmark-prefix/src/googlebenchmark/include/benchmark/benchmark.h:183:
In file included from /usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/map:61:
/usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/stl_map.h:519:44: error: member access into incomplete type 'std::pair<const std::basic_string<char>, benchmark::Counter>'
        if (__i == end() || key_comp()(__k, (*__i).first))
                                                  ^
/home/vvassilev/workspace/builds/clad/googlebenchmark-prefix/src/googlebenchmark/include/benchmark/benchmark.h:602:13: note: in instantiation of member function 'std::map<std::basic_string<char>, benchmark::Counter>::operator[]' requested here
    counters["bytes_per_second"] =
            ^
/usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/type_traits:1093:26: note: in instantiation of function template specialization 'std::__is_complete_or_unbounded<const std::basic_string<char>, 32UL>' requested here
      static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
                         ^
/usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/type_traits:139:26: note: in instantiation of template class 'std::is_copy_assignable<const std::basic_string<char>>' requested here
    : public conditional<_B1::value, _B2, _B1>::type
                         ^
/usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/stl_pair.h:391:3: note: in instantiation of template class 'std::__and_<std::is_copy_assignable<const std::basic_string

...

I believe we try to transform code from there and we should not have.

vgvassilev avatar Oct 31 '21 23:10 vgvassilev

The issue seems to hide in Tape.h. For example,

#include "clad/Differentiator/Tape.h"
 
#include "benchmark/benchmark.h"

vgvassilev avatar Nov 19 '21 18:11 vgvassilev

I think this error was resolved prior to #398 . I tried with the following code snippet and it throws no error for me:

#include "clad/Differentiator/Differentiator.h" 
#include "benchmark/benchmark.h"

int main() {return 0;}

This example was tried with that version of clad prior to #398. I used the latest available stable release of Benchmark to compile the above example.

I also tried the same with benchmark/Simple.cpp but received no error on including differentiator.h before benchmark.h

Nirhar avatar Mar 23 '22 04:03 Nirhar

Can you build clad with -DCLAD_ENABLE_BENCHMARKS=On and verify against it?

vgvassilev avatar Mar 23 '22 16:03 vgvassilev

I verified with clad version prior to #398 with -DCLAD_ENABLE_BENCHMARKS=On during building and still both Simple.cpp and the example given above compiles without any error.

Nirhar avatar Mar 23 '22 17:03 Nirhar

The issue seems resolved.

vgvassilev avatar Jan 02 '24 17:01 vgvassilev