mirror of
https://github.com/VectorCamp/vectorscan.git
synced 2025-06-28 16:41:01 +03:00
hsbench: add stream compress functionality
This commit is contained in:
parent
952f0aad21
commit
5f6291529f
@ -40,5 +40,6 @@ extern std::string serializePath;
|
|||||||
extern unsigned int somPrecisionMode;
|
extern unsigned int somPrecisionMode;
|
||||||
extern bool forceEditDistance;
|
extern bool forceEditDistance;
|
||||||
extern unsigned editDistance;
|
extern unsigned editDistance;
|
||||||
|
extern bool printCompressSize;
|
||||||
|
|
||||||
#endif // COMMON_H
|
#endif // COMMON_H
|
||||||
|
@ -205,6 +205,35 @@ void EngineHyperscan::streamScan(EngineStream &stream, const char *data,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EngineHyperscan::streamCompressExpand(EngineStream &stream,
|
||||||
|
vector<char> &temp) const {
|
||||||
|
size_t used = 0;
|
||||||
|
hs_error_t err = hs_compress_stream(stream.id, temp.data(), temp.size(),
|
||||||
|
&used);
|
||||||
|
if (err == HS_INSUFFICIENT_SPACE) {
|
||||||
|
temp.resize(used);
|
||||||
|
err = hs_compress_stream(stream.id, temp.data(), temp.size(), &used);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (err != HS_SUCCESS) {
|
||||||
|
printf("Fatal error: hs_compress_stream returned error %d\n", err);
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (printCompressSize) {
|
||||||
|
printf("stream %u: compressed to %zu\n", stream.sn, used);
|
||||||
|
}
|
||||||
|
|
||||||
|
err = hs_reset_and_expand_stream(stream.id, temp.data(), temp.size(),
|
||||||
|
nullptr, nullptr, nullptr);
|
||||||
|
|
||||||
|
if (err != HS_SUCCESS) {
|
||||||
|
printf("Fatal error: hs_reset_and expand_stream returned error %d\n",
|
||||||
|
err);
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
unsigned makeModeFlags(ScanMode scan_mode) {
|
unsigned makeModeFlags(ScanMode scan_mode) {
|
||||||
switch (scan_mode) {
|
switch (scan_mode) {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2016, Intel Corporation
|
* Copyright (c) 2016-2017, Intel Corporation
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions are met:
|
* modification, are permitted provided that the following conditions are met:
|
||||||
@ -34,6 +34,7 @@
|
|||||||
#include "hs_runtime.h"
|
#include "hs_runtime.h"
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
/** Structure for the result of a single complete scan. */
|
/** Structure for the result of a single complete scan. */
|
||||||
struct ResultEntry {
|
struct ResultEntry {
|
||||||
@ -79,6 +80,9 @@ public:
|
|||||||
void streamClose(std::unique_ptr<EngineStream> stream,
|
void streamClose(std::unique_ptr<EngineStream> stream,
|
||||||
ResultEntry &result) const;
|
ResultEntry &result) const;
|
||||||
|
|
||||||
|
void streamCompressExpand(EngineStream &stream,
|
||||||
|
std::vector<char> &temp) const;
|
||||||
|
|
||||||
void streamScan(EngineStream &stream, const char *data, unsigned int len,
|
void streamScan(EngineStream &stream, const char *data, unsigned int len,
|
||||||
unsigned int id, ResultEntry &result) const;
|
unsigned int id, ResultEntry &result) const;
|
||||||
|
|
||||||
|
@ -77,10 +77,13 @@ string serializePath("");
|
|||||||
unsigned int somPrecisionMode = HS_MODE_SOM_HORIZON_LARGE;
|
unsigned int somPrecisionMode = HS_MODE_SOM_HORIZON_LARGE;
|
||||||
bool forceEditDistance = false;
|
bool forceEditDistance = false;
|
||||||
unsigned editDistance = 0;
|
unsigned editDistance = 0;
|
||||||
|
bool printCompressSize = false;
|
||||||
|
|
||||||
|
// Globals local to this file.
|
||||||
|
static bool compressStream = false;
|
||||||
|
|
||||||
namespace /* anonymous */ {
|
namespace /* anonymous */ {
|
||||||
|
|
||||||
// Globals local to this file.
|
|
||||||
bool display_per_scan = false;
|
bool display_per_scan = false;
|
||||||
ScanMode scan_mode = ScanMode::STREAMING;
|
ScanMode scan_mode = ScanMode::STREAMING;
|
||||||
unsigned repeats = 20;
|
unsigned repeats = 20;
|
||||||
@ -212,11 +215,15 @@ void processArgs(int argc, char *argv[], vector<BenchmarkSigs> &sigSets,
|
|||||||
int in_sigfile = 0;
|
int in_sigfile = 0;
|
||||||
int do_per_scan = 0;
|
int do_per_scan = 0;
|
||||||
int do_echo_matches = 0;
|
int do_echo_matches = 0;
|
||||||
|
int do_compress = 0;
|
||||||
|
int do_compress_size = 0;
|
||||||
vector<string> sigFiles;
|
vector<string> sigFiles;
|
||||||
|
|
||||||
static struct option longopts[] = {
|
static struct option longopts[] = {
|
||||||
{"per-scan", 0, &do_per_scan, 1},
|
{"per-scan", 0, &do_per_scan, 1},
|
||||||
{"echo-matches", 0, &do_echo_matches, 1},
|
{"echo-matches", 0, &do_echo_matches, 1},
|
||||||
|
{"compress-stream", 0, &do_compress, 1},
|
||||||
|
{"print-compress-size", 0, &do_compress_size, 1},
|
||||||
{nullptr, 0, nullptr, 0}
|
{nullptr, 0, nullptr, 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -338,6 +345,12 @@ void processArgs(int argc, char *argv[], vector<BenchmarkSigs> &sigSets,
|
|||||||
if (do_per_scan) {
|
if (do_per_scan) {
|
||||||
display_per_scan = true;
|
display_per_scan = true;
|
||||||
}
|
}
|
||||||
|
if (do_compress) {
|
||||||
|
compressStream = true;
|
||||||
|
}
|
||||||
|
if (do_compress_size) {
|
||||||
|
printCompressSize = true;
|
||||||
|
}
|
||||||
|
|
||||||
if (exprPath.empty() && !sigFiles.empty()) {
|
if (exprPath.empty() && !sigFiles.empty()) {
|
||||||
/* attempt to infer an expression directory */
|
/* attempt to infer an expression directory */
|
||||||
@ -470,10 +483,12 @@ vector<StreamInfo> prepStreamingData(const ThreadContext *ctx) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
void benchStreamingInternal(ThreadContext *ctx, vector<StreamInfo> &streams) {
|
void benchStreamingInternal(ThreadContext *ctx, vector<StreamInfo> &streams,
|
||||||
|
bool do_compress) {
|
||||||
assert(ctx);
|
assert(ctx);
|
||||||
const EngineHyperscan &e = ctx->engine;
|
const EngineHyperscan &e = ctx->engine;
|
||||||
const vector<DataBlock> &blocks = ctx->corpus_data;
|
const vector<DataBlock> &blocks = ctx->corpus_data;
|
||||||
|
vector<char> compress_buf(do_compress ? 1000 : 0);
|
||||||
|
|
||||||
for (ResultEntry &r : ctx->results) {
|
for (ResultEntry &r : ctx->results) {
|
||||||
ctx->timer.start();
|
ctx->timer.start();
|
||||||
@ -491,6 +506,8 @@ void benchStreamingInternal(ThreadContext *ctx, vector<StreamInfo> &streams) {
|
|||||||
printf("Fatal error: stream open failed!\n");
|
printf("Fatal error: stream open failed!\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
} else if (do_compress) {
|
||||||
|
e.streamCompressExpand(*stream.eng_handle, compress_buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(stream.eng_handle);
|
assert(stream.eng_handle);
|
||||||
@ -521,7 +538,7 @@ void benchStreaming(void *context) {
|
|||||||
|
|
||||||
startTotalTimer(ctx);
|
startTotalTimer(ctx);
|
||||||
|
|
||||||
benchStreamingInternal(ctx, streams);
|
benchStreamingInternal(ctx, streams, false);
|
||||||
|
|
||||||
// Synchronization point
|
// Synchronization point
|
||||||
ctx->barrier();
|
ctx->barrier();
|
||||||
@ -530,6 +547,26 @@ void benchStreaming(void *context) {
|
|||||||
stopTotalTimer(ctx);
|
stopTotalTimer(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
void benchStreamingCompress(void *context) {
|
||||||
|
ThreadContext *ctx = (ThreadContext *)context;
|
||||||
|
vector<StreamInfo> streams = prepStreamingData(ctx);
|
||||||
|
|
||||||
|
// Synchronization point
|
||||||
|
ctx->barrier();
|
||||||
|
|
||||||
|
startTotalTimer(ctx);
|
||||||
|
|
||||||
|
benchStreamingInternal(ctx, streams, true);
|
||||||
|
|
||||||
|
// Synchronization point
|
||||||
|
ctx->barrier();
|
||||||
|
|
||||||
|
// Now that all threads are finished, we can stop the clock.
|
||||||
|
stopTotalTimer(ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/** In-memory structure for a data block to be scanned in vectored mode. */
|
/** In-memory structure for a data block to be scanned in vectored mode. */
|
||||||
struct VectoredInfo {
|
struct VectoredInfo {
|
||||||
vector<const char *> data;
|
vector<const char *> data;
|
||||||
@ -704,7 +741,11 @@ unique_ptr<ThreadContext> makeThreadContext(const EngineHyperscan &db,
|
|||||||
thread_func_t fn = nullptr;
|
thread_func_t fn = nullptr;
|
||||||
switch (scan_mode) {
|
switch (scan_mode) {
|
||||||
case ScanMode::STREAMING:
|
case ScanMode::STREAMING:
|
||||||
fn = benchStreaming;
|
if (compressStream) {
|
||||||
|
fn = benchStreamingCompress;
|
||||||
|
} else {
|
||||||
|
fn = benchStreaming;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case ScanMode::VECTORED:
|
case ScanMode::VECTORED:
|
||||||
fn = benchVectored;
|
fn = benchVectored;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user