boostrsa 0.0.1.dev0__tar.gz → 0.0.1.dev3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- boostrsa-0.0.1.dev3/PKG-INFO +76 -0
- boostrsa-0.0.1.dev3/README.md +59 -0
- {boostrsa-0.0.1.dev0 → boostrsa-0.0.1.dev3}/setup.py +3 -2
- boostrsa-0.0.1.dev3/src/boostrsa/boostrsa_types.py +6 -0
- boostrsa-0.0.1.dev3/src/boostrsa/cores/gpu/__init__.py +0 -0
- boostrsa-0.0.1.dev3/src/boostrsa/searchlight.py +233 -0
- boostrsa-0.0.1.dev3/src/boostrsa.egg-info/PKG-INFO +76 -0
- boostrsa-0.0.1.dev3/src/boostrsa.egg-info/SOURCES.txt +21 -0
- boostrsa-0.0.1.dev3/src/boostrsa.egg-info/top_level.txt +1 -0
- boostrsa-0.0.1.dev3/tests/test_module1.py +3 -0
- boostrsa-0.0.1.dev0/PKG-INFO +0 -27
- boostrsa-0.0.1.dev0/README.md +0 -14
- boostrsa-0.0.1.dev0/src/boostrsa.egg-info/PKG-INFO +0 -27
- boostrsa-0.0.1.dev0/src/boostrsa.egg-info/SOURCES.txt +0 -17
- boostrsa-0.0.1.dev0/src/boostrsa.egg-info/top_level.txt +0 -1
- {boostrsa-0.0.1.dev0 → boostrsa-0.0.1.dev3}/LICENSE.txt +0 -0
- {boostrsa-0.0.1.dev0 → boostrsa-0.0.1.dev3}/setup.cfg +0 -0
- {boostrsa-0.0.1.dev0/src/cores → boostrsa-0.0.1.dev3/src/boostrsa}/__init__.py +0 -0
- {boostrsa-0.0.1.dev0/src/cores/cpgpu → boostrsa-0.0.1.dev3/src/boostrsa/cores}/__init__.py +0 -0
- {boostrsa-0.0.1.dev0/src/cores/cpu → boostrsa-0.0.1.dev3/src/boostrsa/cores/cpgpu}/__init__.py +0 -0
- {boostrsa-0.0.1.dev0/src → boostrsa-0.0.1.dev3/src/boostrsa}/cores/cpgpu/stats.py +0 -0
- {boostrsa-0.0.1.dev0/src/cores/gpu → boostrsa-0.0.1.dev3/src/boostrsa/cores/cpu}/__init__.py +0 -0
- {boostrsa-0.0.1.dev0/src → boostrsa-0.0.1.dev3/src/boostrsa}/cores/cpu/matrix.py +0 -0
- {boostrsa-0.0.1.dev0/src → boostrsa-0.0.1.dev3/src/boostrsa}/cores/gpu/basic_operations.py +0 -0
- {boostrsa-0.0.1.dev0/src → boostrsa-0.0.1.dev3/src/boostrsa}/cores/gpu/mask.py +0 -0
- {boostrsa-0.0.1.dev0/src → boostrsa-0.0.1.dev3/src/boostrsa}/cores/gpu/matrix.py +0 -0
- {boostrsa-0.0.1.dev0 → boostrsa-0.0.1.dev3}/src/boostrsa.egg-info/dependency_links.txt +0 -0
- {boostrsa-0.0.1.dev0 → boostrsa-0.0.1.dev3}/src/boostrsa.egg-info/requires.txt +0 -0
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: boostrsa
|
|
3
|
+
Version: 0.0.1.dev3
|
|
4
|
+
Summary: This is toolbox for boosting calculation speed using GPU
|
|
5
|
+
Home-page: https://github.com/SeojinYoon/boostrsa.git
|
|
6
|
+
Author: seojin
|
|
7
|
+
Author-email: pures1@hanyang.ac.kr
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Requires-Python: >=3.8
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE.txt
|
|
14
|
+
Requires-Dist: numpy
|
|
15
|
+
Requires-Dist: pandas
|
|
16
|
+
Requires-Dist: tqdm
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
# Boostrsa
|
|
20
|
+
|
|
21
|
+
This library is based on rsatoolbox(https://github.com/rsagroup/rsatoolbox).
|
|
22
|
+
|
|
23
|
+
The purpose of library is made to boost calcuation speed for searchlight RSA(Representational Similarity Analysis). However, It is still in development, so this library only includes tools for boosting crossnobis distance calculation for constructing RDM(Representational Dissimilartiy Matrix) on the whole brain.
|
|
24
|
+
|
|
25
|
+
## How it works?
|
|
26
|
+
|
|
27
|
+
Basically, this library uses a Nvidia's GPU instead of CPU for parallel processing. In the searchlight analysis, the data targeted for constructing the RDM in volvxes a voxel and its neighboring voxels. That is well-suited for parallel processing since the calculations for each target are independent of one another. This library utilizes GPU-compatible libraries such as Numba and Cupy to facilitate this process.
|
|
28
|
+
|
|
29
|
+
## Dependencies
|
|
30
|
+
|
|
31
|
+
To use this library, you need to have a Nvidia's GPU and CUDA. Additionally, this library heavily relies on Cupy and Numba. It is essential to install the appropriate versions of these libraries.
|
|
32
|
+
|
|
33
|
+
### Cupy
|
|
34
|
+
|
|
35
|
+
Cupy is designed to work with specific versions of CUDA. See cupy's guide and install appropriate version in correspond to your system (https://github.com/cupy/cupy).
|
|
36
|
+
|
|
37
|
+
Please check your cuda version to install cupy.
|
|
38
|
+
- versions
|
|
39
|
+
- cupy-cuda10x (for cuda 10)
|
|
40
|
+
- cupy-cuda11x (for cuda 11)
|
|
41
|
+
- cupy-cuda12x (for cuda 12)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
If you installed the cuda10 in your computer, then install cupy-cuda10x. install cupy-cuda10x. ex) pip install cupy-cuda10x
|
|
45
|
+
|
|
46
|
+
### Numba
|
|
47
|
+
|
|
48
|
+
The numba library is a powerful tool that enbales python functions to be compiled to machine code at runtime using the LLVM. One of its key features is the ability to generate native code for different architectures, including CPUs and GPUs, which greatly accelerates the execution of data-heavy and computationally intense python code.
|
|
49
|
+
|
|
50
|
+
Please see installation guideline of numba (https://numba.pydata.org/numba-doc/latest/user/installing.html).
|
|
51
|
+
|
|
52
|
+
Pip installation).
|
|
53
|
+
- pip install numba
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
## Installation
|
|
57
|
+
|
|
58
|
+
pip install boostrsa
|
|
59
|
+
|
|
60
|
+
# Checked version
|
|
61
|
+
|
|
62
|
+
These are the latest checked environment.
|
|
63
|
+
|
|
64
|
+
- OS
|
|
65
|
+
- Linux, ubuntu - 21.10
|
|
66
|
+
- numba
|
|
67
|
+
- 0.57.0 ~ 0.59.1 is fine to use
|
|
68
|
+
- cupy
|
|
69
|
+
- cupy-cuda11x
|
|
70
|
+
- cupy-cuda12x
|
|
71
|
+
|
|
72
|
+
# Future works
|
|
73
|
+
|
|
74
|
+
- Add calculation sources to get neighbors and centers (boost)
|
|
75
|
+
- Add RSA sources (boost)
|
|
76
|
+
- Support other calculation methods except crossnobis distance
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
|
|
2
|
+
# Boostrsa
|
|
3
|
+
|
|
4
|
+
This library is based on rsatoolbox(https://github.com/rsagroup/rsatoolbox).
|
|
5
|
+
|
|
6
|
+
The purpose of library is made to boost calcuation speed for searchlight RSA(Representational Similarity Analysis). However, It is still in development, so this library only includes tools for boosting crossnobis distance calculation for constructing RDM(Representational Dissimilartiy Matrix) on the whole brain.
|
|
7
|
+
|
|
8
|
+
## How it works?
|
|
9
|
+
|
|
10
|
+
Basically, this library uses a Nvidia's GPU instead of CPU for parallel processing. In the searchlight analysis, the data targeted for constructing the RDM in volvxes a voxel and its neighboring voxels. That is well-suited for parallel processing since the calculations for each target are independent of one another. This library utilizes GPU-compatible libraries such as Numba and Cupy to facilitate this process.
|
|
11
|
+
|
|
12
|
+
## Dependencies
|
|
13
|
+
|
|
14
|
+
To use this library, you need to have a Nvidia's GPU and CUDA. Additionally, this library heavily relies on Cupy and Numba. It is essential to install the appropriate versions of these libraries.
|
|
15
|
+
|
|
16
|
+
### Cupy
|
|
17
|
+
|
|
18
|
+
Cupy is designed to work with specific versions of CUDA. See cupy's guide and install appropriate version in correspond to your system (https://github.com/cupy/cupy).
|
|
19
|
+
|
|
20
|
+
Please check your cuda version to install cupy.
|
|
21
|
+
- versions
|
|
22
|
+
- cupy-cuda10x (for cuda 10)
|
|
23
|
+
- cupy-cuda11x (for cuda 11)
|
|
24
|
+
- cupy-cuda12x (for cuda 12)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
If you installed the cuda10 in your computer, then install cupy-cuda10x. install cupy-cuda10x. ex) pip install cupy-cuda10x
|
|
28
|
+
|
|
29
|
+
### Numba
|
|
30
|
+
|
|
31
|
+
The numba library is a powerful tool that enbales python functions to be compiled to machine code at runtime using the LLVM. One of its key features is the ability to generate native code for different architectures, including CPUs and GPUs, which greatly accelerates the execution of data-heavy and computationally intense python code.
|
|
32
|
+
|
|
33
|
+
Please see installation guideline of numba (https://numba.pydata.org/numba-doc/latest/user/installing.html).
|
|
34
|
+
|
|
35
|
+
Pip installation).
|
|
36
|
+
- pip install numba
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
## Installation
|
|
40
|
+
|
|
41
|
+
pip install boostrsa
|
|
42
|
+
|
|
43
|
+
# Checked version
|
|
44
|
+
|
|
45
|
+
These are the latest checked environment.
|
|
46
|
+
|
|
47
|
+
- OS
|
|
48
|
+
- Linux, ubuntu - 21.10
|
|
49
|
+
- numba
|
|
50
|
+
- 0.57.0 ~ 0.59.1 is fine to use
|
|
51
|
+
- cupy
|
|
52
|
+
- cupy-cuda11x
|
|
53
|
+
- cupy-cuda12x
|
|
54
|
+
|
|
55
|
+
# Future works
|
|
56
|
+
|
|
57
|
+
- Add calculation sources to get neighbors and centers (boost)
|
|
58
|
+
- Add RSA sources (boost)
|
|
59
|
+
- Support other calculation methods except crossnobis distance
|
|
@@ -8,12 +8,13 @@ with open("README.md", "r") as fh:
|
|
|
8
8
|
|
|
9
9
|
setup(
|
|
10
10
|
name = "boostrsa",
|
|
11
|
-
version = "0.0.
|
|
11
|
+
version = "0.0.1dev3",
|
|
12
12
|
author = "seojin",
|
|
13
13
|
author_email = "pures1@hanyang.ac.kr",
|
|
14
14
|
description = "This is toolbox for boosting calculation speed using GPU",
|
|
15
15
|
long_description = long_description,
|
|
16
16
|
long_description_content_type="text/markdown",
|
|
17
|
+
url = "https://github.com/SeojinYoon/boostrsa.git",
|
|
17
18
|
packages = find_packages(where = "src"),
|
|
18
19
|
package_dir = {"": "src"},
|
|
19
20
|
classifiers = [
|
|
@@ -21,7 +22,7 @@ setup(
|
|
|
21
22
|
"License :: OSI Approved :: MIT License",
|
|
22
23
|
"Operating System :: OS Independent",
|
|
23
24
|
],
|
|
24
|
-
python_requires='>=3.
|
|
25
|
+
python_requires='>=3.8',
|
|
25
26
|
install_requires = [
|
|
26
27
|
"numpy",
|
|
27
28
|
"pandas",
|
|
File without changes
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
|
|
2
|
+
# Common Libraries
|
|
3
|
+
import numpy as np
|
|
4
|
+
from numba import cuda, jit
|
|
5
|
+
import cupy as cp
|
|
6
|
+
import itertools
|
|
7
|
+
from tqdm import trange
|
|
8
|
+
|
|
9
|
+
# Custom Libraries
|
|
10
|
+
from boostrsa_types import ShrinkageMethod
|
|
11
|
+
from cores.cpu.matrix import convert_1d_to_symmertic, mean_fold_variance
|
|
12
|
+
from cores.cpgpu.stats import _covariance_diag, _covariance_eye
|
|
13
|
+
from cores.gpu.mask import set_mask
|
|
14
|
+
from cores.gpu.matrix import calc_kernel, rdm_from_kernel
|
|
15
|
+
|
|
16
|
+
# Functions
|
|
17
|
+
def calc_sl_precision(residuals,
|
|
18
|
+
neighbors,
|
|
19
|
+
n_split_data,
|
|
20
|
+
masking_indexes,
|
|
21
|
+
n_thread_per_block = 1024,
|
|
22
|
+
shrinkage_method = "shrinkage_diag"):
|
|
23
|
+
"""
|
|
24
|
+
Calculate precision
|
|
25
|
+
|
|
26
|
+
:param residuals(np.ndarray): , shape: (#run, #point, #channel)
|
|
27
|
+
:param neighbors(np.ndarray): , shape: (#center, #neighbor)
|
|
28
|
+
:param n_split_data(int): how many datas to process at once
|
|
29
|
+
:param masking_indexes(np.array): , shape: (#channel) / index of masking brain
|
|
30
|
+
:param n_thread_per_block(int): block per thread
|
|
31
|
+
|
|
32
|
+
return (np.ndarray), shape: (#channel, #run, #neighbor, #neighbor)
|
|
33
|
+
"""
|
|
34
|
+
|
|
35
|
+
n_run = residuals.shape[0]
|
|
36
|
+
n_p = residuals.shape[1]
|
|
37
|
+
n_channel = residuals.shape[-1]
|
|
38
|
+
|
|
39
|
+
n_center = len(neighbors)
|
|
40
|
+
n_block = int(np.ceil(n_split_data / n_thread_per_block))
|
|
41
|
+
n_neighbor = neighbors.shape[-1]
|
|
42
|
+
r, c = np.triu_indices(n_neighbor, k = 0)
|
|
43
|
+
|
|
44
|
+
mempool = cp.get_default_memory_pool()
|
|
45
|
+
|
|
46
|
+
chunk_precisions = []
|
|
47
|
+
for i in trange(0, n_center, n_split_data):
|
|
48
|
+
# select neighbors
|
|
49
|
+
target_neighbors = neighbors[i:i + n_split_data, :]
|
|
50
|
+
len_target = len(target_neighbors)
|
|
51
|
+
|
|
52
|
+
# output_1d
|
|
53
|
+
mask_out = cuda.to_device(np.zeros((len_target, n_channel)))
|
|
54
|
+
|
|
55
|
+
# Make mask - neighbor
|
|
56
|
+
set_mask[n_block, n_thread_per_block](target_neighbors, masking_indexes, mask_out)
|
|
57
|
+
|
|
58
|
+
# sync
|
|
59
|
+
cuda.synchronize()
|
|
60
|
+
|
|
61
|
+
# Apply mask
|
|
62
|
+
cpu_mask = mask_out.copy_to_host()
|
|
63
|
+
masked_residuals = []
|
|
64
|
+
for j in range(len(target_neighbors)):
|
|
65
|
+
masked_residuals.append(residuals[:, :, cpu_mask[j] == 1])
|
|
66
|
+
masked_residuals = np.array(masked_residuals)
|
|
67
|
+
|
|
68
|
+
del mask_out
|
|
69
|
+
cuda.defer_cleanup()
|
|
70
|
+
|
|
71
|
+
# Calculate demean
|
|
72
|
+
target_residuals = masked_residuals.reshape(-1, n_p, n_neighbor)
|
|
73
|
+
mean_residuals = np.mean(target_residuals, axis = 1, keepdims=1)
|
|
74
|
+
target_residuals = (target_residuals - mean_residuals)
|
|
75
|
+
|
|
76
|
+
# Calculate covariance
|
|
77
|
+
if shrinkage_method == ShrinkageMethod.shrinkage_diag:
|
|
78
|
+
covariances = _covariance_diag(target_residuals)
|
|
79
|
+
elif shrinkage_method == ShrinkageMethod.shrinkage_eye:
|
|
80
|
+
covariances = _covariance_eye(target_residuals)
|
|
81
|
+
|
|
82
|
+
# Calculate precision matrix
|
|
83
|
+
stack_precisions = cp.linalg.inv(cp.asarray(covariances)).get()
|
|
84
|
+
|
|
85
|
+
# sync
|
|
86
|
+
cuda.synchronize()
|
|
87
|
+
|
|
88
|
+
# concat
|
|
89
|
+
stack_precisions = stack_precisions.reshape(len_target, n_run, n_neighbor, n_neighbor)
|
|
90
|
+
stack_precisions = stack_precisions[:, :, r, c]
|
|
91
|
+
|
|
92
|
+
# add chunk
|
|
93
|
+
chunk_precisions.append(stack_precisions)
|
|
94
|
+
|
|
95
|
+
# Clean data
|
|
96
|
+
cuda.defer_cleanup()
|
|
97
|
+
mempool.free_all_blocks()
|
|
98
|
+
|
|
99
|
+
return chunk_precisions
|
|
100
|
+
|
|
101
|
+
def calc_sl_rdm_crossnobis(n_split_data,
|
|
102
|
+
centers,
|
|
103
|
+
neighbors,
|
|
104
|
+
precs,
|
|
105
|
+
measurements,
|
|
106
|
+
masking_indexes,
|
|
107
|
+
conds,
|
|
108
|
+
sessions,
|
|
109
|
+
n_thread_per_block = 1000):
|
|
110
|
+
"""
|
|
111
|
+
Calculate searchlight crossnobis rdm
|
|
112
|
+
|
|
113
|
+
:param n_split_data(int): how many datas to process at once
|
|
114
|
+
:param centers(np.array): centers, shape: (#center)
|
|
115
|
+
:param neighbors(np.array): neighbors , shape: (#center, #neighbor)
|
|
116
|
+
:param precs(np.array): precisions , shape: (#channel, #run, #precision_mat_element)
|
|
117
|
+
:param measurements(np.array): measurment values , shape: (#cond, #channel)
|
|
118
|
+
:param masking_indexes: (np.array) , shape: (#channel) , index of masking brain
|
|
119
|
+
:param conds: conds(np.array - 1d)
|
|
120
|
+
:param sessions(np.array - 1d): session corressponding to conds
|
|
121
|
+
:param n_thread_per_block(int): , block per thread
|
|
122
|
+
|
|
123
|
+
"""
|
|
124
|
+
# Data configuration
|
|
125
|
+
n_run = len(np.unique(sessions))
|
|
126
|
+
n_cond = len(np.unique(conds))
|
|
127
|
+
n_dissim = int((n_cond * n_cond - n_cond) / 2)
|
|
128
|
+
n_neighbor = neighbors.shape[-1]
|
|
129
|
+
uq_conds = np.unique(conds)
|
|
130
|
+
n_channel = measurements.shape[-1]
|
|
131
|
+
uq_sessions = np.unique(sessions)
|
|
132
|
+
|
|
133
|
+
assert n_channel == masking_indexes.shape[0], "n_channel should be same"
|
|
134
|
+
|
|
135
|
+
# Fold
|
|
136
|
+
fold_info = cuda.to_device(list(itertools.combinations(np.arange(len(uq_sessions)), 2)))
|
|
137
|
+
n_fold = len(fold_info)
|
|
138
|
+
total_calculation = n_split_data * n_fold
|
|
139
|
+
|
|
140
|
+
# GPU Configuration
|
|
141
|
+
n_block = int(np.ceil(n_split_data / n_thread_per_block))
|
|
142
|
+
n_thread_per_block_2d = int(np.ceil(np.sqrt(n_thread_per_block)))
|
|
143
|
+
block_2ds = (total_calculation // n_thread_per_block_2d, total_calculation // n_thread_per_block_2d)
|
|
144
|
+
thread_2ds = (n_thread_per_block_2d, n_thread_per_block_2d)
|
|
145
|
+
|
|
146
|
+
# Memory pool
|
|
147
|
+
mempool = cp.get_default_memory_pool()
|
|
148
|
+
|
|
149
|
+
# Calculation
|
|
150
|
+
rdm_outs = []
|
|
151
|
+
for i in trange(0, len(centers), n_split_data):
|
|
152
|
+
# select neighbors
|
|
153
|
+
target_centers = centers[i:i + n_split_data]
|
|
154
|
+
target_neighbors = neighbors[i:i + n_split_data, :]
|
|
155
|
+
|
|
156
|
+
n_target_centers = len(target_centers)
|
|
157
|
+
|
|
158
|
+
# output_1d
|
|
159
|
+
mask_out = cuda.to_device(np.zeros((n_target_centers, n_channel)))
|
|
160
|
+
|
|
161
|
+
# Make mask - neighbor
|
|
162
|
+
set_mask[n_block, n_thread_per_block](target_neighbors, masking_indexes, mask_out)
|
|
163
|
+
cuda.synchronize()
|
|
164
|
+
|
|
165
|
+
# Apply mask
|
|
166
|
+
cpu_mask = mask_out.copy_to_host()
|
|
167
|
+
masked_measurements = []
|
|
168
|
+
for j in range(n_target_centers):
|
|
169
|
+
masked_measurements.append(measurements[:, cpu_mask[j] == 1])
|
|
170
|
+
masked_measurements = np.array(masked_measurements)
|
|
171
|
+
masked_measurements = cp.asarray(masked_measurements)
|
|
172
|
+
|
|
173
|
+
del mask_out
|
|
174
|
+
cuda.defer_cleanup()
|
|
175
|
+
|
|
176
|
+
# precision
|
|
177
|
+
prec_mat_shape = int((n_neighbor * n_neighbor - n_neighbor) / 2) + n_neighbor
|
|
178
|
+
target_precs = precs[i:i+n_target_centers].reshape(-1, prec_mat_shape)
|
|
179
|
+
target_precs = np.array([convert_1d_to_symmertic(pre, size = n_neighbor) for pre in target_precs])
|
|
180
|
+
variances = cp.linalg.inv(cp.asarray(target_precs))
|
|
181
|
+
variances = variances.reshape(n_target_centers, n_run, n_neighbor, n_neighbor).get()
|
|
182
|
+
fold_preicions = cp.linalg.inv(cp.asarray(mean_fold_variance(variances, fold_info.copy_to_host())))
|
|
183
|
+
fold_preicions = cuda.to_device(fold_preicions.reshape(n_target_centers, len(fold_info), n_neighbor, n_neighbor).get())
|
|
184
|
+
mempool.free_all_blocks()
|
|
185
|
+
|
|
186
|
+
# Avg conds per session
|
|
187
|
+
avg_measurements = []
|
|
188
|
+
avg_conds = []
|
|
189
|
+
for session in uq_sessions:
|
|
190
|
+
filtering_session = sessions == session
|
|
191
|
+
sess_cond = conds[filtering_session]
|
|
192
|
+
sess_measurements = cp.compress(filtering_session, masked_measurements, axis = 1)
|
|
193
|
+
|
|
194
|
+
mean_measurments = []
|
|
195
|
+
for cond in uq_conds:
|
|
196
|
+
filtering_cond = sess_cond == cond
|
|
197
|
+
cond_measurments = cp.compress(filtering_cond, sess_measurements, axis = 1)
|
|
198
|
+
mean_cond_measurement = cp.mean(cond_measurments, axis = 1)
|
|
199
|
+
mean_measurments.append(cp.expand_dims(mean_cond_measurement, axis = 1))
|
|
200
|
+
|
|
201
|
+
avg_conds.append(cond)
|
|
202
|
+
|
|
203
|
+
avg_measurements.append(cp.expand_dims(cp.concatenate(mean_measurments, axis = 1), axis = 1))
|
|
204
|
+
avg_measurements = cp.concatenate(avg_measurements, axis = 1).get()
|
|
205
|
+
|
|
206
|
+
avg_conds = np.array(avg_conds)
|
|
207
|
+
|
|
208
|
+
mempool.free_all_blocks()
|
|
209
|
+
|
|
210
|
+
# make kernel
|
|
211
|
+
avg_measurements = cuda.to_device(avg_measurements)
|
|
212
|
+
|
|
213
|
+
matmul1_out = cuda.to_device(np.zeros((n_target_centers, n_fold, n_cond, n_neighbor)))
|
|
214
|
+
kernel_out = cuda.to_device(np.zeros((n_target_centers, n_fold, n_cond, n_cond)))
|
|
215
|
+
calc_kernel[block_2ds, thread_2ds](avg_measurements, fold_preicions, fold_info, matmul1_out, kernel_out)
|
|
216
|
+
|
|
217
|
+
cuda.synchronize()
|
|
218
|
+
del matmul1_out
|
|
219
|
+
cuda.defer_cleanup()
|
|
220
|
+
|
|
221
|
+
rdm_out = cuda.to_device(np.zeros((n_target_centers, n_fold, n_dissim)))
|
|
222
|
+
rdm_from_kernel[block_2ds, thread_2ds](kernel_out, n_neighbor, rdm_out)
|
|
223
|
+
|
|
224
|
+
cuda.synchronize()
|
|
225
|
+
|
|
226
|
+
mean_rdms = cp.mean(rdm_out.copy_to_host(), axis = 1)
|
|
227
|
+
rdm_outs.append(mean_rdms)
|
|
228
|
+
|
|
229
|
+
del kernel_out
|
|
230
|
+
del rdm_out
|
|
231
|
+
cuda.defer_cleanup()
|
|
232
|
+
|
|
233
|
+
return rdm_outs, uq_conds
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: boostrsa
|
|
3
|
+
Version: 0.0.1.dev3
|
|
4
|
+
Summary: This is toolbox for boosting calculation speed using GPU
|
|
5
|
+
Home-page: https://github.com/SeojinYoon/boostrsa.git
|
|
6
|
+
Author: seojin
|
|
7
|
+
Author-email: pures1@hanyang.ac.kr
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Requires-Python: >=3.8
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE.txt
|
|
14
|
+
Requires-Dist: numpy
|
|
15
|
+
Requires-Dist: pandas
|
|
16
|
+
Requires-Dist: tqdm
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
# Boostrsa
|
|
20
|
+
|
|
21
|
+
This library is based on rsatoolbox(https://github.com/rsagroup/rsatoolbox).
|
|
22
|
+
|
|
23
|
+
The purpose of library is made to boost calcuation speed for searchlight RSA(Representational Similarity Analysis). However, It is still in development, so this library only includes tools for boosting crossnobis distance calculation for constructing RDM(Representational Dissimilartiy Matrix) on the whole brain.
|
|
24
|
+
|
|
25
|
+
## How it works?
|
|
26
|
+
|
|
27
|
+
Basically, this library uses a Nvidia's GPU instead of CPU for parallel processing. In the searchlight analysis, the data targeted for constructing the RDM in volvxes a voxel and its neighboring voxels. That is well-suited for parallel processing since the calculations for each target are independent of one another. This library utilizes GPU-compatible libraries such as Numba and Cupy to facilitate this process.
|
|
28
|
+
|
|
29
|
+
## Dependencies
|
|
30
|
+
|
|
31
|
+
To use this library, you need to have a Nvidia's GPU and CUDA. Additionally, this library heavily relies on Cupy and Numba. It is essential to install the appropriate versions of these libraries.
|
|
32
|
+
|
|
33
|
+
### Cupy
|
|
34
|
+
|
|
35
|
+
Cupy is designed to work with specific versions of CUDA. See cupy's guide and install appropriate version in correspond to your system (https://github.com/cupy/cupy).
|
|
36
|
+
|
|
37
|
+
Please check your cuda version to install cupy.
|
|
38
|
+
- versions
|
|
39
|
+
- cupy-cuda10x (for cuda 10)
|
|
40
|
+
- cupy-cuda11x (for cuda 11)
|
|
41
|
+
- cupy-cuda12x (for cuda 12)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
If you installed the cuda10 in your computer, then install cupy-cuda10x. install cupy-cuda10x. ex) pip install cupy-cuda10x
|
|
45
|
+
|
|
46
|
+
### Numba
|
|
47
|
+
|
|
48
|
+
The numba library is a powerful tool that enbales python functions to be compiled to machine code at runtime using the LLVM. One of its key features is the ability to generate native code for different architectures, including CPUs and GPUs, which greatly accelerates the execution of data-heavy and computationally intense python code.
|
|
49
|
+
|
|
50
|
+
Please see installation guideline of numba (https://numba.pydata.org/numba-doc/latest/user/installing.html).
|
|
51
|
+
|
|
52
|
+
Pip installation).
|
|
53
|
+
- pip install numba
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
## Installation
|
|
57
|
+
|
|
58
|
+
pip install boostrsa
|
|
59
|
+
|
|
60
|
+
# Checked version
|
|
61
|
+
|
|
62
|
+
These are the latest checked environment.
|
|
63
|
+
|
|
64
|
+
- OS
|
|
65
|
+
- Linux, ubuntu - 21.10
|
|
66
|
+
- numba
|
|
67
|
+
- 0.57.0 ~ 0.59.1 is fine to use
|
|
68
|
+
- cupy
|
|
69
|
+
- cupy-cuda11x
|
|
70
|
+
- cupy-cuda12x
|
|
71
|
+
|
|
72
|
+
# Future works
|
|
73
|
+
|
|
74
|
+
- Add calculation sources to get neighbors and centers (boost)
|
|
75
|
+
- Add RSA sources (boost)
|
|
76
|
+
- Support other calculation methods except crossnobis distance
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
LICENSE.txt
|
|
2
|
+
README.md
|
|
3
|
+
setup.py
|
|
4
|
+
src/boostrsa/__init__.py
|
|
5
|
+
src/boostrsa/boostrsa_types.py
|
|
6
|
+
src/boostrsa/searchlight.py
|
|
7
|
+
src/boostrsa.egg-info/PKG-INFO
|
|
8
|
+
src/boostrsa.egg-info/SOURCES.txt
|
|
9
|
+
src/boostrsa.egg-info/dependency_links.txt
|
|
10
|
+
src/boostrsa.egg-info/requires.txt
|
|
11
|
+
src/boostrsa.egg-info/top_level.txt
|
|
12
|
+
src/boostrsa/cores/__init__.py
|
|
13
|
+
src/boostrsa/cores/cpgpu/__init__.py
|
|
14
|
+
src/boostrsa/cores/cpgpu/stats.py
|
|
15
|
+
src/boostrsa/cores/cpu/__init__.py
|
|
16
|
+
src/boostrsa/cores/cpu/matrix.py
|
|
17
|
+
src/boostrsa/cores/gpu/__init__.py
|
|
18
|
+
src/boostrsa/cores/gpu/basic_operations.py
|
|
19
|
+
src/boostrsa/cores/gpu/mask.py
|
|
20
|
+
src/boostrsa/cores/gpu/matrix.py
|
|
21
|
+
tests/test_module1.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
boostrsa
|
boostrsa-0.0.1.dev0/PKG-INFO
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: boostrsa
|
|
3
|
-
Version: 0.0.1.dev0
|
|
4
|
-
Summary: This is toolbox for boosting calculation speed using GPU
|
|
5
|
-
Author: seojin
|
|
6
|
-
Author-email: pures1@hanyang.ac.kr
|
|
7
|
-
Classifier: Programming Language :: Python :: 3
|
|
8
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
9
|
-
Classifier: Operating System :: OS Independent
|
|
10
|
-
Requires-Python: >=3.9
|
|
11
|
-
Description-Content-Type: text/markdown
|
|
12
|
-
License-File: LICENSE.txt
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
# Boostrsa
|
|
16
|
-
|
|
17
|
-
blahblah
|
|
18
|
-
|
|
19
|
-
## Setup
|
|
20
|
-
|
|
21
|
-
### Dependencies
|
|
22
|
-
|
|
23
|
-
numba
|
|
24
|
-
cupy
|
|
25
|
-
|
|
26
|
-
### PIP
|
|
27
|
-
|
boostrsa-0.0.1.dev0/README.md
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: boostrsa
|
|
3
|
-
Version: 0.0.1.dev0
|
|
4
|
-
Summary: This is toolbox for boosting calculation speed using GPU
|
|
5
|
-
Author: seojin
|
|
6
|
-
Author-email: pures1@hanyang.ac.kr
|
|
7
|
-
Classifier: Programming Language :: Python :: 3
|
|
8
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
9
|
-
Classifier: Operating System :: OS Independent
|
|
10
|
-
Requires-Python: >=3.9
|
|
11
|
-
Description-Content-Type: text/markdown
|
|
12
|
-
License-File: LICENSE.txt
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
# Boostrsa
|
|
16
|
-
|
|
17
|
-
blahblah
|
|
18
|
-
|
|
19
|
-
## Setup
|
|
20
|
-
|
|
21
|
-
### Dependencies
|
|
22
|
-
|
|
23
|
-
numba
|
|
24
|
-
cupy
|
|
25
|
-
|
|
26
|
-
### PIP
|
|
27
|
-
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
LICENSE.txt
|
|
2
|
-
README.md
|
|
3
|
-
setup.py
|
|
4
|
-
src/boostrsa.egg-info/PKG-INFO
|
|
5
|
-
src/boostrsa.egg-info/SOURCES.txt
|
|
6
|
-
src/boostrsa.egg-info/dependency_links.txt
|
|
7
|
-
src/boostrsa.egg-info/requires.txt
|
|
8
|
-
src/boostrsa.egg-info/top_level.txt
|
|
9
|
-
src/cores/__init__.py
|
|
10
|
-
src/cores/cpgpu/__init__.py
|
|
11
|
-
src/cores/cpgpu/stats.py
|
|
12
|
-
src/cores/cpu/__init__.py
|
|
13
|
-
src/cores/cpu/matrix.py
|
|
14
|
-
src/cores/gpu/__init__.py
|
|
15
|
-
src/cores/gpu/basic_operations.py
|
|
16
|
-
src/cores/gpu/mask.py
|
|
17
|
-
src/cores/gpu/matrix.py
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
cores
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{boostrsa-0.0.1.dev0/src/cores/cpu → boostrsa-0.0.1.dev3/src/boostrsa/cores/cpgpu}/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
{boostrsa-0.0.1.dev0/src/cores/gpu → boostrsa-0.0.1.dev3/src/boostrsa/cores/cpu}/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|