Exemple #1
0
def get_astype_function(dtype_dest, dtype_src, pitch=True):
    type_dest = dtype_to_ctype(dtype_dest)
    type_src = dtype_to_ctype(dtype_src)
    name = "astype"

    operation = ""

    if pitch:
        func = func_compile(
            name, pitch_template % {
                "name": name,
                "dest_type": type_dest,
                "src_type": type_src,
                "operation": operation,
            })
        func.prepare(
            [np.int32, np.int32, np.intp, np.int32, np.intp, np.int32])
    else:
        func = func_compile(
            name, non_pitch_template % {
                "name": name,
                "dest_type": type_dest,
                "src_type": type_src,
                "operation": operation,
            })
        func.prepare([np.intp, np.intp, np.int32])
    return func
Exemple #2
0
def get_conj_function(dtype, pitch=True):

    type_src = dtype_to_ctype(dtype)
    if dtype == np.complex128:
        operation = "pycuda::conj"
    elif dtype == np.complex64:
        operation = "pycuda::conj"
    else:
        raise TypeError(
            "Only complex arrays are allowed to perform conjugation")

    name = "conj"

    if pitch:
        func = func_compile(
            name, pitch_template % {
                "name": name,
                "dest_type": type_src,
                "src_type": type_src,
                "operation": operation,
            })
        func.prepare(
            [np.int32, np.int32, np.intp, np.int32, np.intp, np.int32])
    else:
        func = func_compile(
            name, non_pitch_template % {
                "name": name,
                "dest_type": type_src,
                "src_type": type_src,
                "operation": operation,
            })
        func.prepare([np.intp, np.intp, np.int32])

    return func
Exemple #3
0
def get_divarray_function(left_dtype, right_dtype, rslt_dtype, pitch = True):
    type_left = dtype_to_ctype(left_dtype)
    type_right = dtype_to_ctype(right_dtype)
    type_rslt = dtype_to_ctype(rslt_dtype)

    name = "divarray"
    operation = "/"

    if pitch:
        func = func_compile(name, pitch_array_op_template % {"name": name,
                   "dest_type": type_rslt,
                   "left_type": type_left,
                   "right_type": type_right,
                   "operation": operation,
                   })
        func.prepare([np.int32, np.int32, np.intp, np.int32, np.intp, np.int32, np.intp, np.int32])
    else:
        func = func_compile(name, non_pitch_array_op_template % {"name": name,
                   "dest_type": type_rslt,
                   "left_type": type_left,
                   "right_type": type_right,
                   "operation": operation,
                   })
        func.prepare([np.intp, np.intp, np.intp, np.int32])
    return func
Exemple #4
0
def get_divarray_function(left_dtype, right_dtype, rslt_dtype, pitch=True):
    type_left = dtype_to_ctype(left_dtype)
    type_right = dtype_to_ctype(right_dtype)
    type_rslt = dtype_to_ctype(rslt_dtype)

    name = "divarray"
    operation = "/"

    if pitch:
        func = func_compile(
            name, pitch_array_op_template % {
                "name": name,
                "dest_type": type_rslt,
                "left_type": type_left,
                "right_type": type_right,
                "operation": operation,
            })
        func.prepare([
            np.int32, np.int32, np.intp, np.int32, np.intp, np.int32, np.intp,
            np.int32
        ])
    else:
        func = func_compile(
            name, non_pitch_array_op_template % {
                "name": name,
                "dest_type": type_rslt,
                "left_type": type_left,
                "right_type": type_right,
                "operation": operation,
            })
        func.prepare([np.intp, np.intp, np.intp, np.int32])
    return func
Exemple #5
0
def get_scalardiv_function(src_type, pitch=True):
    type_src = dtype_to_ctype(src_type)

    name = "scalardiv"
    operation = "/"

    if pitch:
        func = func_compile(
            name, pitch_right_scalar_op_template % {
                "name": name,
                "dest_type": type_src,
                "operation": operation,
            })
        func.prepare([
            np.int32, np.int32, np.intp, np.int32, np.intp, np.int32,
            src_type.type
        ])
    else:
        func = func_compile(
            name, non_pitch_right_scalar_op_template % {
                "name": name,
                "dest_type": type_src,
                "operation": operation,
            })
        func.prepare([np.intp, np.intp, src_type.type, np.int32])
    return func
