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

[Functional] Adds occa::function and occa::array #442

Merged
merged 20 commits into from
Jan 17, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
[Examples] Update array example, remove kernel builder example
  • Loading branch information
dmed256 committed Jan 17, 2021
commit eb5bfb59fab58342c4d55ab495917747318f24a1
File renamed without changes.
File renamed without changes.
93 changes: 93 additions & 0 deletions examples/cpp/05_arrays/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#include <iostream>

#include <occa.hpp>
#include <occa/experimental.hpp>

//---[ Internal Tools ]-----------------
// Note: These headers are not officially supported
// Please don't rely on it outside of the occa examples
#include <occa/internal/utils/cli.hpp>
#include <occa/internal/utils/testing.hpp>
//======================================

occa::json parseArgs(int argc, const char **argv);

int main(int argc, const char **argv) {
occa::json args = parseArgs(argc, argv);

occa::setDevice((std::string) args["options/device"]);

int entries = 5;

float *a = new float[entries];
float *b = new float[entries];
float *ab = new float[entries];

for (int i = 0; i < entries; ++i) {
a[i] = i;
b[i] = 1 - i;
ab[i] = 0;
}

// Uses the background device
occa::array<float> array_a(10);
occa::array<float> array_b(10);

// Copy over host data
array_a.copyFrom(a);
array_b.copyFrom(b);

// Capture the array b
occa::scope scope({
{"b", array_b}
});

occa::array<float> array_ab = array_a.map(OCCA_FUNCTION(
scope,
[=](float value, int index) -> float {
return value + b[index];
}
));

array_ab.copyTo(ab);

// Assert values
for (int i = 0; i < entries; ++i) {
std::cout << i << ": " << ab[i] << '\n';
}
for (int i = 0; i < entries; ++i) {
if (!occa::areBitwiseEqual(ab[i], a[i] + b[i])) {
throw 1;
}
}

// Free host memory
delete [] a;
delete [] b;
delete [] ab;

return 0;
}

occa::json parseArgs(int argc, const char **argv) {
occa::cli::parser parser;
parser
.withDescription(
"Example using occa::array with inline lambdas"
)
.addOption(
occa::cli::option('d', "device",
"Device properties (default: \"{mode: 'Serial'}\")")
.withArg()
.withDefaultValue("{mode: 'Serial'}")
)
.addOption(
occa::cli::option('v', "verbose",
"Compile kernels in verbose mode")
);

occa::json args = parser.parseArgs(argc, argv);
occa::settings()["kernel/verbose"] = args["options/verbose"];

return args;
}
1 change: 0 additions & 1 deletion examples/cpp/05_building_kernels/CMakeLists.txt

This file was deleted.

24 changes: 0 additions & 24 deletions examples/cpp/05_building_kernels/README.md

This file was deleted.

134 changes: 0 additions & 134 deletions examples/cpp/05_building_kernels/main.cpp

This file was deleted.

9 changes: 0 additions & 9 deletions examples/cpp/06_unified_memory/.gitignore

This file was deleted.

Loading