-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DAPHNE-#711] Data transfer with numpy for arrays of more than 2 dime…
…nsions - Previously only numpy arrays with 1 or 2 dimensions were supported. - Added support for numpy arrays with more than 2 dimensions. - Implementation is analog to tensorflow and pytorch with a simple reshape to a 2d numpy array. - Added tests for ndim numpy arrays transfers.
- Loading branch information
Showing
5 changed files
with
74 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright 2022 The DAPHNE Consortium | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
m1 = reshape(seq(0, 7), 2, 4); | ||
m2 = reshape(seq(0, 26), 3, 9); | ||
m3 = reshape(seq(0, 31), 2, 16); | ||
print(m1); | ||
print(m2); | ||
print(m3); | ||
|
||
# verify that the original_shapes of DaphneLib, match the returned output | ||
print("(2, 2, 2)"); | ||
print("(3, 3, 3)"); | ||
print("(2, 2, 2, 2, 2)"); |
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 @@ | ||
#!/usr/bin/python | ||
|
||
# Copyright 2022 The DAPHNE Consortium | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# Data transfer from numpy to DAPHNE and back, via shared memory. | ||
|
||
import numpy as np | ||
from daphne.context.daphne_context import DaphneContext | ||
|
||
m1 = np.arange(8).reshape((2,2,2)) | ||
m2 = np.arange(27).reshape((3,3,3)) | ||
m3 = np.arange(32).reshape((2,2,2,2,2)) | ||
|
||
dctx = DaphneContext() | ||
|
||
X, m1_og_shape = dctx.from_numpy(m1, shared_memory=True, return_shape=True) | ||
Y, m2_og_shape = dctx.from_numpy(m2, shared_memory=True, return_shape=True) | ||
Z, m3_og_shape = dctx.from_numpy(m3, shared_memory=True, return_shape=True) | ||
|
||
X.print().compute() | ||
Y.print().compute() | ||
Z.print().compute() | ||
print(m1_og_shape) | ||
print(m2_og_shape) | ||
print(m3_og_shape) |