-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into fix/from-jax-array-issues
- Loading branch information
Showing
74 changed files
with
6,286 additions
and
2,776 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// | ||
// Created by sam on 28/07/23. | ||
// | ||
|
||
#ifndef ROUGHPY_PLATFORM_THREADS_H | ||
#define ROUGHPY_PLATFORM_THREADS_H | ||
|
||
#include <roughpy/core/alloc.h> | ||
#include <roughpy/core/macros.h> | ||
#include <roughpy/core/types.h> | ||
|
||
#define RPY_ALLOW_THREADING | ||
#if defined(_OPENMP) && defined(RPY_ALLOW_THREADING) | ||
# define RPY_THREADING_OPENMP 1 | ||
#endif | ||
|
||
namespace rpy { | ||
namespace platform { | ||
|
||
enum struct ThreadBackend | ||
{ | ||
Disabled = 0, | ||
OpenMP = 1 | ||
}; | ||
|
||
struct ThreadState { | ||
/// The threading library responsible for managing multi-threaded | ||
/// computation. | ||
ThreadBackend backend; | ||
|
||
/// The maximum number of threads that can be spawned by a single operation. | ||
int max_threads; | ||
|
||
/// The maximum possible number of threads that can be spawned | ||
int max_available_threads; | ||
|
||
/// Is multithreading enabled | ||
bool is_enabled; | ||
}; | ||
|
||
RPY_NO_DISCARD RPY_EXPORT ThreadState get_thread_state(); | ||
|
||
RPY_NO_DISCARD RPY_EXPORT constexpr bool threading_available() | ||
{ | ||
#ifndef RPY_ALLOW_THREADING | ||
return false; | ||
#else | ||
return true; | ||
#endif | ||
} | ||
|
||
RPY_EXPORT void set_num_threads(int num_threads); | ||
|
||
RPY_EXPORT void set_threading_enabled(bool state); | ||
|
||
}// namespace platform | ||
}// namespace rpy | ||
|
||
#endif// ROUGHPY_PLATFORMS_THREADS_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// | ||
// Created by sam on 28/07/23. | ||
// | ||
|
||
#include <roughpy/platform/threads.h> | ||
|
||
#include <atomic> | ||
|
||
#include <omp.h> | ||
|
||
#if !defined(RPY_THREADING_OPENMP) || !RPY_THREADING_OPENMP | ||
# error "OpenMP backend cannot be used unless OpenMP is avaiable." | ||
#endif | ||
|
||
using namespace rpy; | ||
using namespace rpy::platform; | ||
|
||
static const string s_omp_backend_name = "OpenMP"; | ||
|
||
static std::atomic_bool s_enable_omp_threading = true; | ||
|
||
ThreadState rpy::platform::get_thread_state() | ||
{ | ||
return {ThreadBackend::OpenMP, omp_get_num_threads(), omp_get_max_threads(), | ||
s_enable_omp_threading.load(std::memory_order_relaxed)}; | ||
} | ||
|
||
|
||
void rpy::platform::set_num_threads(int num_threads) | ||
{ | ||
omp_set_num_threads(num_threads); | ||
} | ||
|
||
void rpy::platform::set_threading_enabled(bool state) | ||
{ | ||
s_enable_omp_threading.store(state, std::memory_order_relaxed); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.