Skip to content

[XPTI] Additional TBB dependency removal #10486

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions xptifw/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ if (NOT DEFINED XPTI_DIR) # don't overwrite if already set
endif()
endif()

# Create a soft option for enabling the use of TBB
option(XPTI_ENABLE_TBB "Enable TBB in the framework" OFF)

option(XPTI_ENABLE_WERROR OFF)
option(XPTI_BUILD_SAMPLES OFF)
option(XPTI_BUILD_BENCHMARK OFF)
Expand Down
22 changes: 22 additions & 0 deletions xptifw/basic_test/parallel_test.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//
#pragma once
#include "external/BS_thread_pool.hpp"

// Macro to parallelize a loop.
#define PARALLEL_FOR(tp, func, lower, upper) \
{ \
int NumWorkers = tp.get_thread_count(); \
int Step = (upper - lower + 1) / NumWorkers; \
for (int i = 0; i < NumWorkers; ++i) { \
int Min = lower + i * Step; \
int Max = std::min<int>((lower + (i + 1) * Step), upper); \
auto Ret = tp.submit(func, Min, Max); \
} \
tp.wait_for_tasks(); \
}
15 changes: 1 addition & 14 deletions xptifw/basic_test/performance_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,14 @@
//
// Copyright (c) 2023 Barak Shoshany. Licensed under the MIT license.
#include "cl_processor.hpp"
#include "external/BS_thread_pool.hpp"
#include "parallel_test.h"
#include "xpti/xpti_trace_framework.h"

#include <algorithm>
#include <atomic>
#include <chrono>
#include <random>

// Macro to parallelize a loop.
#define PARALLEL_FOR(tp, func, lower, upper) \
{ \
int NumWorkers = tp.get_thread_count(); \
int Step = (upper - lower + 1) / NumWorkers; \
for (int i = 0; i < NumWorkers; ++i) { \
int Min = lower + i * Step; \
int Max = std::min<int>((lower + (i + 1) * Step), upper); \
auto Ret = tp.submit(func, Min, Max); \
} \
tp.wait_for_tasks(); \
}

