Skip to content

Commit

Permalink
loop parallelization, weights and parameters expanded into arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
mpatrou committed Jan 21, 2024
1 parent 7c24264 commit 3dd4a60
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
2 changes: 1 addition & 1 deletion example/sphere_pytorch_prototype.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def make_kernel(model, q_vectors,device):
print("q",q[6])
kernel = model.make_kernel([q])

pars = {'radius': 200, 'radius_pd': 0.1, 'radius_pd_n':1000, 'sld':2, 'sld_pd': 0.1, 'sld_pd_n':100, 'scale': 2}
pars = {'radius': 200, 'radius_pd': 0.1, 'radius_pd_n':100, 'sld':2, 'sld_pd': 0.1, 'sld_pd_n':100, 'scale': 2}

t_before = time.time()
Iq = call_kernel(kernel, pars)
Expand Down
33 changes: 28 additions & 5 deletions sasmodels/kerneltorch.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ def __init__(self, model_info, q_input, device):
self.info = model_info
self.q_input = q_input
self.dim = '2d' if q_input.is_2d else '1d'

call_parameters = model_info.parameters.call_parameters
self.parameters = np.empty(len(call_parameters)-2, np.double)


def Iq(self, pars, scale, background):
Expand Down Expand Up @@ -322,13 +325,33 @@ def _loops(parameters, kernel_idx, form, form_volume, form_radius, q_input, call
pd_stride = call_details.pd_stride[:call_details.num_active]
pd_length = call_details.pd_length[:call_details.num_active]

#total = np.zeros(nq, np.float64)
total = torch.zeros(q_input.nq, dtype= torch.double).to(device)

#print("ll", range(call_details.num_eval))
#parallel for loop
# each look_index can be GPU/CPU thread: tid
# each thread has its own pd_index and p0_index
# #parallel loop preparation

# #for parameter in parameters:
# total_cells = call_details.num_eval
# cells = torch.range(0, total_cells-1,1)

# #parameters repeated at every p0_length!
# parameters_tensor = torch.range(pd_value[p0_offset], pd_value[p0_offset + p0_length-1],1)
# print(f"parameters_tensor = {parameters_tensor}")

# #weights for enevy call_details.num_eval
# pd_index_end = (total_cells//pd_stride)%pd_length
# partial_weights_tensor = torch.empty(p0_length,dtype= torch.double).to(device)
# weights_tensor = torch.ones(total_cells,dtype= torch.double).to(device)


# for index_i in range(p0_length):
# partial_weight_start = torch.prod(pd_weight[pd_offset+index_i][1:]).to(device)
# partial_weights_tensor[index_i] = partial_weight_start
# weights_tensor[index_i*p0_length:(index_i+1)*p0_length] = torch.mul(pd_weight[p0_offset:p0_offset+p0_length],partial_weights_tensor[index_i])

# print(f"weights_tensor = {weights_tensor}")

# #end of parallel loop preparation


for loop_index in range(call_details.num_eval):
# Update polydispersity parameter values.
Expand Down

0 comments on commit 3dd4a60

Please sign in to comment.