diff options
| author | Tomas Jusko | 2022-01-29 21:04:05 +0100 |
|---|---|---|
| committer | Tomas Jusko | 2022-01-29 21:04:05 +0100 |
| commit | ef859d7823161fd579a62b8e80ceb6b9cf721d44 (patch) | |
| tree | 4585118e124d2743e7d56f605ee1353a639d7308 | |
| parent | 321f2e9d1d3942e56da98c87b7df806d31210348 (diff) | |
| download | pyecsca-ef859d7823161fd579a62b8e80ceb6b9cf721d44.tar.gz pyecsca-ef859d7823161fd579a62b8e80ceb6b9cf721d44.tar.zst pyecsca-ef859d7823161fd579a62b8e80ceb6b9cf721d44.zip | |
Removed garbage
| -rw-r--r-- | pyecsca/sca/stacked_traces/stacked_traces.py | 69 | ||||
| -rw-r--r-- | test/sca/test_stacked_combine.py | 14 |
2 files changed, 17 insertions, 66 deletions
diff --git a/pyecsca/sca/stacked_traces/stacked_traces.py b/pyecsca/sca/stacked_traces/stacked_traces.py index 7af96e3..d63fe00 100644 --- a/pyecsca/sca/stacked_traces/stacked_traces.py +++ b/pyecsca/sca/stacked_traces/stacked_traces.py @@ -1,8 +1,8 @@ -from numba import cuda, float32 +from numba import cuda import numpy as np from public import public -from typing import Any, Iterable, Mapping, MutableSequence, Optional -from math import ceil, sqrt +from typing import Any, Mapping, MutableSequence +from math import sqrt TPB = 128 @@ -81,11 +81,6 @@ class GPUTraceManager: @cuda.jit(device=True) def _gpu_average(col: int, samples: np.ndarray, result: np.ndarray): - # col = cuda.grid(1) - - # if col >= samples.shape[1]: - # return - acc = 0. for row in range(samples.shape[0]): acc += samples[row, col] @@ -113,23 +108,8 @@ def _gpu_var_from_avg(col: int, samples: np.ndarray, averages: np.ndarray, resul @cuda.jit(device=True) def _gpu_variance(col: int, samples: np.ndarray, result: np.ndarray): - # col = cuda.grid(1) - - # if col >= samples.shape[1]: - # return - - # avg = 0. - # for row in range(samples.shape[0]): - # avg += samples[row, col] - # avg /= samples.shape[0] - _gpu_average(col, samples, result) _gpu_var_from_avg(col, samples, result, result) - # var = 0. - # for row in range(samples.shape[0]): - # current = samples[row, col] - result[col] - # var += current * current - # result[col] = var / samples.shape[0] @cuda.jit @@ -139,17 +119,6 @@ def gpu_std_dev(samples: np.ndarray, result: np.ndarray): if col >= samples.shape[1]: return - # avg = 0. - # for row in range(samples.shape[0]): - # avg += samples[row, col] - # avg /= samples.shape[0] - - # var = 0. - # for row in range(samples.shape[0]): - # current = samples[row, col] - result[col] - # var += current * current - # result[col] = sqrt(var / samples.shape[0]) - _gpu_variance(col, samples, result) result[col] = sqrt(result[col]) @@ -172,21 +141,10 @@ def gpu_avg_var(samples: np.ndarray, result_avg: np.ndarray, if col >= samples.shape[1]: return - - # avg = 0. - # for row in range(samples.shape[0]): - # avg += samples[row, col] - # avg /= samples.shape[0] _gpu_average(samples, result_avg) _gpu_var_from_avg(col, samples, result_avg, result_var) - # var = 0. - # for row in range(samples.shape[0]): - # current = samples[row, col] - result_avg[col] - # var += current * current - # result_var[col] = var / samples.shape[0] - @cuda.jit def gpu_add(samples: np.ndarray, result: np.ndarray): @@ -210,24 +168,3 @@ def gpu_subtract(samples_one: np.ndarray, samples_other: np.ndarray, return result[col] = samples_one[col] - samples_other[col] - - -def test_average(): - samples = np.random.rand(4 * TPB, 8 * TPB) - ts = StackedTraces.fromarray(np.array(samples)) - res = GPUTraceManager.average(ts) - check_res = samples.sum(0) / ts.traces.shape[0] - print(all(check_res == res)) - - -def test_standard_deviation(): - samples: np.ndarray = np.random.rand(4 * TPB, 8 * TPB) - ts = StackedTraces.fromarray(np.array(samples)) - res = GPUTraceManager.standard_deviation(ts) - check_res = samples.std(0, dtype=samples.dtype) - print(all(np.isclose(res, check_res))) - - -if __name__ == '__main__': - test_average() - test_standard_deviation() diff --git a/test/sca/test_stacked_combine.py b/test/sca/test_stacked_combine.py index d319e5a..41e2153 100644 --- a/test/sca/test_stacked_combine.py +++ b/test/sca/test_stacked_combine.py @@ -30,3 +30,17 @@ class StackedCombineTests(TestCase): (self.samples.shape[0], min_len) ) self.assertTrue((stacked.samples, self.samples[:,:min_len]).all()) + + # def test_average(): + # samples = np.random.rand(4 * TPB, 8 * TPB) + # ts = StackedTraces.fromarray(np.array(samples)) + # res = GPUTraceManager.average(ts) + # check_res = samples.sum(0) / ts.traces.shape[0] + # print(all(check_res == res)) + + # def test_standard_deviation(): + # samples: np.ndarray = np.random.rand(4 * TPB, 8 * TPB) + # ts = StackedTraces.fromarray(np.array(samples)) + # res = GPUTraceManager.standard_deviation(ts) + # check_res = samples.std(0, dtype=samples.dtype) + # print(all(np.isclose(res, check_res)))
\ No newline at end of file |