namespace test {
void registerCallbacks(uint8_t sid);
namespace performance {
Expand Down
244 changes: 127 additions & 117 deletions xptifw/basic_test/semantic_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
// expected results.
//--------------------------------------------------------------------------
#include "cl_processor.hpp"
#include "parallel_test.h"
#include "xpti/xpti_trace_framework.h"

#include <atomic>
Expand Down Expand Up @@ -125,6 +126,7 @@ void TestCorrectness::runStringTableTestThreads(
(double)(Strings.size() + LookupCount + DuplicateCount) /
(NumStrings * 3) * 100;
} else { // Multi-threaded run
BS::thread_pool tp(NumThreads);
std::vector<char *> Strings;
std::vector<xpti::string_id_t> IDs;
Strings.resize(NumStrings);
Expand All @@ -139,36 +141,39 @@ void TestCorrectness::runStringTableTestThreads(

{
int Count = 0;
std::vector<int> MRange(NumStrings, 0);
std::for_each(MRange.begin(), MRange.end(),
[&](int &n) { n += Count++; });

std::for_each(
std::execution::par, MRange.begin(), MRange.end(), [&](int &i) {
char *TableStrRef = nullptr;
std::string StrName = "Function" + std::to_string(i);
IDs[i] = xptiRegisterString(StrName.c_str(), &TableStrRef);
Strings[i] = TableStrRef;
});

std::for_each(std::execution::par, MRange.begin(), MRange.end(),
[&](int &i) {
const char *TableStrRef = xptiLookupString(IDs[i]);
if (TableStrRef == Strings[i])
++LookupCount;
});

auto RegisterString = [&](int min, int max) {
for (int i = min; i < max; ++i) {
char *TableStrRef = nullptr;
std::string StrName = "Function" + std::to_string(i);
IDs[i] = xptiRegisterString(StrName.c_str(), &TableStrRef);
Strings[i] = TableStrRef;
}
};
PARALLEL_FOR(tp, RegisterString, 0, NumStrings);

auto LookupString = [&](int min, int max) {
for (int i = min; i < max; ++i) {
const char *TableStrRef = xptiLookupString(IDs[i]);
if (TableStrRef == Strings[i])
++LookupCount;
}
};
PARALLEL_FOR(tp, LookupString, 0, NumStrings);
ModelRow[(int)STColumns::Lookups] = LookupCount;

std::for_each(std::execution::par, MRange.begin(), MRange.end(),
[&](int &i) {
char *TableStrRef = nullptr;
std::string StrName = "Function" + std::to_string(i);
xpti::string_id_t id =
xptiRegisterString(StrName.c_str(), &TableStrRef);
if (StrName == TableStrRef && id == IDs[i] &&
TableStrRef == Strings[i])
++DuplicateCount;
});
auto CheckLookup = [&](int min, int max) {
for (int i = min; i < max; ++i) {
char *TableStrRef = nullptr;
std::string StrName = "Function" + std::to_string(i);
xpti::string_id_t id =
xptiRegisterString(StrName.c_str(), &TableStrRef);
if (StrName == TableStrRef && id == IDs[i] &&
TableStrRef == Strings[i])
++DuplicateCount;
}
};
PARALLEL_FOR(tp, CheckLookup, 0, NumStrings);
ModelRow[(int)STColumns::DuplicateInserts] = DuplicateCount;

ModelRow[(int)STColumns::PassRate] =
Expand Down Expand Up @@ -266,10 +271,8 @@ void TestCorrectness::runTracepointTestThreads(int RunNo, int NumThreads,
(TracepointCount * 4) * 100;
} else {

BS::thread_pool tp(NumThreads);
int Count = 0;
std::vector<size_t> MRange(TracepointCount, 0);
std::for_each(MRange.begin(), MRange.end(),
[&](size_t &n) { n += Count++; });

std::vector<xpti::payload_t *> Payloads;
std::vector<int64_t> UIds;
Expand All @@ -285,51 +288,57 @@ void TestCorrectness::runTracepointTestThreads(int RunNo, int NumThreads,
std::atomic<int> LookupCount = {0}, DuplicateCount = {0},
PayloadCount = {0};

std::for_each(
std::execution::par, MRange.begin(), MRange.end(), [&](size_t &i) {
std::string fn = "Function" + std::to_string(i);
xpti::payload_t P = xpti::payload_t(fn.c_str(), MSource, (int)i,
(int)i % 80, (void *)i);
xpti::trace_event_data_t *Ev = xptiMakeEvent(
fn.c_str(), &P, (uint16_t)xpti::trace_event_type_t::algorithm,
xpti::trace_activity_type_t::active, &MInstanceID);
if (Ev) {
UIds[i] = Ev->unique_id;
Payloads[i] = Ev->reserved.payload;
Events[i] = Ev;
}
});
auto MakeEvent = [&](int min, int max) {
for (size_t i = min; i < max; ++i) {
std::string fn = "Function" + std::to_string(i);
xpti::payload_t P = xpti::payload_t(fn.c_str(), MSource, (int)i,
(int)i % 80, (void *)i);
xpti::trace_event_data_t *Ev = xptiMakeEvent(
fn.c_str(), &P, (uint16_t)xpti::trace_event_type_t::algorithm,
xpti::trace_activity_type_t::active, &MInstanceID);
if (Ev) {
UIds[i] = Ev->unique_id;
Payloads[i] = Ev->reserved.payload;
Events[i] = Ev;
}
}
};
PARALLEL_FOR(tp, MakeEvent, 0, TracepointCount);
ModelRow[(int)TPColumns::Insertions] = (long double)Events.size();

std::for_each(std::execution::par, MRange.begin(), MRange.end(),
[&](size_t &i) {
std::string fn = "Function" + std::to_string(i);
const xpti::trace_event_data_t *Ev = xptiFindEvent(UIds[i]);
if (Ev && Ev->unique_id == UIds[i])
LookupCount++;
});
auto EventLookup = [&](int min, int max) {
for (size_t i = min; i < max; ++i) {
std::string fn = "Function" + std::to_string(i);
const xpti::trace_event_data_t *Ev = xptiFindEvent(UIds[i]);
if (Ev && Ev->unique_id == UIds[i])
LookupCount++;
}
};
PARALLEL_FOR(tp, EventLookup, 0, TracepointCount);
ModelRow[(int)TPColumns::Lookups] = LookupCount;

std::for_each(
std::execution::par, MRange.begin(), MRange.end(), [&](size_t &i) {
std::string fn = "Function" + std::to_string(i);
xpti::payload_t P = xpti::payload_t(fn.c_str(), MSource, (int)i,
(int)i % 80, (void *)i);
xpti::trace_event_data_t *Ev = xptiMakeEvent(
fn.c_str(), &P, (uint16_t)xpti::trace_event_type_t::algorithm,
xpti::trace_activity_type_t::active, &MInstanceID);
if (Ev) {
if (Ev->unique_id == UIds[i]) {
++DuplicateCount;
}
xpti::payload_t *RP = Ev->reserved.payload;
if (Ev->unique_id == UIds[i] && RP &&
std::string(RP->name) == std::string(P.name) &&
std::string(RP->source_file) == std::string(P.source_file) &&
RP->line_no == P.line_no && RP->column_no == P.column_no)
++PayloadCount;
auto CheckEvents = [&](int min, int max) {
for (size_t i = min; i < max; ++i) {
std::string fn = "Function" + std::to_string(i);
xpti::payload_t P = xpti::payload_t(fn.c_str(), MSource, (int)i,
(int)i % 80, (void *)i);
xpti::trace_event_data_t *Ev = xptiMakeEvent(
fn.c_str(), &P, (uint16_t)xpti::trace_event_type_t::algorithm,
xpti::trace_activity_type_t::active, &MInstanceID);
if (Ev) {
if (Ev->unique_id == UIds[i]) {
++DuplicateCount;
}
});
xpti::payload_t *RP = Ev->reserved.payload;
if (Ev->unique_id == UIds[i] && RP &&
std::string(RP->name) == std::string(P.name) &&
std::string(RP->source_file) == std::string(P.source_file) &&
RP->line_no == P.line_no && RP->column_no == P.column_no)
++PayloadCount;
}
}
};
PARALLEL_FOR(tp, CheckEvents, 0, TracepointCount);
ModelRow[(int)TPColumns::DuplicateInserts] = DuplicateCount;
ModelRow[(int)TPColumns::PayloadLookup] = PayloadCount;
ModelRow[(int)TPColumns::PassRate] =
Expand Down Expand Up @@ -426,60 +435,61 @@ void TestCorrectness::runNotificationTestThreads(
ModelRow[(int)NColumns::Notifications] = (long double)Acc;
ModelRow[(int)NColumns::PassRate] = (long double)(Acc) / (NotifyCount)*100;
} else {

BS::thread_pool tp(NumThreads);
std::atomic<int> NotifyCount = {0};

int Count = 0;
std::vector<size_t> MRange(CallbackCount, 0);
std::for_each(MRange.begin(), MRange.end(),
[&](size_t &n) { n += Count++; });

std::for_each(std::execution::par_unseq, MRange.begin(), MRange.end(),
[&](size_t &i) {
if (i >= TPCount)
return;

size_t Index = (int)i;
std::string fn = "Function" + std::to_string(i);
xpti::payload_t P =
xpti::payload_t(fn.c_str(), MSource, (int)Index,
(int)Index % 80, (void *)(i % 10));
xpti::trace_event_data_t *Ev = xptiMakeEvent(
fn.c_str(), &P,
(uint16_t)xpti::trace_event_type_t::algorithm,
xpti::trace_activity_type_t::active, &MInstanceID);
if (Ev) {
UIds[Index] = Ev->unique_id;
Payloads[Index] = Ev->reserved.payload;
Events[Index] = Ev;
}
++NotifyCount;
});

auto MakeEvents = [&](int min, int max) {
for (size_t i = min; i < max; ++i) {
if (i >= TPCount)
return;

size_t Index = (int)i;
std::string fn = "Function" + std::to_string(i);
xpti::payload_t P = xpti::payload_t(fn.c_str(), MSource, (int)Index,
(int)Index % 80, (void *)(i % 10));
xpti::trace_event_data_t *Ev = xptiMakeEvent(
fn.c_str(), &P, (uint16_t)xpti::trace_event_type_t::algorithm,
xpti::trace_activity_type_t::active, &MInstanceID);
if (Ev) {
UIds[Index] = Ev->unique_id;
Payloads[Index] = Ev->reserved.payload;
Events[Index] = Ev;
}
++NotifyCount;
}
};
PARALLEL_FOR(tp, MakeEvents, 0, CallbackCount);

std::string RowTitle = "Threads " + std::to_string(NumThreads);
auto &ModelRow = Model.addRow(RunNo, RowTitle);
ModelRow[(int)NColumns::Threads] = NumThreads;

std::for_each(
std::execution::par, MRange.begin(), MRange.end(), [&](size_t &i) {
if (i < TPCount)
return;

size_t Index = (int)i % TPCount;
void *Address = (void *)(Index % 10);
std::string fn = "Function" + std::to_string(Index);
xpti::payload_t P = xpti::payload_t(fn.c_str(), MSource, (int)Index,
(int)Index % 80, Address);
xpti::trace_event_data_t *Ev = xptiMakeEvent(
fn.c_str(), &P, (uint16_t)xpti::trace_event_type_t::algorithm,
xpti::trace_activity_type_t::active, &MInstanceID);
if (Ev && Ev->unique_id == UIds[Index]) {
uint8_t TP = (Index % 10) + 1;
uint16_t TPType = (uint16_t)(TP << 1);
xpti::framework::scoped_notify ev("xpti", TPType, nullptr, Ev,
MInstanceID, nullptr);
NotifyCount++;
}
});
auto NotifyCallbacks = [&](int min, int max) {
for (size_t i = min; i < max; ++i) {
if (i < TPCount)
return;

size_t Index = (int)i % TPCount;
void *Address = (void *)(Index % 10);
std::string fn = "Function" + std::to_string(Index);
xpti::payload_t P = xpti::payload_t(fn.c_str(), MSource, (int)Index,
(int)Index % 80, Address);
xpti::trace_event_data_t *Ev = xptiMakeEvent(
fn.c_str(), &P, (uint16_t)xpti::trace_event_type_t::algorithm,
xpti::trace_activity_type_t::active, &MInstanceID);
if (Ev && Ev->unique_id == UIds[Index]) {
uint8_t TP = (Index % 10) + 1;
uint16_t TPType = (uint16_t)(TP << 1);
xpti::framework::scoped_notify ev("xpti", TPType, nullptr, Ev,
MInstanceID, nullptr);
NotifyCount++;
}
}
};
PARALLEL_FOR(tp, NotifyCallbacks, 0, CallbackCount);

uint64_t Acc = 0;
for (int i = 0; i < TPCount; ++i) {
Expand Down