Discussion:
pyCUDA kill app with using pyQt5
(too old to reply)
안태우
2018-01-06 19:03:04 UTC
Permalink
Hello, all.I'm using pycuda for making simple project with pyQt5. But when I programed like this(in Windows 10, Python 3.6.2), app is aborted with printing bottom logs.​-------------------------------------------------------------------PyCUDA ERROR: The context stack was not empty upon module cleanup.-------------------------------------------------------------------A context was still active when the context stack was beingcleaned up. At this point in our execution, CUDA may alreadyhave been deinitialized, so there is no way we can finishcleanly. The program will be aborted now.Use Context.pop() to avoid this problem.------------------------------------------------------------------​My code is like this.Could you give me some help? ​main.py​ import sys from PyQt5 import uic from PyQt5.QtGui import * from PyQt5.QtWidgets import * from PyQt5.QtCore import * from PIL.ImageQt import ImageQt import fractal​ form_class = uic.loadUiType("main.ui")[0]​ class Form(QMainWindow, form_class): DRAW_MANDELBROT = 1​ def __init__(self): super().__init__() self.setupUi(self) self.setWindowFlags(Qt.MSWindowsFixedSizeDialogHint) self.setFixedSize(self.size()) self.drawfractal(self.DRAW_MANDELBROT)​ def wheelEvent(self, event: QWheelEvent): pos = QWidget.mapFromGlobal(QCursor.pos()) // when this event happens, error occurs. print(pos)​ def drawfractal(self, sort): global img if sort is self.DRAW_MANDELBROT: img = fractal.mandelbrot(-2, -2, self.size().width() * 2, 400)​ qimg = QPixmap.fromImage(ImageQt(img)) qimg = qimg.scaled(self.size(), Qt.KeepAspectRatio, Qt.SmoothTransformation) self.label.setPixmap(qimg)​​ if __name__ == "__main__": app = QApplication(sys.argv) w = Form() w.show() sys.exit(app.exec())​​fractal.py​ import pycuda.autoinit import pycuda.driver as cuda from pycuda.compiler import SourceModule import numpy as np import matplotlib.cm as cm from matplotlib.colors import Normalize from PIL import Image​ ...​ def mandelbrot(startx, starty, size, precision): matrix = np.array([startx, starty, size, precision], np.float32) result = np.empty((size, size), np.int32) matrix_gpu = cuda.mem_alloc(matrix.nbytes) result_gpu = cuda.mem_alloc(result.nbytes)​ cuda.memcpy_htod(matrix_gpu, matrix)​ func = cu.get_function("mandelbrot") func(matrix_gpu, result_gpu, block=(1, 1, 1), grid=(size, size))​ cuda.memcpy_dtoh(result, result_gpu)​ return array2imgarray(result, 'nipy_spectral') Thanks
Andreas Kloeckner
2018-01-06 20:15:02 UTC
Permalink
Hello, all.I'm using pycuda for making simple project with pyQt5. But when I programed like this(in Windows 10, Python 3.6.2), app is aborted with printing bottom logs.​-------------------------------------------------------------------PyCUDA ERROR: The context stack was not empty upon module cleanup.-------------------------------------------------------------------A context was still active when the context stack was beingcleaned up. At this point in our execution, CUDA may alreadyhave been deinitialized, so there is no way we can finishcleanly. The program will be aborted now.Use Context.pop() to avoid this problem.------------------------------------------------------------------​My code is like this.Could you give me some help? ​main.py​ import sys from PyQt5 import uic from PyQt5.QtGui import * from PyQt5.QtWidgets import * from PyQt5.QtCore import * from PIL.ImageQt import ImageQt import fractal​ form_class = uic.loadUiType("main.ui")[0]​ class Form(QMainWindow, form_class): DRAW_MANDELBROT = 1​ def __init__(self): super().__init__() self.setupUi(self) self.setWindowFlags(Qt.MSWindowsFixedSizeDialogHint) self.setFixedSize(self.size()) self.drawfractal(self.DRAW_MANDELBROT)​ def wheelEvent(self, event: QWheelEvent): pos = QWidget.mapFromGlobal(QCursor.pos()) // when this event happens, error occurs. print(pos)​ def drawfractal(self, sort): global img if sort is self.DRAW_MANDELBROT: img = fractal.mandelbrot(-2, -2, self.size().width() * 2, 400)​ qimg = QPixmap.fromImage(ImageQt(img)) qimg = qimg.scaled(self.size(), Qt.KeepAspectRatio, Qt.SmoothTransformation) self.label.setPixmap(qimg)​​ if __name__ == "__main__": app = QApplication(sys.argv) w = Form() w.show() sys.exit(app.exec())​​fractal.py​ import pycuda.autoinit import pycuda.driver as cuda from pycuda.compiler import SourceModule import numpy as np import matplotlib.cm as cm from matplotlib.colors import Normalize from PIL import Image​ ...​ def mandelbrot(startx, starty, size, precision): matrix = np.array([startx, starty, size, precision], np.float32) result = np.empty((size, size), np.int32) matrix_gpu = cuda.mem_alloc(matrix.nbytes) result_gpu = cuda.mem_alloc(result.nbytes)​ cuda.memcpy_htod(matrix_gpu, matrix)​ func = cu.get_function("mandelbrot") func(matrix_gpu, result_gpu, block=(1, 1, 1), grid=(size, size))​ cuda.memcpy_dtoh(result, result_gpu)​ return array2imgarray(result, 'nipy_spectral') Thanks
Can you supply a stack trace of the crash? Could you confirm that
PyCUDA's atexit function runs?

