Hello. I have been trying to create some OpenGL examples for PyCUDA and found program that segfaults. I cannot debug it fully as the last 8 functions are from NVIDIA libraries. The last known function in the trace is cuda::context::detach.
Error is present on GTX460 (Fermi) and ION (9400M), on PyCUDA with my patch and without it. System information: Debian 64-bit, kernel 2.6.32, drivers 256.53, CUDA 3.1. PyCUDA from git. Can someone look at program and stack trace and tell whether there is some obvious mistake I am missing? If not, I think I will report upstream bug to NVIDIA. Regards. -- Tomasz Rybak <[email protected]> GPG/PGP key ID: 2AD5 9860 Fingerprint A481 824E 7DD3 9C0E C40A 488E C654 FB33 2AD5 9860 http://member.acm.org/~tomaszrybak
#! /usr/bin/python
import sys
import array
import math
import numpy
from OpenGL.GL import *
import pycuda
import pycuda.compiler
import pycuda.driver
import pycuda.gl
import pycuda.gpuarray
from PyQt4 import QtCore, QtGui, QtOpenGL
vertexSource = """#version 150 core
uniform mat4 projectionMatrix;
in vec3 vertexCoordinate;
void main() {
vec4 a = vec4(vertexCoordinate, 1.0);
a.z = a.z - 2.0;
gl_Position = projectionMatrix * a;
}
"""
fragmentSource = """#version 150 core
void main() {
gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);
}
"""
kernel = """
__global__ void compute(float3 *pos) {
unsigned int x = threadIdx.x;
// if (x < N) {
if (x % 2 == 0) {
pos[x].z = pos[x].z+1;
} else {
pos[x].z = pos[x].z-1;
}
// }
}
"""
class Widget(QtOpenGL.QGLWidget):
def __init__(self, parent = None):
super(Widget, self).__init__(parent)
def minimumSizeHint(self):
return QtCore.QSize(400, 300)
def sizeHint(self):
return QtCore.QSize(800, 600)
def initializeGL(self):
self.qglClearColor(QtCore.Qt.black)
glEnable(GL_DEPTH_TEST)
program = glCreateProgram()
vertexShader = glCreateShader(GL_VERTEX_SHADER)
glShaderSource(vertexShader, [vertexSource])
glCompileShader(vertexShader)
glAttachShader(program, vertexShader)
fragmentShader = glCreateShader(GL_FRAGMENT_SHADER)
glShaderSource(fragmentShader, [fragmentSource])
glCompileShader(fragmentShader)
glAttachShader(program, fragmentShader)
glBindAttribLocation(program, 0, 'vertexCoordinate')
glLinkProgram(program)
glValidateProgram(program)
glUseProgram(program)
self.projectionMatrixLocation = glGetUniformLocation(program, 'projectionMatrix')
self.data = numpy.zeros((99, 3), numpy.float32)
for i in range(33):
self.data[i*3+0, 0] = 0
self.data[i*3+0, 1] = 0
self.data[i*3+0, 2] = 0
self.data[i*3+1, 0] = 1*math.cos(math.pi*(i+0)/16)
self.data[i*3+1, 1] = 1*math.sin(math.pi*(i+0)/16)
self.data[i*3+1, 2] = 0
self.data[i*3+2, 0] = 1*math.cos(math.pi*(i+1)/16)
self.data[i*3+2, 1] = 1*math.sin(math.pi*(i+1)/16)
self.data[i*3+2, 2] = 0
self.gl_buffer = glGenBuffers(1)
glBindBuffer(GL_ARRAY_BUFFER, self.gl_buffer)
glBufferData(GL_ARRAY_BUFFER, self.data, GL_DYNAMIC_DRAW)
glVertexAttribPointer(0, 3, GL_FLOAT, False, 0, None)
glEnableVertexAttribArray(0)
import pycuda.gl.autoinit
k = pycuda.compiler.SourceModule(kernel)
self.cuda_function = k.get_function("compute")
self.cuda_function.prepare("P", (99, 1, 1))
self.cuda_buffer = pycuda.gl.BufferObject(long(self.gl_buffer))
def paintGL(self):
cuda_object = self.cuda_buffer.map()
self.cuda_function.prepared_call((1, 1), cuda_object.device_ptr())
pycuda.driver.Context.synchronize()
cuda_object.unmap()
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
glDrawArrays(GL_TRIANGLES, 0, 99)
def resizeGL(self, width, height):
side = min(width, height)
glViewport((width-side)/2, (height-side)/2, side, side)
projectionMatrix = numpy.zeros((4, 4), 'f')
top = +1.5
bottom = -1.5
left = -1.5
right = +1.5
near = 1.0
far = 3.0
projectionMatrix[0, 0] = (2.0)/(right-left)
projectionMatrix[0, 3] = -(right+left)/(right-left)
projectionMatrix[1, 1] = (2.0)/(top-bottom)
projectionMatrix[1, 3] = -(top+bottom)/(top-bottom)
projectionMatrix[2, 2] = -(2.0)/(far-near)
projectionMatrix[2, 3] = -(far+near)/(far-near)
projectionMatrix[3, 3] = 1.0
glUniformMatrix4fv(self.projectionMatrixLocation, 1, True, projectionMatrix)
def closeEvent(self, event):
self.makeCurrent()
glDeleteBuffers(1, long(self.gl_buffer))
del self.gl_buffer
del self.cuda_buffer
super(Widget, self).closeEvent(event)
class Window(QtGui.QWidget):
def __init__(self):
super(Window, self).__init__()
self.widget = Widget()
self.setWindowTitle("CUDA OpenGL")
layout = QtGui.QHBoxLayout()
layout.addWidget(self.widget)
self.setLayout(layout)
def closeEvent(self, event):
self.widget.close()
del self.widget
super(Window, self).closeEvent(event)
app = QtGui.QApplication(sys.argv)
window = Window()
window.show()
app.exec_()
#0 0x00007f659b244849 in ?? () from /usr/lib/libnvidia-glcore.so.256.53
(gdb) bt
#0 0x00007f659b244849 in ?? () from /usr/lib/libnvidia-glcore.so.256.53
#1 0x00007f659b2448d7 in ?? () from /usr/lib/libnvidia-glcore.so.256.53
#2 0x00007f659b24516e in ?? () from /usr/lib/libnvidia-glcore.so.256.53
#3 0x00007f6597d0e6e0 in ?? () from /usr/lib/libcuda.so.1
#4 0x00007f6597ca0294 in ?? () from /usr/lib/libcuda.so.1
#5 0x00007f6597c99bcb in ?? () from /usr/lib/libcuda.so.1
#6 0x00007f6597d47cbe in ?? () from /usr/lib/libcuda.so.1
#7 0x00007f6598b1cb00 in cuda::context::detach() ()
from /usr/lib/pymodules/python2.6/pycuda/_driver.so
#8 0x00007f6598b1cdb8 in
boost::detail::sp_counted_impl_p<cuda::context>::dispose() () from
/usr/lib/pymodules/python2.6/pycuda/_driver.so
#9 0x00007f6598ae69a9 in boost::detail::shared_count::~shared_count() ()
from /usr/lib/pymodules/python2.6/pycuda/_driver.so
#10 0x00007f6598b0b7cf in
boost::python::objects::pointer_holder<boost::shared_ptr<cuda::context>,
cuda::context>::~pointer_holder() ()
from /usr/lib/pymodules/python2.6/pycuda/_driver.so
#11 0x00007f659883b09e in boost::python::objects::instance_dealloc (inst=
<Context at remote 0x31130c8>) at libs/python/src/object/class.cpp:335
#12 0x000000000046d008 in subtype_dealloc (self=<Context at remote 0x31130c8>)
at ../Objects/typeobject.c:1019
#13 0x000000000044e217 in insertdict (mp=0x31783d0, key='context',
hash=-3481218393171069706, value=None) at ../Objects/dictobject.c:459
#14 0x0000000000450077 in PyDict_SetItem (op=
---Type <return> to continue, or q <return> to quit---
{'__builtins__': {'bytearray': <type at remote 0x871800>, 'IndexError':
<type at remote 0x820fc0>, 'all': <built-in function all>, 'help': <_Helper at
remote 0x7f65a0a06c10>, 'vars': <built-in function vars>, 'SyntaxError': <type
at remote 0x820940>, 'unicode': <type at remote 0x8321c0>,
'UnicodeDecodeError': <type at remote 0x8217e0>, 'isinstance': <built-in
function isinstance>, 'copyright': <_Printer(_Printer__data='Copyright (c)
2001-2010 Python Software Foundation.\nAll Rights Reserved.\n\nCopyright (c)
2000 BeOpen.com.\nAll Rights Reserved.\n\nCopyright (c) 1995-2001 Corporation
for National Research Initiatives.\nAll Rights Reserved.\n\nCopyright (c)
1991-1995 Stichting Mathematisch Centrum, Amsterdam.\nAll Rights Reserved.',
_Printer__lines=None, _Printer__name='copyright', _Printer__dirs=(),
_Printer__files=(...)) at remote 0x7f65a0a06d50>, 'NameError': <type at remote
0x820460>, 'BytesWarning': <type at remote 0x823860>, 'dict': <type at remote
0x8286c0>, 'input': <built-in function input>, 'oct': <...(truncated),
key='context', value=None) at ../Objects/dictobject.c:701
#15 0x000000000045261e in _PyModule_Clear (m=<value optimized out>)
at ../Objects/moduleobject.c:138
#16 0x00000000004bb4c4 in PyImport_Cleanup () at ../Python/import.c:476
#17 0x00000000004c90df in Py_Finalize () at ../Python/pythonrun.c:444
#18 0x000000000041a156 in Py_Main (argc=-1600565120,
argv=<value optimized out>) at ../Modules/main.c:602
#19 0x00007f659f48cc4d in __libc_start_main (main=<value optimized out>,
argc=<value optimized out>, ubp_av=<value optimized out>,
init=<value optimized out>, fini=<value optimized out>,
---Type <return> to continue, or q <return> to quit---
rtld_fini=<value optimized out>, stack_end=0x7fff5a3c7e38)
at libc-start.c:228
#20 0x00000000004198d9 in _start ()
(gdb)
signature.asc
Description: This is a digitally signed message part
_______________________________________________ PyCUDA mailing list [email protected] http://lists.tiker.net/listinfo/pycuda
