Skip to content

Commit

Permalink
Migrate to 1.0
Browse files Browse the repository at this point in the history
Windows Support (v1.0.0)
  • Loading branch information
Clemapfel authored Feb 28, 2023
2 parents e554271 + 9bb529d commit 35cfa4f
Show file tree
Hide file tree
Showing 61 changed files with 1,715 additions and 6,267 deletions.
5 changes: 2 additions & 3 deletions .benchmark/benchmark.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ namespace jluna
struct Result
{
Result()
: _name(""),
_min(0),
: _min(0),
_max(0),
_average(0),
_median(0),
Expand Down Expand Up @@ -165,7 +164,7 @@ namespace jluna
std::cout << "│ Max : " << max << "ms" << std::endl;
std::cout << "│ Median : " << med << "ms" << std::endl;
std::cout << "" << std::endl;
std::cout << "│ Overhead: " << (res._overhead * 100) << "%" << std::endl;
std::cout << "│ Overhead: " << (res._overhead * 100.f) << "%" << std::endl;

if (res._exception_maybe != "")
{
Expand Down
10 changes: 5 additions & 5 deletions .benchmark/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,29 +83,29 @@ int main()
// C-API
Benchmark::run_as_base("C-API: set", n_reps, [](){

Int64 to_box = generate_number<Int64>();
auto to_box = generate_number<Int64>();
jl_set_global(jl_main_module, "x"_sym, jl_box_int64(to_box));
});

// unsafe
Benchmark::run("unsafe: set", n_reps, [](){

Int64 to_box = generate_number<Int64>();
auto to_box = generate_number<Int64>();
unsafe::set_value(jl_main_module, "x"_sym, unsafe::unsafe_box<Int64>(to_box));
});

// Module::assign
Benchmark::run("Module::assign", n_reps / 10, [](){

Int64 to_box = generate_number<Int64>();
auto to_box = generate_number<Int64>();
Main.assign("x", to_box);
});

// Proxy::operator=
auto x_proxy = Main["x"];
Benchmark::run("Proxy::operator=", n_reps / 10, [&](){

Int64 to_box = generate_number<Int64>();
auto to_box = generate_number<Int64>();
x_proxy = to_box;
});

Expand Down Expand Up @@ -304,7 +304,7 @@ int main()
// run task using std::thread
Benchmark::run("threading: std::thread", n_reps, [&]()
{
queue.emplace(std::packaged_task<void()>(task));
queue.emplace(task);
queue_cv.notify_all();
master_cv.wait(master_lock, [](){
return queue.empty();
Expand Down
15 changes: 11 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,18 @@
/.vscode
/.benchmark/results
/.idea/
/jluna_c_adapter.so/
/libjluna.so
/libjluna_c_adapter.so
/docs/doxygen
/docs/html
/docs/latex
/docs/out

/.vs/
/cmake_build_debug
/CMakeSettings.json
out/build
out/install
*.vsidx
/enc_temp_folder
/cmake-build-debug-mingw/
/cmake-build-debug/
/cmake-build-debug-event-trace/
/out/
14 changes: 12 additions & 2 deletions .src/array.inl
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ namespace jluna
{}

template<is_boxable T, size_t Rank>
size_t Array<T, Rank>::get_dimension(int index) const
size_t Array<T, Rank>::get_dimension(size_t index) const
{
return jl_array_dim(this->operator unsafe::Array*(), index);
}
Expand Down Expand Up @@ -214,6 +214,12 @@ namespace jluna
return operator[]<T>(index);
}

#ifdef _MSC_VER
// silence false positive conversion warning on MSVC
#pragma warning(push)
#pragma warning(disable:4267)
#endif

template<is_boxable V, size_t R>
template<typename... Args, std::enable_if_t<sizeof...(Args) == R and (std::is_integral_v<Args> and ...), bool>>
auto Array<V, R>::at(Args... in)
Expand All @@ -237,6 +243,10 @@ namespace jluna
return operator[](index);
}

#ifdef _MSC_VER
#pragma warning(pop)
#endif

template<is_boxable V, size_t R>
template<is_boxable T>
void Array<V, R>::set(size_t i, T value)
Expand Down Expand Up @@ -278,7 +288,7 @@ namespace jluna
template<is_unboxable T>
T Array<V, R>::front() const
{
return operator[](0);
return static_cast<T>(operator[](0));
}

template<is_boxable V, size_t R>
Expand Down
16 changes: 13 additions & 3 deletions .src/box.inl
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ namespace jluna
}

template<is<void> T>
unsafe::Value* box(T value)
unsafe::Value* box(T)
{
return jl_nothing;
}
Expand All @@ -53,13 +53,13 @@ namespace jluna
}

template<is<std::bool_constant<true>> T>
unsafe::Value* box(T value)
unsafe::Value* box(T)
{
return jl_box_bool(true);
}

template<is<std::bool_constant<false>> T>
unsafe::Value* box(T value)
unsafe::Value* box(T)
{
return jl_box_bool(false);
}
Expand Down Expand Up @@ -216,6 +216,12 @@ namespace jluna
return unsafe::call(pair, box<T1>(value.first), box<T2>(value.second));
}

#ifdef _MSC_VER
// silence false positive conversion warning on MSVC
#pragma warning(push)
#pragma warning(disable:4267)
#endif

template<is_tuple T>
unsafe::Value* box(const T& value)
{
Expand All @@ -239,4 +245,8 @@ namespace jluna
gc_unpause;
return out;
}

#ifdef _MSC_VER
#pragma warning(pop)
#endif
}
2 changes: 1 addition & 1 deletion .src/c_adapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void jluna_free_lambda(void* in, int n_args)
else if (n_args == 3)
delete (jluna::detail::lambda_3_arg*) in;
else
throw std::invalid_argument("In c_adapter::jluna_free_lambda: " + std::to_string(n_args) + " is a invalid number of arguments");
std::cerr << "[C++][WARNING] In c_adapter::jluna_free_lambda: Unreachable reached" << std::endl;
}

jluna::unsafe::Value* jluna_invoke_lambda_0(void* function_ptr)
Expand Down
4 changes: 2 additions & 2 deletions .src/c_adapter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

#pragma once

#include <stddef.h>

#include <include/julia_wrapper.hpp>

#include <cstddef>
#include <functional>
#include <string>

Expand Down
2 changes: 1 addition & 1 deletion .src/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace jluna::detail
inline std::string to_string(unsafe::Value* value)
{
static auto* string = unsafe::get_function(jl_base_module, "string"_sym);
return std::string(jl_string_ptr(unsafe::call(string, value)));
return {jl_string_ptr(unsafe::call(string, value))};
}

inline void assert_type(unsafe::DataType* type_a, unsafe::DataType* type_b)
Expand Down
2 changes: 1 addition & 1 deletion .src/exceptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace jluna
{
JuliaException::JuliaException(jl_value_t* exception, std::string stacktrace)
JuliaException::JuliaException(jl_value_t* exception, const std::string& stacktrace)
: _value(exception), _message("[JULIA][EXCEPTION] " + stacktrace)
{}

Expand Down
8 changes: 4 additions & 4 deletions .src/generator_expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace jluna
auto* res = jl_eval_string(in);
forward_last_exception();

static jl_datatype_t* generator_type = (jl_datatype_t*) jl_eval_string("Base.Generator");
static auto* generator_type = (jl_datatype_t*) jl_eval_string("Base.Generator");
if (not jl_isa(res, (unsafe::Value*) generator_type))
{
std::stringstream error_str;
Expand Down Expand Up @@ -78,13 +78,13 @@ namespace jluna
}

GeneratorExpression::ForwardIterator::ForwardIterator(const GeneratorExpression* owner, Int64 state)
: _owner(owner), _state(state), _is_end(_state)
: _owner(owner), _state(state)
{}

unsafe::Value* GeneratorExpression::ForwardIterator::operator*()
{
gc_pause;
auto* out = jl_get_nth_field(jl_call2(_owner->_iterate, _owner->get(), jl_box_int64(_state)), 0);
auto* out = jl_get_nth_field(jl_call2(_iterate, _owner->get(), jl_box_int64(_state)), 0);
gc_unpause;
return out;
}
Expand All @@ -94,7 +94,7 @@ namespace jluna
auto previous = _state;

gc_pause;
auto* next = jl_call2(_owner->_iterate, _owner->get(), jl_box_int64(_state));
auto* next = jl_call2(_iterate, _owner->get(), jl_box_int64(_state));

if (jl_is_nothing(next))
_state = previous;
Expand Down
11 changes: 10 additions & 1 deletion .src/include_julia.inl.in
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,14 @@
namespace jluna::detail
{
static inline const char* shared_library_name = "@SHARED_LIBRARY_NAME@";
static inline const char* julia_source = R"(@JLUNA_JULIA_SOURCE@)";

// necessary to avoid https://learn.microsoft.com/en-us/cpp/error-messages/compiler-errors-1/compiler-error-c2026?view=msvc-170
static inline std::string julia_source =
R"(@JLUNA_01@)"
R"(@JLUNA_02@)"
R"(@JLUNA_03@)"
R"(@JLUNA_04@)"
R"(@JLUNA_05@)"
R"(@JLUNA_06@)"
;
}
4 changes: 2 additions & 2 deletions .src/module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace jluna

Module Module::get_parent_module() const
{
return Module(value()->parent);
return {value()->parent};
}

bool Module::is_top_module() const
Expand Down Expand Up @@ -79,7 +79,7 @@ namespace jluna

Symbol Module::get_symbol() const
{
return Symbol(value()->name);
return {value()->name};
}

void Module::initialize_lock()
Expand Down
13 changes: 12 additions & 1 deletion .src/module.inl
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@ namespace jluna
initialize_lock();
_lock->lock();
}

gc_pause;
jl_set_global(value(), jl_symbol(variable_name.c_str()), box<T>(new_value));
gc_unpause;

if (detail::_num_threads != 1)
_lock->unlock();
Expand Down Expand Up @@ -305,4 +306,14 @@ namespace jluna
{
return Proxy(get<unsafe::Value*>(variable_name), jl_symbol(variable_name.c_str()));
}

namespace detail
{
inline void initialize_modules()
{
Main = Module(jl_main_module);
Core = Module(jl_core_module);
Base = Module(jl_base_module);
}
}
}
23 changes: 12 additions & 11 deletions .src/multi_threading.inl
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ namespace jluna
struct TaskValue : public detail::TaskSuper
{
friend class jluna::ThreadPool;
TaskValue(size_t);
explicit TaskValue(size_t);
~TaskValue();

void free() override;
void initialize(std::function<unsafe::Value*()>*);

unsafe::Value* _value;
size_t _value_id;
size_t _threadpool_id;
unsafe::Value* _value = nullptr;
size_t _value_id = -1;
size_t _threadpool_id = -1;
std::unique_ptr<Future<Result_t>> _future;
};
}
Expand Down Expand Up @@ -125,7 +125,7 @@ namespace jluna
}

template<typename T>
Task<T>::Task(Task&& other)
Task<T>::Task(Task&& other) noexcept
{
_value = std::move(other._value);
other._value = nullptr;
Expand All @@ -141,7 +141,7 @@ namespace jluna
}

template<typename T>
Task<T>& Task<T>::operator=(Task&& other)
Task<T>& Task<T>::operator=(Task&& other) noexcept
{
_value = std::move(other._value);
other._value = nullptr;
Expand Down Expand Up @@ -220,8 +220,8 @@ namespace jluna

Task& operator=(const Task&) = delete;
Task(const Task&) = delete;
Task(Task&& other);
Task& operator=(Task&& other);
Task(Task&& other) noexcept;
Task& operator=(Task&& other) noexcept;

operator unsafe::Value*();
void join();
Expand All @@ -235,7 +235,7 @@ namespace jluna
Task(detail::TaskValue<unsafe::Value*>*);

private:
detail::TaskValue<unsafe::Value*>* _value; // lifetime managed by threadpool
detail::TaskValue<unsafe::Value*>* _value = nullptr; // lifetime managed by threadpool
};

inline Task<void>::Task(detail::TaskValue<unsafe::Value*>* value)
Expand All @@ -248,7 +248,7 @@ namespace jluna
ThreadPool::free(_value->_threadpool_id);
}

inline Task<void>::Task(Task&& other)
inline Task<void>::Task(Task&& other) noexcept
{
_value = std::move(other._value);
other._value = nullptr;
Expand All @@ -262,10 +262,11 @@ namespace jluna
return _value->_value;
}

inline Task<void>& Task<void>::operator=(Task&& other)
inline Task<void>& Task<void>::operator=(Task&& other) noexcept
{
_value = std::move(other._value);
other._value = nullptr;
return *this;
}

inline void Task<void>::join()
Expand Down
Loading

0 comments on commit 35cfa4f

Please sign in to comment.