Exemple #6
0
def get_conj_function(dtype, pitch = True):
    
    type_src = dtype_to_ctype(dtype)
    if dtype == np.complex128:
        operation = "pycuda::conj"
    elif dtype == np.complex64:
        operation = "pycuda::conj"
    else:
        raise TypeError("Only complex arrays are allowed to perform conjugation")
    
    name = "conj"
    
    if pitch:
        func = func_compile(name, pitch_template % {"name": name,
                   "dest_type": type_src,
                   "src_type": type_src,
                   "operation": operation,
                   })
        func.prepare([np.int32, np.int32, np.intp, np.int32, np.intp, np.int32])
    else:
        func = func_compile(name, non_pitch_template % {"name": name,
                   "dest_type": type_src,
                   "src_type": type_src,
                   "operation": operation,
                   })
        func.prepare([np.intp, np.intp, np.int32])
    
    return func
Exemple #7
0
def get_fill_function(dtype, pitch = True):
    type_dst = dtype_to_ctype(dtype)
    name = "fill"
    
    if pitch:
        func = func_compile(name, fill_pitch_template % {"name": name,
                       "type_dst": type_dst})
        func.prepare([np.int32, np.int32, np.intp, np.int32, dtype.type])
    else:
        func = func_compile(name, fill_nonpitch_template % {"name": name,
                       "type_dst": type_dst})
        func.prepare([np.int32, np.intp, dtype.type])
    return func
Exemple #8
0
def get_realimag_function(dtype, real=True, pitch=True):
    type_src = dtype_to_ctype(dtype)

    if dtype == np.complex64:
        type_dest = "float"
        if real:
            operation = "pycuda::real"
            name = "real"
        else:
            operation = "pycuda::imag"
            name = "imag"
    elif dtype == np.complex128:
        type_dest = "double"
        if real:
            operation = "pycuda::real"
            name = "real"
        else:
            operation = "pycuda::imag"
            name = "imag"
    else:
        raise TypeError(
            "only support complex inputs as numpy.complex64 or numpy.complex128"
        )

    if pitch:
        func = func_compile(
            name, pitch_template % {
                "name": name,
                "dest_type": type_dest,
                "src_type": type_src,
                "operation": operation,
            })
        func.prepare(
            [np.int32, np.int32, np.intp, np.int32, np.intp, np.int32])
    else:
        func = func_compile(
            name, non_pitch_template % {
                "name": name,
                "dest_type": type_dest,
                "src_type": type_src,
                "operation": operation,
            })
        func.prepare([np.intp, np.intp, np.int32])
    return func
Exemple #9
0
def get_scalardiv_function(src_type, pitch = True):
    type_src = dtype_to_ctype(src_type)

    name = "scalardiv"
    operation = "/"
    
    if pitch:
        func = func_compile(name, pitch_right_scalar_op_template % {"name": name,
                   "dest_type": type_src,
                   "operation": operation,
                   })
        func.prepare([np.int32, np.int32, np.intp, np.int32, np.intp, np.int32, src_type.type])
    else:
        func = func_compile(name, non_pitch_right_scalar_op_template % {"name": name,
                   "dest_type": type_src,
                   "operation": operation,
                   })
        func.prepare([np.intp, np.intp, src_type.type, np.int32])
    return func
Exemple #10
0
def get_fill_function(dtype, pitch=True):
    type_dst = dtype_to_ctype(dtype)
    name = "fill"

    if pitch:
        func = func_compile(
            name, fill_pitch_template % {
                "name": name,
                "type_dst": type_dst
            })
        func.prepare([np.int32, np.int32, np.intp, np.int32, dtype.type])
    else:
        func = func_compile(
            name, fill_nonpitch_template % {
                "name": name,
                "type_dst": type_dst
            })
        func.prepare([np.int32, np.intp, dtype.type])
    return func
Exemple #11
0
def get_abs_function(dtype, pitch=True):
    type_src = dtype_to_ctype(dtype)

    if dtype == np.complex128:
        operation = "pycuda::abs"
        type_dest = "double"
    elif dtype == np.complex64:
        operation = "pycuda::abs"
        type_dest = "float"
    elif dtype == np.float64:
        operation = "fabs"
        type_dest = "double"
    elif dtype == np.float32:
        operation = "fabsf"
        type_dest = "float"
    else:
        operation = "abs"
        type_dest = dtype_to_ctype(dtype)

    name = "abs_function"

    if pitch:
        func = func_compile(
            name, pitch_template % {
                "name": name,
                "dest_type": type_dest,
                "src_type": type_src,
                "operation": operation,
            })
        func.prepare(
            [np.int32, np.int32, np.intp, np.int32, np.intp, np.int32])
    else:
        func = func_compile(
            name, non_pitch_template % {
                "name": name,
                "dest_type": type_dest,
                "src_type": type_src,
                "operation": operation,
            })
        func.prepare([np.intp, np.intp, np.int32])

    return func
