@@ -193,6 +193,38 @@ cdef void *call_compiler_python(const_char_p src, size_t sz,
193193ctypedef void * (* comp_f)(const_char_p, size_t, int * )
194194
195195def set_cuda_compiler_fn (fn ):
196+ """
197+ set_cuda_compiler_fn(fn)
198+
199+ Sets the compiler function for cuda kernels.
200+
201+ :param fn: compiler function
202+ :type fn: callable
203+ :rtype: None
204+
205+ `fn` must have the following signature::
206+
207+ fn(source)
208+
209+ It will recieve a python bytes string consiting the of complete
210+ kernel source code and must return a python byte string consisting
211+ of the compilation results or raise an exception.
212+
213+ .. warning::
214+
215+ Exceptions raised by the function will not be propagated
216+ because the call path goes through libcompyte. They are only
217+ used to indicate that there was a problem during the
218+ compilation.
219+
220+ This overrides the built-in compiler function with the provided
221+ one or resets to the default if `None` is given. The provided
222+ function must be rentrant if the library is used in a
223+ multi-threaded context.
224+
225+ .. note::
226+ If the "cuda" module was not compiled in libcompyte then this function will raise a `RuntimeError` unconditionaly.
227+ """
196228 cdef void (* set_comp)(comp_f f)
197229 set_comp = < void (* )(comp_f)> compyte_get_extension(" cuda_set_compiler" )
198230 if set_comp == NULL :
@@ -226,6 +258,20 @@ cdef dict NP_TO_TYPE = {
226258cdef dict TYPE_TO_NP = dict ((v, k) for k, v in NP_TO_TYPE.iteritems())
227259
228260def register_dtype (np.dtype dtype , cname ):
261+ """
262+ register_dtype(dtype, cname)
263+
264+ Make a new type known to the cluda machinery.
265+
266+ This function return the associted internal typecode for the new
267+ type.
268+
269+ :param dtype: new type
270+ :type dtype: numpy.dtype
271+ :param cname: C name for the type declarations
272+ :type cname: string
273+ :rtype: int
274+ """
229275 cdef compyte_type * t
230276 cdef int typecode
231277 cdef char * tmp
@@ -257,6 +303,15 @@ cdef public np.dtype typecode_to_dtype(int typecode):
257303 raise NotImplementedError (" TODO" )
258304
259305cpdef int dtype_to_typecode(dtype) except - 1 :
306+ """
307+ dtype_to_typecode(dtype)
308+
309+ Get the internal typecode for a type.
310+
311+ :param dtype: type to get the code for
312+ :type dtype: numpy.dtype
313+ :rtype: int
314+ """
260315 if isinstance (dtype, int ):
261316 return dtype
262317 if isinstance (dtype, str ):
@@ -268,6 +323,15 @@ cpdef int dtype_to_typecode(dtype) except -1:
268323 raise ValueError (" don't know how to convert to dtype: %s " % (dtype,))
269324
270325def dtype_to_ctype (dtype ):
326+ """
327+ dtype_to_ctype(dtype)
328+
329+ Return the C name for a type.
330+
331+ :param dtype: type to get the name for
332+ :type dtype: numpy.dtype
333+ :rtype: string
334+ """
271335 cdef int typecode = dtype_to_typecode(dtype)
272336 cdef compyte_type * t = compyte_get_type(typecode)
273337 if t.cluda_name == NULL :
@@ -277,15 +341,21 @@ def dtype_to_ctype(dtype):
277341cdef ga_order to_ga_order(ord ) except < ga_order> - 2 :
278342 if ord == " C" or ord == " c" :
279343 return GA_C_ORDER
280- elif ord == " A" or ord == " a" :
344+ elif ord == " A" or ord == " a" or ord is None :
281345 return GA_ANY_ORDER
282346 elif ord == " F" or ord == " f" :
283347 return GA_F_ORDER
284348 else :
285349 raise ValueError (" Valid orders are: 'A' (any), 'C' (C), 'F' (Fortran)" )
286350
287351class GpuArrayException (Exception ):
352+ """
353+ Exception used for all errors related to libcompyte.
354+ """
288355 def __init__ (self , msg , errcode ):
356+ """
357+ __init__(self, msg, errcode)
358+ """
289359 Exception .__init__ (self , msg)
290360 self .errcode = errcode
291361
@@ -635,10 +705,18 @@ def asfortranarray(a, dtype=None, GpuArray context=None):
635705 context = context)
636706
637707def may_share_memory (GpuArray a not None , GpuArray b not None ):
708+ """
709+ may_share_memory(a, b)
710+
711+ Returns True if `a` and `b` may share memory, False otherwise.
712+ """
638713 return array_share(a, b)
639714
640715def from_gpudata (size_t data , offset , dtype , shape , GpuContext context = None ,
641716 strides = None , writable = True , base = None , cls = None ):
717+ """
718+ from_gpudata(data, offset, dtype, shape, context=None, strides=None, writable=True, base=None, cls=None)
719+ """
642720 cdef GpuArray res
643721 cdef size_t * cdims
644722 cdef ssize_t * cstrides
0 commit comments