1 | ''' |
---|
2 | Created on Nov 29, 2016 |
---|
3 | |
---|
4 | @author: wpotrzebowski |
---|
5 | ''' |
---|
6 | |
---|
7 | import wx |
---|
8 | import wx.richtext |
---|
9 | import wx.lib.hyperlink |
---|
10 | import os |
---|
11 | |
---|
12 | from sas.sasgui.guiframe.documentation_window import DocumentationWindow |
---|
13 | |
---|
14 | try: |
---|
15 | # Try to find a local config |
---|
16 | import imp |
---|
17 | path = os.getcwd() |
---|
18 | if(os.path.isfile("%s/%s.py" % (path, 'local_config'))) or \ |
---|
19 | (os.path.isfile("%s/%s.pyc" % (path, 'local_config'))): |
---|
20 | fObj, path, descr = imp.find_module('local_config', [path]) |
---|
21 | config = imp.load_module('local_config', fObj, path, descr) |
---|
22 | else: |
---|
23 | # Try simply importing local_config |
---|
24 | import local_config as config |
---|
25 | except: |
---|
26 | # Didn't find local config, load the default |
---|
27 | import config |
---|
28 | |
---|
29 | |
---|
30 | class GpuOptions(wx.Dialog): |
---|
31 | """ |
---|
32 | "Acknowledgement" Dialog Box |
---|
33 | |
---|
34 | Shows the current method for acknowledging SasView in |
---|
35 | scholarly publications. |
---|
36 | |
---|
37 | """ |
---|
38 | |
---|
39 | def __init__(self, *args, **kwds): |
---|
40 | |
---|
41 | kwds["style"] = wx.DEFAULT_DIALOG_STYLE |
---|
42 | wx.Dialog.__init__(self, *args, **kwds) |
---|
43 | |
---|
44 | clinfo = self._get_clinfo() |
---|
45 | |
---|
46 | self.panel1 = wx.Panel(self, -1) |
---|
47 | static_box1 = wx.StaticBox(self.panel1, -1, "Available OpenCL Options:") |
---|
48 | |
---|
49 | boxsizer = wx.BoxSizer(orient=wx.VERTICAL) |
---|
50 | self.option_button = {} |
---|
51 | for index, fitter in enumerate(clinfo): |
---|
52 | button = wx.RadioButton(self.panel1, -1, |
---|
53 | label=fitter, name=fitter) |
---|
54 | if fitter != "No OpenCL": |
---|
55 | self.option_button[fitter] = str(index) |
---|
56 | else: |
---|
57 | self.option_button[fitter] = "None" |
---|
58 | self.Bind(wx.EVT_RADIOBUTTON, self.OnRadio, id=button.GetId()) |
---|
59 | boxsizer.Add(button, 0, 0) |
---|
60 | |
---|
61 | fit_hsizer = wx.StaticBoxSizer(static_box1, orient=wx.VERTICAL) |
---|
62 | fit_hsizer.Add(boxsizer, 0, wx.ALL, 5) |
---|
63 | |
---|
64 | self.panel1.SetSizer(fit_hsizer) |
---|
65 | |
---|
66 | self.vbox = wx.BoxSizer(wx.VERTICAL) |
---|
67 | self.vbox.Add(self.panel1, 0, wx.ALL, 10) |
---|
68 | |
---|
69 | accept_btn = wx.Button(self, wx.ID_OK) |
---|
70 | accept_btn.SetToolTipString("Accept new options for GPU") |
---|
71 | |
---|
72 | help_btn = wx.Button(self, wx.ID_HELP, 'Help') |
---|
73 | help_btn.SetToolTipString("Help on the GPU options") |
---|
74 | |
---|
75 | self.Bind(wx.EVT_BUTTON, self.OnAccept, accept_btn) |
---|
76 | if help is not None: |
---|
77 | self.Bind(wx.EVT_BUTTON, self.OnHelp, help_btn) |
---|
78 | |
---|
79 | self.Bind(wx.EVT_CLOSE, self.OnClose) |
---|
80 | |
---|
81 | btn_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
82 | btn_sizer.Add((10,20), 1) # stretchable whitespace |
---|
83 | btn_sizer.Add(accept_btn, 0) |
---|
84 | btn_sizer.Add((10,20), 0) # non-stretchable whitespace |
---|
85 | btn_sizer.Add(help_btn, 0) |
---|
86 | |
---|
87 | # Add the button sizer to the main sizer. |
---|
88 | self.vbox.Add(btn_sizer, 0, wx.EXPAND|wx.ALL, 10) |
---|
89 | |
---|
90 | self.SetSizer(self.vbox) |
---|
91 | self.vbox.Fit(self) |
---|
92 | |
---|
93 | self.Centre() |
---|
94 | |
---|
95 | def _get_clinfo(self): |
---|
96 | try: |
---|
97 | #TODO: Is PYOPENCL_CTX setup up in this order? |
---|
98 | import pyopencl as cl |
---|
99 | for platform in cl.get_platforms(): |
---|
100 | clinfo = [device.name for device in platform.get_devices()] |
---|
101 | clinfo.append("No OpenCL") |
---|
102 | except: |
---|
103 | warnings.warn(str(exc)) |
---|
104 | warnings.warn("pyopencl import failed") |
---|
105 | clinfo = None |
---|
106 | return clinfo |
---|
107 | |
---|
108 | def OnRadio(self, event): |
---|
109 | import sasmodels |
---|
110 | button = event.GetEventObject() |
---|
111 | os.environ["SAS_OPENCL"] = self.option_button[button.Name] |
---|
112 | sasmodels.kernelcl.ENV = None |
---|
113 | reload(sasmodels.core) |
---|
114 | |
---|
115 | def OnAccept(self, event): |
---|
116 | """ |
---|
117 | Close window on accpetance |
---|
118 | """ |
---|
119 | event.Skip() |
---|
120 | |
---|
121 | def OnHelp(self, event): |
---|
122 | """ |
---|
123 | Provide help on opencl options. |
---|
124 | """ |
---|
125 | _TreeLocation = "user/gpu_computations.html" |
---|
126 | _anchor = "#device-selection" |
---|
127 | DocumentationWindow(self, -1, |
---|
128 | _TreeLocation, _anchor, "OpenCL Options Help") |
---|
129 | |
---|
130 | def OnClose(self, event): |
---|
131 | """ |
---|
132 | Close window |
---|
133 | """ |
---|
134 | event.Skip() |
---|
135 | |
---|
136 | ##### testing code ############################################################ |
---|
137 | class MyApp(wx.App): |
---|
138 | """ |
---|
139 | Class for running module as stand alone for testing |
---|
140 | """ |
---|
141 | def OnInit(self): |
---|
142 | """ |
---|
143 | Defines an init when running as standalone |
---|
144 | """ |
---|
145 | wx.InitAllImageHandlers() |
---|
146 | dialog = GpuOptions(None, -1, "") |
---|
147 | self.SetTopWindow(dialog) |
---|
148 | dialog.ShowModal() |
---|
149 | dialog.Destroy() |
---|
150 | return 1 |
---|
151 | |
---|
152 | # end of class MyApp |
---|
153 | |
---|
154 | if __name__ == "__main__": |
---|
155 | app = MyApp(0) |
---|
156 | app.MainLoop() |
---|