안태우
2018-01-06 19:03:04 UTC
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