Andreas
안태우
2018-01-07 08:47:13 UTC
Permalink
​​-----Original Message-----
From: "Andreas Kloeckner"<***@informa.tiker.net>
To: "안태우"<***@alphago.pe.kr>; ;
Cc:
Sent: 2018-01-07 (음) 05:15:02
Subject: Re: [PyCUDA] pyCUDA kill app with using pyQt5

안태우<***@alphago.pe.kr> writes:
> Hello, all.I'm using pycuda for making simple project with pyQt5. But when I programed like this(in Windows 10, Python 3.6.2), app is aborted with printing bottom logs.​-------------------------------------------------------------------PyCUDA ERROR: The context stack was not empty upon module cleanup.-------------------------------------------------------------------A context was still active when the context stack was beingcleaned up. At this point in our execution, CUDA may alreadyhave been deinitialized, so there is no way we can finishcleanly. The program will be aborted now.Use Context.pop() to avoid this problem.------------------------------------------------------------------​My code is like this.Could you give me some help? ​main.py​ import sys from PyQt5 import uic from PyQt5.QtGui import * from PyQt5.QtWidgets import * from PyQt5.QtCore import * from PIL.ImageQt import ImageQt import fractal​ form_class = uic.loadUiType("main.ui")[0]​ class Form(QMainWindow, form_class): DRAW_MANDELBROT = 1​ def __init__(self): super().__init__() self.setupUi(self) self.setWindowFlags(Qt.MSWindowsFixedSizeDialogHint) self.setFixedSize(self.size()) self.drawfractal(self.DRAW_MANDELBROT)​ def wheelEvent(self, event: QWheelEvent): pos = QWidget.mapFromGlobal(QCursor.pos()) // when this event happens, error occurs. print(pos)​ def drawfractal(self, sort): global img if sort is self.DRAW_MANDELBROT: img = fractal.mandelbrot(-2, -2, self.size().width() * 2, 400)​ qimg = QPixmap.fromImage(ImageQt(img)) qimg = qimg.scaled(self.size(), Qt.KeepAspectRatio, Qt.SmoothTransformation) self.label.setPixmap(qimg)​​ if __name__ == "__main__": app = QApplication(sys.argv) w = Form() w.show() sys.exit(app.exec())​​fractal.py​ import pycuda.autoinit import pycuda.driver as cuda from pycuda.compiler import SourceModule import numpy as np import matplotlib.cm as cm from matplotlib.colors import Normalize from PIL import Image​ ...​ def mandelbrot(startx, starty, size, precision): matrix = np.array([startx, starty, size, precision], np.float32) result = np.empty((size, size), np.int32) matrix_gpu = cuda.mem_alloc(matrix.nbytes) result_gpu = cuda.mem_alloc(result.nbytes)​ cuda.memcpy_htod(matrix_gpu, matrix)​ func = cu.get_function("mandelbrot") func(matrix_gpu, result_gpu, block=(1, 1, 1), grid=(size, size))​ cuda.memcpy_dtoh(result, result_gpu)​ return array2imgarray(result, 'nipy_spectral') Thanks

Can you supply a stack trace of the crash? Could you confirm that
PyCUDA's atexit function runs?

Andreas​Oh, sorry. When I change some parts, it can run well. I'm very sorry for not checking in detail.By changing like this,​def wheelEvent(self, event: QWheelEvent): p = QCursor.pos() pos = QWidget.mapFromGlobal(self.label, p) print(pos)​Thanks
Loading...