-
Notifications
You must be signed in to change notification settings - Fork 366
[STF] stackable stf resources #2674
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
Open
caugonnet
wants to merge
631
commits into
NVIDIA:main
Choose a base branch
from
caugonnet:stackable_ctx_data
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+10,057
−245
Open
Changes from 32 commits
Commits
Show all changes
631 commits
Select commit
Hold shift + click to select a range
30576a3
unit test to detect inconsistent access modes in stackable ctx
caugonnet eead229
Detect erroneous accesses
caugonnet d16ee51
check that virtual nodes are using data appropriately too
caugonnet 6be49a7
fix programming error
caugonnet 721cbd1
Add a new test that could simulate how we implement while nodes in st…
caugonnet e46997a
Define virtual methods to detect if we have a graph context, and star…
caugonnet 579baf5
Extract the insert_graph in a dedicated header
caugonnet 9276df9
clang-format
caugonnet 2455266
example as a preparatory work to use reductions to create condition h…
caugonnet 50b319a
define wait and reduce methods on stackable_logical_data (WIP)
caugonnet b59ceb3
Allow access_mode::reduce{_no_init} in stackable_ctx
caugonnet 0a06b8b
Make sure that the reduce access mode in parallel_for works with grap…
caugonnet 140a373
Bug fix ! there was a confusion between block and grid sizes
caugonnet a0da9e7
Do use a stackable_ctx in this test
caugonnet 99d6bcc
add missing cuda_safe_call
caugonnet 8c67453
Replace explicit allocations by calls to the uncached allocator
caugonnet d124172
Add missing file
caugonnet aab5241
- Use a different implementation of internal ctx nodes in stackable b…
caugonnet c4346c7
use push/pop rather than scope
caugonnet 70f781e
Add const qualifiers and expose the backend ctx
caugonnet f1c9063
add missing header
caugonnet 6ed5ca8
refactor for nested ctx again
caugonnet 4922653
Move file to a better location
caugonnet f1c5537
remove an inappropriate assertion, and minor code cleanup
caugonnet a006410
First prototype of push_while
caugonnet 08a2fba
more work with while loops
caugonnet 8743bc1
Experiments with while loops
caugonnet 389fff3
Merge branch 'main' into stackable_ctx_data
caugonnet 9246f12
Merge branch 'main' into stackable_ctx_data
caugonnet ee8b6a7
Add tests to make sure task_deps are movable, copyable...
caugonnet 8e4270d
clang-format
caugonnet 9e24884
Save WIP with update cond helper
caugonnet 41d8aa1
better implementation of update_cond
caugonnet 1521ea5
change default value to 1, since a 0 value means the loop cannot exec…
caugonnet c72f88b
Merge branch 'main' into stackable_ctx_data
caugonnet 333fe12
clang-format
caugonnet cad53e6
Make sure the push_while API is only enabled with CUDA 12.4 and above
caugonnet 3d03c4a
Implement an RAII construct to perform loops
caugonnet 9a54090
fix implementation of the repeat guard construct
caugonnet 2689116
Add an FDTD example with repeat (temporary)
caugonnet 1daadb3
cleanups and formatting
caugonnet 35b45b8
Merge branch 'main' into stackable_ctx_data
caugonnet f08e92b
We cannot put extended lambdas in unit tests, and properly define whe…
caugonnet 254cc07
misplaced ifdef
caugonnet c6d7569
fix unit tests
caugonnet 9480518
add missing header
caugonnet c54b498
fix unused variable
caugonnet 39b1f56
Merge branch 'main' into stackable_ctx_data
caugonnet 3ab836d
fix unused warning
caugonnet 114de09
fix unused warning again
caugonnet a81a269
remove experiment with extract graph
caugonnet 48fa248
fix unused argc argv if waived
caugonnet 7e1fc57
Comment to explain why it's complicated to do ctx.task in stackable_ctx
caugonnet 1bf7825
clang-format
caugonnet 950743a
- Move insert_graph utility
caugonnet 8c0ac6c
Reimplement insert_graph_node which was erased
caugonnet 2f5e496
Start to refactor how we implement nested contexts
caugonnet 6db1fb2
do no try to use conditional nodes unless CUDA 12.4+
caugonnet 7360828
Remove previous virtual_node approach
caugonnet 855f7b8
defer the creation of child graphs until later
caugonnet 1721570
Introduce a new test with nested while loops
caugonnet 8d31202
Fix example with nested while (still WIP)
caugonnet 963409b
remove remaining bits of virtual ctx nodes
caugonnet c0e7d23
Do not clone a graph to a child graph, directly fill the child graph
caugonnet 8a888b6
Fix the implementation of conditional nodes to reset them after they …
caugonnet 772f708
Merge branch 'main' into stackable_ctx_data
caugonnet 68cfc74
Fix bounds
caugonnet a0c4ac6
Fix input dependencies when there are more than 1
caugonnet d6fbd18
Waive tests with conditional nodes before 12.4
caugonnet 9ca5a09
Remove some tests which are broken for now
caugonnet 2d89324
clang-format
caugonnet c6a0abf
waive pagerank test if cuda <12.4
caugonnet 69d08d6
wait and fence can't be done in a nested context
caugonnet b997a89
Fix bug with missing __device__ annotations, and add a test where we …
caugonnet 79678fe
fix unused variable warnings
caugonnet b5fb189
Stream adapters are not cleared directly when we have nested contexts…
caugonnet 1ae04d4
Merge branch 'main' into stackable_ctx_data
caugonnet 22c6072
Add a unit test that uses an host exec place on a task with stackable…
caugonnet 809c449
Deal with the execution place in deferred tasks
caugonnet 5220a03
Fix how we get the default exec place in task
caugonnet 2848aa6
Merge branch 'main' into stackable_ctx_data
caugonnet fd3dca2
Remove graph_utilities.cuh and reimplement the freeze_while_graphs_2.…
caugonnet 6a52ea7
Remove dead code
caugonnet 47786f6
fix compilation errors
caugonnet f194afd
while and repeat guards need nvcc
caugonnet ae24701
Remove a reference on a const data
caugonnet d44a52b
remove a test on exception because we don't handle them
caugonnet f04dec4
Merge branch 'main' into stackable_ctx_data
caugonnet 48d6336
Remove debug prints
caugonnet a3d0a8e
Rename defaultLaunchValue to default_launch_value
caugonnet a174d0b
Rely on finalize again to instantiate the root graph (and use a cache…
caugonnet 748f7b3
Merge branch 'main' into stackable_ctx_data
caugonnet 8b6c697
Fix the synchronization mechanism used in freeze_while_graph_2 test
caugonnet a284911
provide export/import resources in context
caugonnet b8fefdc
For non nested contexts, the finalize step did release resources, no …
caugonnet 66e8d10
easier to verify test
caugonnet e4e957f
Merge branch 'main' into stackable_ctx_data
caugonnet b994059
minor test cleanup
caugonnet fb2387b
revert a previous change, we cannot use finalize directly because the…
caugonnet 4a7c56d
Workaround broken tests on NVHPC
caugonnet 4d030bc
Merge branch 'main' into stackable_ctx_data
caugonnet ebfab1a
Fixes and uniformization of jacobi examples (pfor and update_cond)
caugonnet 366779f
Move stackable_ctx.cuh to a new directory
caugonnet 27b7c35
Start to split stackable_ctx.cuh into multiple files
caugonnet c892602
clang-format
caugonnet 24d725e
Extract stackable_ctx impl
caugonnet 9eb9326
clang-format
caugonnet a112667
frozen_logical_data<T> now inherits from frozen_logical_data_untyped
caugonnet e58ad48
Implement a ctx.freeze method for untyped objects
caugonnet 8e76ebd
clang-format
caugonnet 10632c9
minor cleanups
caugonnet a8dd2fe
Allow extra link_libs for header test link checks, add driver for stf.
alliepiper f48bdfb
Merge branch 'stf_frozen_untyped' into stackable_ctx_data
caugonnet e644a3b
Add missing const in logical_data_untyped::read()
caugonnet 41e3fc7
Implement stackable_logical_data_untyped
caugonnet 0efbfea
overload set_symbol
caugonnet c4050bb
Revert "overload set_symbol"
caugonnet b834061
Revert "Implement stackable_logical_data_untyped"
caugonnet 1c3c893
Automatically include stackable_ctx.cuh from stf.cuh
caugonnet 80882c9
More realistic Sparse CG
caugonnet 495ce68
Implement Sparse CG with a while node, this required fixing a bug in …
caugonnet 5995840
clang-format
caugonnet 4413581
Merge branch 'main' into stackable_ctx_data
caugonnet bdb5c50
Fix wrongly formed constructor
caugonnet e98c3be
remove useless header
caugonnet 2ca36c3
Remove a test not needed
caugonnet 99f1828
Fix headers
caugonnet 3d0c958
Merge branch 'main' into stackable_ctx_data
caugonnet 5a78826
Waive cg_csr_stackable test for CUDA < 12.4
caugonnet 9f8d954
Merge branch 'main' into stackable_ctx_data
caugonnet 2441e83
more protection against undefined features on CUDA < 12.4
caugonnet 424af80
Select parameters for jacobi that should converge fast for the sake o…
caugonnet 908c8de
Merge branch 'main' into stackable_ctx_data
caugonnet 05443a2
Start to adapt a cuda sample to show how this is done with STF
caugonnet 7a2fdb5
Adapt more of the cuda sample with conditional graphs
caugonnet eedccc3
extend the example with cuda_kernel constructs
caugonnet 64cda5c
Burger equation
caugonnet cec337c
Reduce the amount of prints
caugonnet ca980b0
Add symbol
caugonnet 17c920f
Add a script to cleanup the DOT files generated by CUDA graph API
caugonnet 00979e6
apply cu++filt
caugonnet ec212a4
clang-format
caugonnet 6381f2b
Save WIP with Burger solver
caugonnet e3c2313
Use a cudaGraph_t and not a shared_ptr to a cudaGraph_t to query if w…
caugonnet 198de53
Try to use cached graphs
caugonnet 8565b4a
Merge branch 'main' into stackable_ctx_data
caugonnet 587f309
Only enable graphConditionalNodes example for CUDA >= 12.4
caugonnet 723d914
Repeat the same nested context to ensure we have to reinstantiate graphs
caugonnet f954c14
Temporary work-around to avoid a CUDA graph bug
caugonnet e16d4b3
add ctx.launch for stackable_ctx
caugonnet 4d92ec8
declare data where the need to be
caugonnet d134a44
Merge branch 'main' into stackable_ctx_data
caugonnet 7be2ff6
start to restructure newton/burger example
caugonnet 5f0cfd1
generic newton solver
caugonnet 15acd5d
Pagerank batched example
caugonnet e3f3490
More general burger examples
caugonnet 1da2239
CUDASTF_DEBUG_STACKABLE_DOT only prints the instantiable graph
caugonnet 2914044
Improve examples
caugonnet 8107630
instrument examples
caugonnet 1a00d05
define ctx::logical_data_t<T>
caugonnet 1335a2b
Merge branch 'main' into stackable_ctx_data
caugonnet 2a20564
move CUDA 12.4+ code into ifdef guards
caugonnet 55ab19d
clang-format
caugonnet e316290
take into account cuda13 changes in graph API
caugonnet 1260861
Merge branch 'main' into stackable_ctx_data
caugonnet 70fc9d6
get_ready_dependencies is dead code
caugonnet 1b38ec6
Merge branch 'main' into stackable_ctx_data
caugonnet 52097f0
Merge branch 'main' into stackable_ctx_data
caugonnet 2ee8717
Merge branch 'main' into stackable_ctx_data
caugonnet d6ab5c2
clang-format
caugonnet d78c3e8
No longer use _CUDA_VSTD
caugonnet 9764592
Fix a logic error with CTK filtering in pagerank_batched
caugonnet 50e8dd9
remove unused captured variable
caugonnet 3b80cd7
Merge branch 'main' into stackable_ctx_data
caugonnet b9bf978
Merge branch 'main' into stackable_ctx_data
caugonnet d79d621
API to import resources from a context rather than to import(mv)/export
caugonnet 293f992
Remove unnecessary cmake change
caugonnet 8e64583
Merge branch 'main' into stackable_ctx_data
caugonnet a54033b
Remove task input nodes which have never been used and which are effe…
caugonnet 8e3f74c
Simpler code without debug leftovers
caugonnet ba83a97
fix a concurrency issue
caugonnet 29dde3f
Remove unused variable
caugonnet 11a30c6
Remove a useless variadic template parameter
caugonnet c6ef2e2
Merge branch 'main' into stackable_ctx_data
caugonnet f49cd29
Add some debug for stackable_ctx heads
caugonnet b4d57ee
Merge branch 'main' into stackable_ctx_data
caugonnet 5227029
Merge branch 'main' into stackable_ctx_data
caugonnet 43c13c6
Merge branch 'main' into stackable_ctx_data
caugonnet e2ff95a
Merge branch 'main' into stackable_ctx_data
caugonnet 9b0bab1
Fix header path
caugonnet f0a0970
Merge branch 'main' into stackable_ctx_data
caugonnet a449392
Merge branch 'main' into stackable_ctx_data
caugonnet cd47ea9
Merge branch 'main' into stackable_ctx_data
caugonnet f7ad3c5
Merge branch 'main' into stackable_ctx_data
caugonnet 4d3add9
Merge branch 'main' into stackable_ctx_data
caugonnet c1f5477
Merge branch 'main' into stackable_ctx_data
caugonnet a333433
[STF] Refactor stackable_task_dep to lazy resolution
caugonnet e079ef6
Rename access_mode_is_compatible to access_mode_permits and handle al…
caugonnet e587dcb
clang-format
caugonnet 9cdb247
Merge branch 'main' into stackable_ctx_data
caugonnet ea52412
Remove dead code
caugonnet aab737f
Merge branch 'main' into stackable_ctx_data
caugonnet 8677364
fix access_mode_permits for write-only access
caugonnet cca428e
Merge branch 'main' into stackable_ctx_data
caugonnet 33c6f34
Fix access_mode_permits and repeat_graph_scope_guard destruction order
caugonnet da2243e
Fix dummy_graph leak in graph_ctx_node constructor
caugonnet 2fb2393
Fix set_write_back to use data_root_offset instead of hardcoded 0
caugonnet 0655141
Initialize get_cnt to 0 in data_node
caugonnet cac496d
Enable correctness assertion in stackable_nested_repeat test
caugonnet 0554463
Implement node_hierarchy growth and fix head_map thread safety
caugonnet 8325b22
clang-format
caugonnet 5e4cdab
Remove redundant optional wrapper around unique_ptr in nodes vector
caugonnet bc601cb
Unify access-mode combining logic with shared helpers
caugonnet 71f6c4f
Document why deferred_task_builder is needed
caugonnet c573637
Remove superfluous const/mutable from deferred_task_builder
caugonnet 0a30c31
Add comment explaining why deferred_task_builder stores a reference
caugonnet fa87356
Extract node_hierarchy into its own header
caugonnet 0147c01
Make warning_count thread-safe with std::atomic
caugonnet 144299f
Remove no-op data_node destructor
caugonnet c9aafee
Remove unused was_destroyed flag from stackable_logical_data state
caugonnet 40a8f60
Remove dead code: unused parent_depth, commented-out debug fprintf
caugonnet d5452b6
Remove dead print_logical_data_summary and traverse_nodes
caugonnet 459b96b
Remove unused deferred_arg_info struct
caugonnet c486b99
Remove commented-out offset_depth variable
caugonnet 156e5d4
Fix ~impl destroying wrong data_node via pop_back
caugonnet 7593a91
Replace inline bounds-check + has_value with was_imported()
caugonnet 9f6460c
Merge branch 'main' into stackable_ctx_data
caugonnet 6d82683
Simplify access_mode_permits to a mutating-implies-mutating check
caugonnet f5755d4
Make get_head_offset() always abort on missing thread context
caugonnet ba8d456
Remove const/mutable abuse from stackable_logical_data state
caugonnet de58572
Remove redundant public: label in deferred_task_builder
caugonnet bdb6385
Use node_hierarchy growth constants in grow_data_nodes
caugonnet e3ee676
Remove unused manual lock/unlock methods from impl
caugonnet 19719cc
Minor formatting cleanup in node_hierarchy and stackable test
caugonnet 4bcfd6c
Fix copy-paste EXPECT value in stackable_illegal_export
caugonnet 2593305
Clean up stackable tests and examples
caugonnet 8ca6f6e
Fix ~impl: do not destroy root data_node while frozen_ld may be active
caugonnet 69d714b
Merge branch 'main' into stackable_ctx_data
caugonnet 8864e7b
Add result validation to graph_scope_test
caugonnet c55c3bc
Add error tests for fence() and wait() in nested stackable context
caugonnet 140017d
Add focused test for stackable_logical_data::set_read_only
caugonnet f7c3c19
Add minimal iterative solver example using while_graph_scope
caugonnet 457cde8
Fix wait-in-nested error test to use scalar_view
caugonnet a951fb8
Remove stackable DESIGN.md from tracked files
caugonnet 035425a
Extract scope guards from stackable_ctx class body
caugonnet 7f486e5
Fix scope guard ordering: define guards before inline unit tests
caugonnet 30ffa9e
Less compute intensive default burger parameters to avoid 20 minutes …
caugonnet 5c8f6f0
Merge branch 'main' into stackable_ctx_data
caugonnet 47c36a5
Move dot_cleanup.py from benchmarks/scripts/ to cudax/scripts/stf/
caugonnet 6699386
Merge branch 'main' into stackable_ctx_data
caugonnet File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,247 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // Part of CUDASTF in CUDA C++ Core Libraries, | ||
| // under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // SPDX-FileCopyrightText: Copyright (c) 2024-2024 NVIDIA CORPORATION & AFFILIATES. | ||
caugonnet marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| /** | ||
| * @file | ||
| * @brief A toy example to illustrate how we can compose logical operations over encrypted data | ||
| */ | ||
|
|
||
| #include "cuda/experimental/__stf/utility/stackable_ctx.cuh" | ||
| #include "cuda/experimental/stf.cuh" | ||
caugonnet marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| using namespace cuda::experimental::stf; | ||
|
|
||
| class ciphertext; | ||
|
|
||
| class plaintext | ||
| { | ||
| public: | ||
| plaintext(const stackable_ctx& ctx) | ||
| : ctx(ctx) | ||
| {} | ||
|
|
||
| plaintext(stackable_ctx& ctx, ::std::vector<char> v) | ||
| : values(mv(v)) | ||
| , ctx(ctx) | ||
| { | ||
| l = ctx.logical_data(values.data(), values.size()); | ||
caugonnet marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| void set_symbol(std::string s) | ||
| { | ||
| l.set_symbol(s); | ||
| symbol = s; | ||
| } | ||
|
|
||
| std::string get_symbol() const | ||
| { | ||
| return symbol; | ||
| } | ||
|
|
||
| std::string symbol; | ||
|
|
||
| const stackable_logical_data<slice<char>>& data() const | ||
| { | ||
| return l; | ||
| } | ||
|
|
||
| stackable_logical_data<slice<char>>& data() | ||
| { | ||
| return l; | ||
| } | ||
|
|
||
| // This will asynchronously fill string s | ||
| void convert_to_vector(std::vector<char>& v) | ||
| { | ||
| ctx.host_launch(l.read()).set_symbol("to_vector")->*[&](auto dl) { | ||
| v.resize(dl.size()); | ||
| for (size_t i = 0; i < dl.size(); i++) | ||
| { | ||
| v[i] = dl(i); | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| ciphertext encrypt() const; | ||
|
|
||
| stackable_logical_data<slice<char>> l; | ||
caugonnet marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| template <typename... Pack> | ||
| void push(Pack&&... pack) | ||
|
||
| { | ||
| l.push(::std::forward<Pack>(pack)...); | ||
| } | ||
|
|
||
| void pop() | ||
| { | ||
| l.pop(); | ||
| } | ||
|
|
||
| private: | ||
| std::vector<char> values; | ||
| mutable stackable_ctx ctx; | ||
| }; | ||
|
|
||
| class ciphertext | ||
| { | ||
| public: | ||
| ciphertext() = default; | ||
| ciphertext(const ciphertext&) = default; | ||
|
|
||
| ciphertext(const stackable_ctx& ctx) | ||
| : ctx(ctx) | ||
| {} | ||
|
|
||
| plaintext decrypt() const | ||
| { | ||
| plaintext p(ctx); | ||
| p.l = ctx.logical_data(shape_of<slice<char>>(l.shape().size())); | ||
| ctx.parallel_for(l.shape(), l.read(), p.l.write()).set_symbol("decrypt")->* | ||
| [] __device__(size_t i, auto dctxt, auto dptxt) { | ||
| dptxt(i) = char((dctxt(i) >> 32)); | ||
| }; | ||
| return p; | ||
| } | ||
|
|
||
| // Copy assignment operator | ||
| ciphertext& operator=(const ciphertext& other) | ||
| { | ||
| if (this != &other) | ||
| { | ||
| assert(l.shape() == other.l.shape()); | ||
caugonnet marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| other.ctx.parallel_for(l.shape(), other.l.read(), l.write()).set_symbol("copy")->* | ||
| [] __device__(size_t i, auto other, auto result) { | ||
| result(i) = other(i); | ||
| }; | ||
| } | ||
| return *this; | ||
| } | ||
|
|
||
| ciphertext operator|(const ciphertext& other) const | ||
| { | ||
| ciphertext result(ctx); | ||
| result.l = ctx.logical_data(data().shape()); | ||
|
|
||
| ctx.parallel_for(data().shape(), data().read(), other.data().read(), result.data().write()).set_symbol("OR")->* | ||
| [] __device__(size_t i, auto d_c1, auto d_c2, auto d_res) { | ||
| d_res(i) = d_c1(i) | d_c2(i); | ||
| }; | ||
|
|
||
| return result; | ||
| } | ||
|
|
||
| ciphertext operator&(const ciphertext& other) const | ||
| { | ||
| ciphertext result(ctx); | ||
| result.l = ctx.logical_data(data().shape()); | ||
|
|
||
| ctx.parallel_for(data().shape(), data().read(), other.data().read(), result.data().write()).set_symbol("AND")->* | ||
| [] __device__(size_t i, auto d_c1, auto d_c2, auto d_res) { | ||
| d_res(i) = d_c1(i) & d_c2(i); | ||
| }; | ||
|
|
||
| return result; | ||
| } | ||
|
|
||
| ciphertext operator~() const | ||
| { | ||
| ciphertext result(ctx); | ||
| result.l = ctx.logical_data(data().shape()); | ||
| ctx.parallel_for(data().shape(), data().read(), result.data().write()).set_symbol("NOT")->* | ||
| [] __device__(size_t i, auto d_c, auto d_res) { | ||
| d_res(i) = ~d_c(i); | ||
| }; | ||
|
|
||
| return result; | ||
| } | ||
|
|
||
| const stackable_logical_data<slice<uint64_t>>& data() const | ||
| { | ||
| return l; | ||
| } | ||
|
|
||
| stackable_logical_data<slice<uint64_t>>& data() | ||
| { | ||
| return l; | ||
| } | ||
|
|
||
| stackable_logical_data<slice<uint64_t>> l; | ||
|
|
||
| template <typename... Pack> | ||
| void push(Pack&&... pack) | ||
|
||
| { | ||
| l.push(::std::forward<Pack>(pack)...); | ||
| } | ||
|
|
||
| void pop() | ||
| { | ||
| l.pop(); | ||
| } | ||
|
|
||
| private: | ||
| mutable stackable_ctx ctx; | ||
| }; | ||
|
|
||
| ciphertext plaintext::encrypt() const | ||
| { | ||
| ciphertext c(ctx); | ||
| c.l = ctx.logical_data(shape_of<slice<uint64_t>>(l.shape().size())); | ||
|
|
||
| ctx.parallel_for(l.shape(), l.read(), c.l.write()).set_symbol("encrypt")->* | ||
| [] __device__(size_t i, auto dptxt, auto dctxt) { | ||
| // A super safe encryption ! | ||
| dctxt(i) = ((uint64_t) (dptxt(i)) << 32 | 0x4); | ||
| }; | ||
|
|
||
| return c; | ||
| } | ||
|
|
||
| template <typename T> | ||
| T circuit(const T& a, const T& b) | ||
| { | ||
| return (~((a | ~b) & (~a | b))); | ||
| } | ||
|
|
||
| int main() | ||
| { | ||
| stackable_ctx ctx; | ||
|
|
||
| std::vector<char> vA{3, 3, 2, 2, 17}; | ||
| plaintext pA(ctx, vA); | ||
| pA.set_symbol("A"); | ||
|
|
||
| std::vector<char> vB{1, 7, 7, 7, 49}; | ||
| plaintext pB(ctx, vB); | ||
| pB.set_symbol("B"); | ||
|
|
||
| auto eA = pA.encrypt(); | ||
| auto eB = pB.encrypt(); | ||
|
|
||
| ctx.push(); | ||
|
|
||
| eA.push(access_mode::read); | ||
| eB.push(access_mode::read); | ||
|
|
||
| // TODO find a way to get "out" outside of this scope to do decryption in the main ctx | ||
| auto out = circuit(eA, eB); | ||
|
|
||
| std::vector<char> v_out; | ||
| out.decrypt().convert_to_vector(v_out); | ||
|
|
||
| ctx.pop(); | ||
|
|
||
| ctx.finalize(); | ||
|
|
||
| for (size_t i = 0; i < v_out.size(); i++) | ||
| { | ||
| char expected = circuit(vA[i], vB[i]); | ||
| EXPECT(expected == v_out[i]); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.