-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ilya Antonov
committed
Jul 26, 2020
1 parent
0f28432
commit 9ba738c
Showing
8 changed files
with
14,154 additions
and
734 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,76 @@ | ||
"""Potential is plotted for | ||
- Fixed Phi L | ||
- Fixed Phi R | ||
- Minimised phi03 | ||
and for a range of phi02-phi01 values | ||
""" | ||
|
||
from typing import List, Callable, Tuple, Optional | ||
|
||
from numba import cuda | ||
from numba.cuda.cudadrv.devicearray import DeviceNDArray | ||
import numpy as np | ||
|
||
|
||
class PotentialEvaluatedInPhi02Phi02Plane: | ||
def __init__( | ||
self, number_of_phi_points: int, potential_function_cuda: Callable, | ||
): | ||
self.NUMBER_OF_PHI_POINTS = number_of_phi_points | ||
self.potential_function_cuda = potential_function_cuda | ||
|
||
self.kernel = self.kernel_wrapper() | ||
|
||
def kernel_wrapper(self): | ||
NUMBER_OF_PHI_POINTS = self.NUMBER_OF_PHI_POINTS | ||
potential_function_cuda = self.potential_function_cuda | ||
|
||
@cuda.jit | ||
def kernel( | ||
phi01_array: List[float], | ||
phi02_array: List[float], | ||
phi03_array: List[float], | ||
phi_l: float, | ||
phi_r: float, | ||
alpha: float, | ||
array_out: DeviceNDArray, | ||
): | ||
""" | ||
phixx_array: array of the values for phi03 - float32 | ||
phi_l, phi_r: fixed values for the externally applied phase | ||
alpha: variables parameter | ||
array_out: allocate either with cuda.device_array or passing in a numpy array - floa32 | ||
""" | ||
|
||
phi01_idx = cuda.blockIdx.x | ||
phi02_idx = cuda.blockIdx.y | ||
phi03_idx = cuda.threadIdx.x | ||
potential_at_phi03 = cuda.shared.array( | ||
shape=(NUMBER_OF_PHI_POINTS), dtype=np.float32 | ||
) | ||
|
||
# Traverse over all the phi03 values | ||
while phi03_idx < NUMBER_OF_PHI_POINTS: | ||
potential_at_phi03[phi03_idx] = potential_function_cuda( | ||
( | ||
phi01_array[phi01_idx], | ||
phi02_array[phi02_idx], | ||
phi03_array[phi03_idx], | ||
), | ||
phi_l, | ||
phi_r, | ||
alpha, | ||
) | ||
phi03_idx += cuda.blockDim.x | ||
cuda.syncthreads() | ||
|
||
# Then step through and find minimal value | ||
min_potential = potential_at_phi03[0] | ||
for potential in potential_at_phi03[1:]: | ||
if potential < min_potential: | ||
min_potential = potential | ||
|
||
array_out[phi01_idx][phi02_idx] = min_potential | ||
|
||
return kernel |
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
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,51 @@ | ||
import unittest | ||
from unittest.mock import Mock | ||
from unittest.mock import patch | ||
|
||
from kernels.potential_evaluated_in_phi02_phi01_plane import ( | ||
PotentialEvaluatedInPhi02Phi02Plane, | ||
) | ||
from template import mock_potential_function_cuda | ||
import numpy as np | ||
from numba import cuda | ||
|
||
|
||
class TestPotentialEvaluatedInPhi02Phi02Plane(unittest.TestCase): | ||
def setUp(self): | ||
|
||
self.NUMBER_OF_PHI_POINTS = 3 | ||
|
||
self.sut = PotentialEvaluatedInPhi02Phi02Plane( | ||
self.NUMBER_OF_PHI_POINTS, mock_potential_function_cuda, | ||
) | ||
|
||
def tearDown(self): | ||
pass | ||
|
||
def test(self): | ||
phi01_array = np.array([4, 5, 6]) | ||
phi02_array = np.array([4, 5, 6]) | ||
phi03_array = np.array([4, 5, 6]) | ||
alpha = 7 | ||
DEVICE_out_array = cuda.device_array( | ||
shape=(self.NUMBER_OF_PHI_POINTS, self.NUMBER_OF_PHI_POINTS,), | ||
dtype=np.float32, | ||
) | ||
|
||
self.sut.kernel[(self.NUMBER_OF_PHI_POINTS, self.NUMBER_OF_PHI_POINTS), 10,]( | ||
cuda.to_device(phi01_array), | ||
cuda.to_device(phi01_array), | ||
cuda.to_device(phi01_array), | ||
0, | ||
0, | ||
alpha, | ||
DEVICE_out_array, | ||
) | ||
expected = np.array( | ||
[ | ||
[744400, 745400, 746400], | ||
[754400, 755400, 756400], | ||
[764400, 765400, 766400], | ||
] | ||
) | ||
np.all(expected == DEVICE_out_array.copy_to_host()) |
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