Changeset c036ddb in sasmodels for sasmodels/kernelcl.py
- Timestamp:
- Aug 7, 2018 10:45:45 PM (6 years ago)
- Branches:
- master, core_shell_microgels, magnetic_model, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
- Children:
- 7e923c2
- Parents:
- 7b0abf8
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/kernelcl.py
r01c8d9e rc036ddb 420 420 if self.program is None: 421 421 compile_program = environment().compile_program 422 with open('model.c','w') as fid:423 print(self.source['opencl'], file=fid)424 422 timestamp = generate.ocl_timestamp(self.info) 425 423 self.program = compile_program( … … 540 538 self.dtype = dtype 541 539 self.dim = '2d' if q_input.is_2d else '1d' 542 # plus three for the normalization values 543 self.result = np.empty(2*q_input.nq+2,dtype) 540 # leave room for f1/f2 results in case we need to compute beta for 1d models 541 num_returns = 1 if self.dim == '2d' else 2 # 542 # plus 1 for the normalization value 543 self.result = np.empty((q_input.nq+1)*num_returns, dtype) 544 544 545 545 # Inputs and outputs for each kernel call … … 549 549 550 550 self.result_b = cl.Buffer(self.queue.context, mf.READ_WRITE, 551 q_input.global_size[0] * dtype.itemsize)551 q_input.global_size[0] * num_returns * dtype.itemsize) 552 552 self.q_input = q_input # allocated by GpuInput above 553 553 … … 557 557 else np.float16 if dtype == generate.F16 558 558 else np.float32) # will never get here, so use np.float32 559 __call__= Iq560 559 561 560 def Iq(self, call_details, values, cutoff, magnetic): 561 # type: (CallDetails, np.ndarray, np.ndarray, float, bool) -> np.ndarray 562 self._call_kernel(call_details, values, cutoff, magnetic) 563 #print("returned",self.q_input.q, self.result) 564 pd_norm = self.result[self.q_input.nq] 565 scale = values[0]/(pd_norm if pd_norm != 0.0 else 1.0) 566 background = values[1] 567 #print("scale",scale,background) 568 return scale*self.result[:self.q_input.nq] + background 569 __call__ = Iq 570 571 def beta(self, call_details, values, cutoff, magnetic): 572 # type: (CallDetails, np.ndarray, np.ndarray, float, bool) -> np.ndarray 573 if self.dim == '2d': 574 raise NotImplementedError("beta not yet supported for 2D") 575 self._call_kernel(call_details, values, cutoff, magnetic) 576 w_norm = self.result[2*self.q_input.nq + 1] 577 pd_norm = self.result[self.q_input.nq] 578 if w_norm == 0.: 579 w_norm = 1. 580 F2 = self.result[:self.q_input.nq]/w_norm 581 F1 = self.result[self.q_input.nq+1:2*self.q_input.nq+1]/w_norm 582 volume_avg = pd_norm/w_norm 583 return F1, F2, volume_avg 584 585 def _call_kernel(self, call_details, values, cutoff, magnetic): 562 586 # type: (CallDetails, np.ndarray, np.ndarray, float, bool) -> np.ndarray 563 587 context = self.queue.context … … 575 599 ] 576 600 #print("Calling OpenCL") 577 call_details.show(values)601 #call_details.show(values) 578 602 #Call kernel and retrieve results 579 603 wait_for = None … … 601 625 v.release() 602 626 603 pd_norm = self.result[self.q_input.nq]604 scale = values[0]/(pd_norm if pd_norm != 0.0 else 1.0)605 background = values[1]606 #print("scale",scale,values[0],self.result[self.q_input.nq],background)607 return scale*self.result[:self.q_input.nq] + background608 # return self.result[:self.q_input.nq]609 #NEEDS TO BE FINISHED FOR OPENCL610 def beta():611 return 0612 613 627 def release(self): 614 628 # type: () -> None
Note: See TracChangeset
for help on using the changeset viewer.