Exemple #12
0
def get_resize_function(dtype):
    type_src = dtype_to_ctype(dtype)
    name = "resize"
    
    func = func_compile(name, reshape_template % {"name": name,
                   "dest_type": type_src,
                   "src_type": type_src,
                   "operation": "",
                   })
    func.prepare([np.int32, np.int32, np.int32, np.int32, np.intp, np.int32, np.intp, np.int32])
    return func
Exemple #13
0
def get_astype_function(dtype_dest, dtype_src, pitch = True):
    type_dest = dtype_to_ctype(dtype_dest)
    type_src = dtype_to_ctype(dtype_src)
    name = "astype"
    
    operation = ""
    
    if pitch:
        func = func_compile(name, pitch_template % {"name": name,
                   "dest_type": type_dest,
                   "src_type": type_src,
                   "operation": operation,
                   })
        func.prepare([np.int32, np.int32, np.intp, np.int32, np.intp, np.int32])
    else:
        func = func_compile(name, non_pitch_template % {"name": name,
                   "dest_type": type_dest,
                   "src_type": type_src,
                   "operation": operation,
                   })
        func.prepare([np.intp, np.intp, np.int32])
    return func
Exemple #14
0
def get_abs_function(dtype, pitch = True):
    type_src = dtype_to_ctype(dtype)

    if dtype == np.complex128:
        operation = "pycuda::abs"
        type_dest = "double"
    elif dtype == np.complex64:
        operation = "pycuda::abs"
        type_dest = "float"
    elif dtype == np.float64:
        operation = "fabs"
        type_dest = "double"
    elif dtype == np.float32:
        operation = "fabsf"
        type_dest = "float"
    else:
        operation = "abs"
        type_dest = dtype_to_ctype(dtype)
    
    name = "abs_function"
    
    
    if pitch:
        func = func_compile(name, pitch_template % {"name": name,
                   "dest_type": type_dest,
                   "src_type": type_src,
                   "operation": operation,
                   })
        func.prepare([np.int32, np.int32, np.intp, np.int32, np.intp, np.int32])
    else:
        func = func_compile(name, non_pitch_template % {"name": name,
                   "dest_type": type_dest,
                   "src_type": type_src,
                   "operation": operation,
                   })
        func.prepare([np.intp, np.intp, np.int32])
    
    return func
Exemple #15
0
def get_transpose_function(dtype, conj = False):

    src_type = dtype_to_ctype(dtype)
    name = "trans"
    operation = ""
    if conj:
        if dtype == np.complex128:
            operation = "pycuda::conj"
        elif dtype == np.complex64:
            operation = "pycuda::conj"
    
    func = func_compile(name, transpose_template % {"name": name, "type": src_type, "operation": operation})
    func.prepare([np.int32, np.int32, np.intp, np.int32, np.intp, np.int32])
    return func
Exemple #16
0
def get_realimag_function(dtype, real = True, pitch = True):
    type_src = dtype_to_ctype(dtype)
    
    if dtype == np.complex64:
        type_dest = "float"
        if real:
            operation = "pycuda::real"
            name = "real"
        else:
            operation = "pycuda::imag"
            name = "imag"
    elif dtype == np.complex128:
        type_dest = "double"
        if real:
            operation = "pycuda::real"
            name = "real"
        else:
            operation = "pycuda::imag"
            name = "imag"
    else:
        raise TypeError("only support complex inputs as numpy.complex64 or numpy.complex128")
    
    if pitch:
        func = func_compile(name, pitch_template % {"name": name,
                   "dest_type": type_dest,
                   "src_type": type_src,
                   "operation": operation,
                   })
        func.prepare([np.int32, np.int32, np.intp, np.int32, np.intp, np.int32])
    else:
        func = func_compile(name, non_pitch_template % {"name": name,
                   "dest_type": type_dest,
                   "src_type": type_src,
                   "operation": operation,
                   })
        func.prepare([np.intp, np.intp, np.int32])
    return func
Exemple #17
0
def get_resize_function(dtype):
    type_src = dtype_to_ctype(dtype)
    name = "resize"

    func = func_compile(
        name, reshape_template % {
            "name": name,
            "dest_type": type_src,
            "src_type": type_src,
            "operation": "",
        })
    func.prepare([
        np.int32, np.int32, np.int32, np.int32, np.intp, np.int32, np.intp,
        np.int32
    ])
    return func
Exemple #18
0
def get_transpose_function(dtype, conj=False):

    src_type = dtype_to_ctype(dtype)
    name = "trans"
    operation = ""
    if conj:
        if dtype == np.complex128:
            operation = "pycuda::conj"
        elif dtype == np.complex64:
            operation = "pycuda::conj"

    func = func_compile(
        name, transpose_template % {
            "name": name,
            "type": src_type,
            "operation": operation
        })
    func.prepare([np.int32, np.int32, np.intp, np.int32, np.intp, np.int32])
    return func