Skip to content
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