1 | ''' |
---|
2 | Created on Nov 29, 2016 |
---|
3 | |
---|
4 | @author: wpotrzebowski |
---|
5 | ''' |
---|
6 | |
---|
7 | import os |
---|
8 | import warnings |
---|
9 | |
---|
10 | import wx |
---|
11 | import wx.richtext |
---|
12 | import wx.lib.hyperlink |
---|
13 | |
---|
14 | from sas.sasgui.guiframe.documentation_window import DocumentationWindow |
---|
15 | |
---|
16 | class GpuOptions(wx.Dialog): |
---|
17 | """ |
---|
18 | "Acknowledgement" Dialog Box |
---|
19 | |
---|
20 | Shows the current method for acknowledging SasView in |
---|
21 | scholarly publications. |
---|
22 | |
---|
23 | """ |
---|
24 | |
---|
25 | def __init__(self, *args, **kwds): |
---|
26 | |
---|
27 | kwds["style"] = wx.DEFAULT_DIALOG_STYLE |
---|
28 | wx.Dialog.__init__(self, *args, **kwds) |
---|
29 | |
---|
30 | clinfo = self._get_clinfo() |
---|
31 | |
---|
32 | self.panel1 = wx.Panel(self, -1) |
---|
33 | static_box1 = wx.StaticBox(self.panel1, -1, "Available OpenCL Options:") |
---|
34 | |
---|
35 | boxsizer = wx.BoxSizer(orient=wx.VERTICAL) |
---|
36 | self.option_button = {} |
---|
37 | self.buttons = [] |
---|
38 | for index, clopt in enumerate(clinfo): |
---|
39 | button = wx.CheckBox(self.panel1, -1, label=clopt, name=clopt) |
---|
40 | if clopt != "No OpenCL": |
---|
41 | self.option_button[clopt] = str(index) |
---|
42 | else: |
---|
43 | self.option_button[clopt] = "None" |
---|
44 | self.Bind(wx.EVT_CHECKBOX, self.on_radio, id=button.GetId()) |
---|
45 | self.buttons.append(button) |
---|
46 | boxsizer.Add(button, 0, 0) |
---|
47 | |
---|
48 | fit_hsizer = wx.StaticBoxSizer(static_box1, orient=wx.VERTICAL) |
---|
49 | fit_hsizer.Add(boxsizer, 0, wx.ALL, 5) |
---|
50 | |
---|
51 | self.panel1.SetSizer(fit_hsizer) |
---|
52 | |
---|
53 | self.vbox = wx.BoxSizer(wx.VERTICAL) |
---|
54 | self.vbox.Add(self.panel1, 0, wx.ALL, 10) |
---|
55 | |
---|
56 | accept_btn = wx.Button(self, wx.ID_OK) |
---|
57 | accept_btn.SetToolTipString("Accept OpenCL settings") |
---|
58 | |
---|
59 | help_id = wx.NewId() |
---|
60 | help_btn = wx.Button(self, help_id, 'Help') |
---|
61 | help_btn.SetToolTipString("Help on the GPU options") |
---|
62 | |
---|
63 | self.Bind(wx.EVT_BUTTON, self.on_accept, accept_btn) |
---|
64 | self.Bind(wx.EVT_BUTTON, self.on_help, help_btn) |
---|
65 | self.Bind(wx.EVT_CLOSE, self.on_close) |
---|
66 | |
---|
67 | btn_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
68 | btn_sizer.Add((10, 20), 1) # stretchable whitespace |
---|
69 | btn_sizer.Add(accept_btn, 0) |
---|
70 | btn_sizer.Add((10, 20), 0) # non-stretchable whitespace |
---|
71 | btn_sizer.Add(help_btn, 0) |
---|
72 | |
---|
73 | # Add the button sizer to the main sizer. |
---|
74 | self.vbox.Add(btn_sizer, 0, wx.EXPAND|wx.ALL, 10) |
---|
75 | |
---|
76 | self.SetSizer(self.vbox) |
---|
77 | self.vbox.Fit(self) |
---|
78 | |
---|
79 | self.Centre() |
---|
80 | |
---|
81 | def _get_clinfo(self): |
---|
82 | clinfo = [] |
---|
83 | |
---|
84 | try: |
---|
85 | import pyopencl as cl |
---|
86 | for platform in cl.get_platforms(): |
---|
87 | for device in platform.get_devices(): |
---|
88 | clinfo.append(device.name) |
---|
89 | except ImportError: |
---|
90 | warnings.warn("pyopencl import failed. Please check installation") |
---|
91 | |
---|
92 | clinfo.append("No OpenCL") |
---|
93 | return clinfo |
---|
94 | |
---|
95 | def on_radio_default(self, event): |
---|
96 | event.GetEventObject().SetValue(not event.GetEventObject().GetValue()) |
---|
97 | |
---|
98 | def on_radio(self, event): |
---|
99 | """ |
---|
100 | Action triggered when button is selected |
---|
101 | :param event: |
---|
102 | :return: |
---|
103 | """ |
---|
104 | import sasmodels |
---|
105 | selected_button = event.GetEventObject() |
---|
106 | for btn in self.buttons: |
---|
107 | if btn != selected_button: |
---|
108 | btn.SetValue(0) |
---|
109 | os.environ["SAS_OPENCL"] = self.option_button[selected_button.Name] |
---|
110 | sasmodels.kernelcl.ENV = None |
---|
111 | #Need to reload sasmodels.core module to account SAS_OPENCL = "None" |
---|
112 | reload(sasmodels.core) |
---|
113 | |
---|
114 | def on_accept(self, event): |
---|
115 | """ |
---|
116 | Close window on accpetance |
---|
117 | """ |
---|
118 | event.Skip() |
---|
119 | |
---|
120 | def on_help(self, event): |
---|
121 | """ |
---|
122 | Provide help on opencl options. |
---|
123 | """ |
---|
124 | TreeLocation = "user/gpu_computations.html" |
---|
125 | anchor = "#device-selection" |
---|
126 | DocumentationWindow(self, -1, |
---|
127 | TreeLocation, anchor, "OpenCL Options Help") |
---|
128 | |
---|
129 | def on_close(self, event): |
---|
130 | """ |
---|
131 | Close window |
---|
132 | """ |
---|
133 | event.Skip() |
---|