Commit b6fa949c by Nicolas Capens

Merge changes I5e9afad9,Ibd0b2ee4

* changes: Update Marl to bf3e23083 Squashed 'third_party/marl/' changes from 59068ee4c..bf3e23083
parents 126d9d60 e901e9b5
...@@ -26,6 +26,7 @@ option(MARL_BUILD_EXAMPLES "Build example applications" OFF) ...@@ -26,6 +26,7 @@ option(MARL_BUILD_EXAMPLES "Build example applications" OFF)
option(MARL_BUILD_TESTS "Build tests" OFF) option(MARL_BUILD_TESTS "Build tests" OFF)
option(MARL_ASAN "Build marl with address sanitizer" OFF) option(MARL_ASAN "Build marl with address sanitizer" OFF)
option(MARL_TSAN "Build marl with thread sanitizer" OFF) option(MARL_TSAN "Build marl with thread sanitizer" OFF)
option(MARL_INSTALL "Create marl install target" OFF)
if(MARL_ASAN AND MARL_TSAN) if(MARL_ASAN AND MARL_TSAN)
message(FATAL_ERROR "MARL_ASAN and MARL_TSAN are mutually exclusive") message(FATAL_ERROR "MARL_ASAN and MARL_TSAN are mutually exclusive")
...@@ -53,7 +54,7 @@ endif(MARL_BUILD_TESTS) ...@@ -53,7 +54,7 @@ endif(MARL_BUILD_TESTS)
########################################################### ###########################################################
# File lists # File lists
########################################################### ###########################################################
file(GLOB MARL_LIST set(MARL_LIST
${MARL_SRC_DIR}/debug.cpp ${MARL_SRC_DIR}/debug.cpp
${MARL_SRC_DIR}/scheduler.cpp ${MARL_SRC_DIR}/scheduler.cpp
${MARL_SRC_DIR}/thread.cpp ${MARL_SRC_DIR}/thread.cpp
...@@ -74,20 +75,6 @@ if(NOT MSVC) ...@@ -74,20 +75,6 @@ if(NOT MSVC)
) )
endif(NOT MSVC) endif(NOT MSVC)
file(GLOB MARL_TEST_LIST
${MARL_SRC_DIR}/blockingcall_test.cpp
${MARL_SRC_DIR}/conditionvariable_test.cpp
${MARL_SRC_DIR}/containers_test.cpp
${MARL_SRC_DIR}/defer_test.cpp
${MARL_SRC_DIR}/marl_test.cpp
${MARL_SRC_DIR}/marl_test.h
${MARL_SRC_DIR}/osfiber_test.cpp
${MARL_SRC_DIR}/pool_test.cpp
${MARL_SRC_DIR}/scheduler_test.cpp
${MARL_SRC_DIR}/ticket_test.cpp
${MARL_SRC_DIR}/waitgroup_test.cpp
)
########################################################### ###########################################################
# OS libraries # OS libraries
########################################################### ###########################################################
...@@ -148,10 +135,44 @@ marl_set_target_options(marl) ...@@ -148,10 +135,44 @@ marl_set_target_options(marl)
target_link_libraries(marl "${MARL_OS_LIBS}") target_link_libraries(marl "${MARL_OS_LIBS}")
# install
if(MARL_INSTALL)
include(GNUInstallDirs)
install(DIRECTORY ${MARL_INCLUDE_DIR}/marl
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
USE_SOURCE_PERMISSIONS
)
install(TARGETS marl
EXPORT marl-targets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
install(EXPORT marl-targets
FILE marl-config.cmake
NAMESPACE marl::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/marl
)
endif(MARL_INSTALL)
# tests # tests
if(MARL_BUILD_TESTS) if(MARL_BUILD_TESTS)
file(GLOB MARL_TEST_LIST set(MARL_TEST_LIST
${MARL_SRC_DIR}/*_test.cpp ${MARL_SRC_DIR}/blockingcall_test.cpp
${MARL_SRC_DIR}/conditionvariable_test.cpp
${MARL_SRC_DIR}/containers_test.cpp
${MARL_SRC_DIR}/defer_test.cpp
${MARL_SRC_DIR}/marl_test.cpp
${MARL_SRC_DIR}/marl_test.h
${MARL_SRC_DIR}/osfiber_test.cpp
${MARL_SRC_DIR}/pool_test.cpp
${MARL_SRC_DIR}/scheduler_test.cpp
${MARL_SRC_DIR}/ticket_test.cpp
${MARL_SRC_DIR}/waitgroup_test.cpp
${GOOGLETEST_DIR}/googletest/src/gtest-all.cc ${GOOGLETEST_DIR}/googletest/src/gtest-all.cc
) )
......
...@@ -45,7 +45,7 @@ The resulting binaries will be found in `<path-to-marl>/build` ...@@ -45,7 +45,7 @@ The resulting binaries will be found in `<path-to-marl>/build`
### Windows ### Windows
Marl can be build using [Visual Studio 2019's CMake integration](https://docs.microsoft.com/en-us/cpp/build/cmake-projects-in-visual-studio?view=vs-2019). Marl can be built using [Visual Studio 2019's CMake integration](https://docs.microsoft.com/en-us/cpp/build/cmake-projects-in-visual-studio?view=vs-2019).
### Using Marl in your CMake project ### Using Marl in your CMake project
......
...@@ -175,17 +175,20 @@ int main(int argc, const char** argv) { ...@@ -175,17 +175,20 @@ int main(int argc, const char** argv) {
for (uint32_t x = 0; x < imageWidth; x++) { for (uint32_t x = 0; x < imageWidth; x++) {
// Calculate the fractal pixel color. // Calculate the fractal pixel color.
Color<float> color = {}; Color<float> color = {};
// Take a number of sub-pixel samples.
for (int sy = 0; sy < samplesPerPixelH; sy++) { for (int sy = 0; sy < samplesPerPixelH; sy++) {
auto fy = float(y) + (sy / float(samplesPerPixelH)); auto fy = float(y) + (sy / float(samplesPerPixelH));
auto dy = float(fy) / float(imageHeight);
for (int sx = 0; sx < samplesPerPixelW; sx++) { for (int sx = 0; sx < samplesPerPixelW; sx++) {
auto fx = float(x) + (sx / float(samplesPerPixelW)); auto fx = float(x) + (sx / float(samplesPerPixelW));
auto dx = float(fx) / float(imageWidth); auto dx = float(fx) / float(imageWidth);
auto dy = float(fy) / float(imageHeight);
color += julia(lerp(dx, windowMinX, windowMaxX), color += julia(lerp(dx, windowMinX, windowMaxX),
lerp(dy, windowMinY, windowMaxY), cx, cy); lerp(dy, windowMinY, windowMaxY), cx, cy);
} }
} }
// Average the color.
color /= samplesPerPixelW * samplesPerPixelH; color /= samplesPerPixelW * samplesPerPixelH;
// Write the pixel out to the image buffer.
pixels[x + y * imageWidth] = {static_cast<uint8_t>(color.r * 255), pixels[x + y * imageWidth] = {static_cast<uint8_t>(color.r * 255),
static_cast<uint8_t>(color.g * 255), static_cast<uint8_t>(color.g * 255),
static_cast<uint8_t>(color.b * 255)}; static_cast<uint8_t>(color.b * 255)};
......
...@@ -20,6 +20,8 @@ ...@@ -20,6 +20,8 @@
#include "marl/thread.h" #include "marl/thread.h"
#include "marl/ticket.h" #include "marl/ticket.h"
#include <math.h>
// searchMax defines the upper limit on primes to find. // searchMax defines the upper limit on primes to find.
constexpr int searchMax = 10000000; constexpr int searchMax = 10000000;
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
namespace marl { namespace marl {
void fatal(const char* msg, ...); void fatal(const char* msg, ...);
void warn(const char* msg, ...);
void assert_has_bound_scheduler(const char* feature); void assert_has_bound_scheduler(const char* feature);
#if MARL_DEBUG_ENABLED #if MARL_DEBUG_ENABLED
...@@ -39,11 +40,13 @@ void assert_has_bound_scheduler(const char* feature); ...@@ -39,11 +40,13 @@ void assert_has_bound_scheduler(const char* feature);
#define MARL_ASSERT_HAS_BOUND_SCHEDULER(feature) \ #define MARL_ASSERT_HAS_BOUND_SCHEDULER(feature) \
assert_has_bound_scheduler(feature); assert_has_bound_scheduler(feature);
#define MARL_UNREACHABLE() MARL_FATAL("UNREACHABLE"); #define MARL_UNREACHABLE() MARL_FATAL("UNREACHABLE");
#define MARL_WARN(msg, ...) marl::warn("WARNING: " msg "\n", ##__VA_ARGS__);
#else #else
#define MARL_FATAL(msg, ...) #define MARL_FATAL(msg, ...)
#define MARL_ASSERT(cond, msg, ...) #define MARL_ASSERT(cond, msg, ...)
#define MARL_ASSERT_HAS_BOUND_SCHEDULER(feature) #define MARL_ASSERT_HAS_BOUND_SCHEDULER(feature)
#define MARL_UNREACHABLE() #define MARL_UNREACHABLE()
#define MARL_WARN(msg, ...)
#endif #endif
} // namespace marl } // namespace marl
......
...@@ -161,7 +161,7 @@ void Pool<T>::Loan::reset() { ...@@ -161,7 +161,7 @@ void Pool<T>::Loan::reset() {
} }
template <typename T> template <typename T>
typename Pool<T>::Loan& Pool<T>::Loan::operator=(const Pool<T>::Loan& rhs) { typename Pool<T>::Loan& Pool<T>::Loan::operator=(const Loan& rhs) {
reset(); reset();
if (rhs.item != nullptr) { if (rhs.item != nullptr) {
item = rhs.item; item = rhs.item;
...@@ -172,7 +172,7 @@ typename Pool<T>::Loan& Pool<T>::Loan::operator=(const Pool<T>::Loan& rhs) { ...@@ -172,7 +172,7 @@ typename Pool<T>::Loan& Pool<T>::Loan::operator=(const Pool<T>::Loan& rhs) {
} }
template <typename T> template <typename T>
typename Pool<T>::Loan& Pool<T>::Loan::operator=(Pool<T>::Loan&& rhs) { typename Pool<T>::Loan& Pool<T>::Loan::operator=(Loan&& rhs) {
reset(); reset();
std::swap(item, rhs.item); std::swap(item, rhs.item);
std::swap(storage, rhs.storage); std::swap(storage, rhs.storage);
......
...@@ -137,7 +137,7 @@ class Scheduler { ...@@ -137,7 +137,7 @@ class Scheduler {
static constexpr size_t FiberStackSize = 1024 * 1024; static constexpr size_t FiberStackSize = 1024 * 1024;
// Maximum number of worker threads. // Maximum number of worker threads.
static constexpr size_t MaxWorkerThreads = 64; static constexpr size_t MaxWorkerThreads = 256;
// TODO: Implement a queue that recycles elements to reduce number of // TODO: Implement a queue that recycles elements to reduce number of
// heap allocations. // heap allocations.
......
...@@ -32,6 +32,13 @@ void fatal(const char* msg, ...) { ...@@ -32,6 +32,13 @@ void fatal(const char* msg, ...) {
abort(); abort();
} }
void warn(const char* msg, ...) {
va_list vararg;
va_start(vararg, msg);
vfprintf(stdout, msg, vararg);
va_end(vararg);
}
void assert_has_bound_scheduler(const char* feature) { void assert_has_bound_scheduler(const char* feature) {
MARL_ASSERT(Scheduler::get() != nullptr, MARL_ASSERT(Scheduler::get() != nullptr,
"%s requires a marl::Scheduler to be bound", feature); "%s requires a marl::Scheduler to be bound", feature);
......
...@@ -122,6 +122,14 @@ const std::function<void()>& Scheduler::getThreadInitializer() { ...@@ -122,6 +122,14 @@ const std::function<void()>& Scheduler::getThreadInitializer() {
void Scheduler::setWorkerThreadCount(int newCount) { void Scheduler::setWorkerThreadCount(int newCount) {
MARL_ASSERT(newCount >= 0, "count must be positive"); MARL_ASSERT(newCount >= 0, "count must be positive");
if (newCount > int(MaxWorkerThreads)) {
MARL_WARN(
"marl::Scheduler::setWorkerThreadCount() called with a count of %d, "
"which exceeds the maximum of %d. Limiting the number of threads to "
"%d.",
newCount, int(MaxWorkerThreads), int(MaxWorkerThreads));
newCount = MaxWorkerThreads;
}
auto oldCount = numWorkerThreads; auto oldCount = numWorkerThreads;
for (int idx = oldCount - 1; idx >= newCount; idx--) { for (int idx = oldCount - 1; idx >= newCount; idx--) {
workerThreads[idx]->stop(); workerThreads[idx]->stop();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment