Skip to content
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

[Loops] Adds occa::forLoop #465

Merged
merged 13 commits into from
Jan 20, 2021
Prev Previous commit
Next Next commit
[Functional] Make scope optional
  • Loading branch information
dmed256 committed Jan 20, 2021
commit 884bd360e85434bffeadcadff19cf565c6791cdb
1 change: 1 addition & 0 deletions include/occa/experimental/kernelBuilder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ namespace occa {

occa::kernel getOrBuildKernel(const occa::scope &scope);

void run();
void run(const occa::scope &scope);

void free();
Expand Down
4 changes: 2 additions & 2 deletions include/occa/functional/array.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ namespace occa {
TM max() const {
return reduce<TM>(
reductionType::max,
OCCA_FUNCTION({}, [=](TM currentMax, TM value) -> TM {
OCCA_FUNCTION([=](TM currentMax, TM value) -> TM {
return currentMax > value ? currentMax : value;
})
);
Expand All @@ -477,7 +477,7 @@ namespace occa {
TM min() const {
return reduce<TM>(
reductionType::min,
OCCA_FUNCTION({}, [=](TM currentMin, TM value) -> TM {
OCCA_FUNCTION([=](TM currentMin, TM value) -> TM {
return currentMin < value ? currentMin : value;
})
);
Expand Down
2 changes: 2 additions & 0 deletions include/occa/functional/scope.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ namespace occa {

scope();

scope(occa::device device_);

scope(scopeKernelArgInitializerList args_,
const occa::json &props_ = occa::json());

Expand Down
18 changes: 17 additions & 1 deletion include/occa/functional/utils.hpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,28 @@
#ifndef OCCA_FUNCTIONAL_UTILS_HEADER
#define OCCA_FUNCTIONAL_UTILS_HEADER

#include <occa/defines/macros.hpp>
#include <occa/functional/types.hpp>
#include <occa/functional/scope.hpp>

#define OCCA_FUNCTION(scope, lambda) \
#define OCCA_FUNCTION_2(scope, lambda) \
::occa::functional::inferFunction(scope, lambda, #lambda)

#define OCCA_FUNCTION_1(lambda) \
::occa::functional::inferFunction({}, lambda, #lambda)

#define OCCA_FUNCTION(...) \
OCCA_FUNCTION_EXPAND_1(OCCA_ARG_COUNT(__VA_ARGS__), __VA_ARGS__)

#define OCCA_FUNCTION_EXPAND_1(ARG_COUNT, ...) \
OCCA_FUNCTION_EXPAND_2(ARG_COUNT, __VA_ARGS__)

#define OCCA_FUNCTION_EXPAND_2(ARG_COUNT, ...) \
OCCA_FUNCTION_EXPAND_3(ARG_COUNT, __VA_ARGS__)

#define OCCA_FUNCTION_EXPAND_3(ARG_COUNT, ...) \
OCCA_FUNCTION_ ## ARG_COUNT (__VA_ARGS__)

namespace occa {
template <class Function>
class function;
Expand Down
2 changes: 1 addition & 1 deletion src/functional/range.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ namespace occa {

//---[ Utility methods ]--------------
array<int> range::toArray() const {
return map(OCCA_FUNCTION({}, [=](int index) -> int {
return map(OCCA_FUNCTION([=](int index) -> int {
return index;
}));
}
Expand Down
3 changes: 3 additions & 0 deletions src/functional/scope.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
namespace occa {
scope::scope() {}

scope::scope(occa::device device_) :
device(device_) {}

scope::scope(scopeKernelArgInitializerList args_,
const occa::json &props_) :
props(props_) {
Expand Down
Loading