This would allow users to find out what builtin is. (#1227)
* This would allow users to find out what builtin is. * Trying another approach. * Added instructions. * Cleaning up the printout. * Let us be less invasive. * Adding a comment.
This commit is contained in:
parent
e4897d6b54
commit
07a6e098c8
|
@ -12,7 +12,6 @@ using namespace simdjson::builtin;
|
||||||
class OnDemand {
|
class OnDemand {
|
||||||
public:
|
public:
|
||||||
simdjson_really_inline bool Run(const padded_string &json);
|
simdjson_really_inline bool Run(const padded_string &json);
|
||||||
|
|
||||||
simdjson_really_inline const std::vector<my_point> &Result() { return container; }
|
simdjson_really_inline const std::vector<my_point> &Result() { return container; }
|
||||||
simdjson_really_inline size_t ItemCount() { return container.size(); }
|
simdjson_really_inline size_t ItemCount() { return container.size(); }
|
||||||
|
|
||||||
|
@ -43,7 +42,6 @@ namespace sum {
|
||||||
class OnDemand {
|
class OnDemand {
|
||||||
public:
|
public:
|
||||||
simdjson_really_inline bool Run(const padded_string &json);
|
simdjson_really_inline bool Run(const padded_string &json);
|
||||||
|
|
||||||
simdjson_really_inline my_point &Result() { return sum; }
|
simdjson_really_inline my_point &Result() { return sum; }
|
||||||
simdjson_really_inline size_t ItemCount() { return count; }
|
simdjson_really_inline size_t ItemCount() { return count; }
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,6 @@ using namespace simdjson::builtin;
|
||||||
class OnDemand {
|
class OnDemand {
|
||||||
public:
|
public:
|
||||||
simdjson_really_inline bool Run(const padded_string &json);
|
simdjson_really_inline bool Run(const padded_string &json);
|
||||||
|
|
||||||
simdjson_really_inline const std::vector<my_point> &Result() { return container; }
|
simdjson_really_inline const std::vector<my_point> &Result() { return container; }
|
||||||
simdjson_really_inline size_t ItemCount() { return container.size(); }
|
simdjson_really_inline size_t ItemCount() { return container.size(); }
|
||||||
|
|
||||||
|
@ -40,7 +39,6 @@ namespace sum {
|
||||||
class OnDemand {
|
class OnDemand {
|
||||||
public:
|
public:
|
||||||
simdjson_really_inline bool Run(const padded_string &json);
|
simdjson_really_inline bool Run(const padded_string &json);
|
||||||
|
|
||||||
simdjson_really_inline my_point &Result() { return sum; }
|
simdjson_really_inline my_point &Result() { return sum; }
|
||||||
simdjson_really_inline size_t ItemCount() { return count; }
|
simdjson_really_inline size_t ItemCount() { return count; }
|
||||||
|
|
||||||
|
|
|
@ -9,10 +9,16 @@ namespace partial_tweets {
|
||||||
using namespace simdjson;
|
using namespace simdjson;
|
||||||
using namespace simdjson::builtin;
|
using namespace simdjson::builtin;
|
||||||
|
|
||||||
|
|
||||||
class OnDemand {
|
class OnDemand {
|
||||||
public:
|
public:
|
||||||
|
OnDemand() {
|
||||||
|
if(!displayed_implementation) {
|
||||||
|
std::cout << "On Demand implementation: " << builtin_implementation()->name() << std::endl;
|
||||||
|
displayed_implementation = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
simdjson_really_inline bool Run(const padded_string &json);
|
simdjson_really_inline bool Run(const padded_string &json);
|
||||||
|
|
||||||
simdjson_really_inline const std::vector<tweet> &Result() { return tweets; }
|
simdjson_really_inline const std::vector<tweet> &Result() { return tweets; }
|
||||||
simdjson_really_inline size_t ItemCount() { return tweets.size(); }
|
simdjson_really_inline size_t ItemCount() { return tweets.size(); }
|
||||||
|
|
||||||
|
@ -30,6 +36,7 @@ private:
|
||||||
ondemand::object u = std::move(user);
|
ondemand::object u = std::move(user);
|
||||||
return { u["id"], u["screen_name"] };
|
return { u["id"], u["screen_name"] };
|
||||||
}
|
}
|
||||||
|
static inline bool displayed_implementation = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
simdjson_really_inline bool OnDemand::Run(const padded_string &json) {
|
simdjson_really_inline bool OnDemand::Run(const padded_string &json) {
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 12e496da3d486b87fa9df43edea65232ed852510
|
Subproject commit 794c975287355de48158d9a80ed502d26b20a472
|
|
@ -509,3 +509,21 @@ Good applications for the On Demand API might be:
|
||||||
* You have a closed system on predetermined hardware. Both the generation and the consumption of JSON data is within your system. Your team controls both the software that produces the JSON and the software the parses it, your team knows and control the hardware. Thus you can fully test your system.
|
* You have a closed system on predetermined hardware. Both the generation and the consumption of JSON data is within your system. Your team controls both the software that produces the JSON and the software the parses it, your team knows and control the hardware. Thus you can fully test your system.
|
||||||
* You are working with stable JSON APIs which have a consistent layout and JSON dialect.
|
* You are working with stable JSON APIs which have a consistent layout and JSON dialect.
|
||||||
|
|
||||||
|
## Checking Your CPU Selection
|
||||||
|
|
||||||
|
Given that the On Demand API does not offer runtime dispatching, your code is compiled against a specific CPU target. You should
|
||||||
|
verify that the code is compiled against the target you expect: `haswell` (AVX2 x64 processors), `westmere` (SSE4 x64 processors), `arm64` (64-bit ARM), `fallback` (others). Under x64 processors, many programmers will want to target `haswell` whereas under ARM,
|
||||||
|
most programmers will want to target `arm64`. The `fallback` is probably only good for testing purposes, not for deployment.
|
||||||
|
|
||||||
|
```C++
|
||||||
|
std::cout << simdjson::builtin_implementation()->name() << std::endl;
|
||||||
|
```
|
||||||
|
|
||||||
|
If you are using CMake for your C++ project, then you can pass compilation flags to your compiler during the first configuration
|
||||||
|
by using the `CXXFLAGS` configuration variable:
|
||||||
|
```
|
||||||
|
CXXFLAGS=-march=haswell cmake -B build_haswell
|
||||||
|
cmake --build build_haswell
|
||||||
|
```
|
||||||
|
|
||||||
|
You may also use the `CMAKE_CXX_FLAGS` variable.
|
|
@ -29,6 +29,13 @@ namespace simdjson {
|
||||||
* code that uses it) will use westmere.
|
* code that uses it) will use westmere.
|
||||||
*/
|
*/
|
||||||
namespace builtin = SIMDJSON_BUILTIN_IMPLEMENTATION;
|
namespace builtin = SIMDJSON_BUILTIN_IMPLEMENTATION;
|
||||||
|
/**
|
||||||
|
* Function which returns a pointer to an implementation matching the "builtin" implementation.
|
||||||
|
* The builtin implementation is the best statically linked simdjson implementation that can be used by the compiling
|
||||||
|
* program. If you compile with g++ -march=haswell, this will return the haswell implementation.
|
||||||
|
* It is handy to be able to check what builtin was used: builtin_implementation()->name().
|
||||||
|
*/
|
||||||
|
const implementation * builtin_implementation();
|
||||||
} // namespace simdjson
|
} // namespace simdjson
|
||||||
|
|
||||||
#endif // SIMDJSON_BUILTIN_H
|
#endif // SIMDJSON_BUILTIN_H
|
||||||
|
|
|
@ -147,5 +147,10 @@ simdjson_warn_unused bool validate_utf8(const char *buf, size_t len) noexcept {
|
||||||
return active_implementation->validate_utf8(buf, len);
|
return active_implementation->validate_utf8(buf, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const implementation * builtin_implementation() {
|
||||||
|
static const implementation * builtin_impl = available_implementations[STRINGIFY(SIMDJSON_BUILTIN_IMPLEMENTATION)];
|
||||||
|
return builtin_impl;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace simdjson
|
} // namespace simdjson
|
||||||
|
|
|
@ -1337,8 +1337,11 @@ int main(int argc, char *argv[]) {
|
||||||
printf("unsupported CPU\n");
|
printf("unsupported CPU\n");
|
||||||
}
|
}
|
||||||
// We want to know what we are testing.
|
// We want to know what we are testing.
|
||||||
std::cout << "Running tests against this implementation: " << simdjson::active_implementation->name();
|
// Next line would be the runtime dispatched implementation but that's not necessarily what gets tested.
|
||||||
std::cout << "(" << simdjson::active_implementation->description() << ")" << std::endl;
|
// std::cout << "Running tests against this implementation: " << simdjson::active_implementation->name();
|
||||||
|
// Rather, we want to display builtin_implementation()->name().
|
||||||
|
// In practice, by default, we often end up testing against fallback.
|
||||||
|
std::cout << "builtin_implementation -- " << builtin_implementation()->name() << std::endl;
|
||||||
std::cout << "------------------------------------------------------------" << std::endl;
|
std::cout << "------------------------------------------------------------" << std::endl;
|
||||||
|
|
||||||
std::cout << "Running basic tests." << std::endl;
|
std::cout << "Running basic tests." << std::endl;
|
||||||
|
|
Loading…
Reference in New Issue