Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for tril, triu when kernel_sched returns LS, GS such that LS*GS < N #589

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions pygpu/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from .gpuarray import GpuArray, GpuKernel, SIZE, dtype_to_ctype
import numpy


def _generate_kernel(ctx, cols, dtype, upper=True):
tmpl = Template("""
#include "cluda.h"
Expand Down Expand Up @@ -54,7 +55,17 @@ def triu(A, inplace=True):
upper = True
cols = A.shape[1]
k = _generate_kernel(A.context, cols, A.dtype, upper)
k(A, A.offset, A.shape[0] * A.shape[1], n=A.shape[0] * A.shape[1])
n = int(A.shape[0]*A.shape[1])
ls = 256
if n < ls:
ls = n
gs = 1
else:
(gs, r) = divmod(n, ls)
if r > 0:
gs += 1

k(A, A.offset, A.shape[0] * A.shape[1], ls=ls, gs=gs)
return A


Expand All @@ -73,5 +84,15 @@ def tril(A, inplace=True):
upper = False
cols = A.shape[1]
k = _generate_kernel(A.context, cols, A.dtype, upper)
k(A, A.offset, A.shape[0] * A.shape[1], n=A.shape[0] * A.shape[1])
n = int(A.shape[0]*A.shape[1])
ls = 256
if n < ls:
ls = n
gs = 1
else:
(gs, r) = divmod(n, ls)
if r > 0:
gs += 1

k(A, A.offset, A.shape[0] * A.shape[1], ls=ls, gs=gs)
return A