<commit_before>"""
This is a test for the last block scan.
"""


import MyML.helper.scan as scan
import numpy as np
from numba import cuda
from timeit import default_timer as timer

import sys

def last_block_test():

    MAX_TPB = 512
    n = 1024

    a = np.arange(n).astype(np.int32)
    reference = np.empty_like(a)

    start = timer()
    scan.exprefixsumNumba(a, reference, init = 0)
    end = timer()

    auxidx = -1

    elb = a.size
    p2elb = np.int(np.ceil(np.log2(elb)))
    telb = 2 ** p2elb
    tlb = telb / 2
    startIdx = 0

    sm_size = telb * a.itemsize

    aux = np.empty(1,dtype=np.int8)

    trash = cuda.device_array(1)

    e1, e2 = cuda.event(), cuda.event()

    e1.record()
    scan.last_scan[1, tlb, 0, sm_size](a, aux, -1, elb, startIdx)
    e2.record()

    print "CPU took:    ", (end - start) * 1000, " ms"
    print "Kernel took: ", cuda.event_elapsed_time(e1,e2), " ms"

    print (a == reference).all()

def recursive_big_scan_test():

    print "running recursive scan test"

    MAX_TPB = 512
    n = 50000000

    a = np.arange(n).astype(np.int32) 
    reference = np.empty_like(a)

    start = timer()
    sum_ref = scan.exprefixsumNumba(a, reference, init = 0)
    end = timer()

    dA = cuda.to_device(a)

    # e1, e2 = cuda.event(), cuda.event()

    # e1.record()
    # e2.record()


    start2 = timer()
    total_sum = scan.scan_gpu(dA)
    end2 = timer()
    

    dA.copy_to_host(ary = a)
    sum_gpu = total_sum.copy_to_host()
    

    print "sum_ref = ", sum_ref
    print "sum_gpu = ", sum_gpu<commit_msg>gpu scan<commit_after>"""
This is a test for the last block scan.
"""


import MyML.helper.scan as scan
import numpy as np
from numba import cuda
from timeit import default_timer as timer

import sys

def last_block_test():

    MAX_TPB = 512
    n = 1024

    a = np.arange(n).astype(np.int32)
    reference = np.empty_like(a)

    start = timer()
    scan.exprefixsumNumba(a, reference, init = 0)
    end = timer()

    auxidx = -1

    elb = a.size
    p2elb = np.int(np.ceil(np.log2(elb)))
    telb = 2 ** p2elb
    tlb = telb / 2
    startIdx = 0

    sm_size = telb * a.itemsize

    aux = np.empty(1,dtype=np.int8)

    trash = cuda.device_array(1)

    e1, e2 = cuda.event(), cuda.event()

    e1.record()
    scan.last_scan[1, tlb, 0, sm_size](a, aux, -1, elb, startIdx)
    e2.record()

    print "CPU took:    ", (end - start) * 1000, " ms"
    print "Kernel took: ", cuda.event_elapsed_time(e1,e2), " ms"

    print (a == reference).all()

def recursive_big_scan_test():

    print "running recursive scan test"

    MAX_TPB = 512
    n = 50000

    a = np.arange(n).astype(np.int32) 
    reference = np.empty_like(a)

    start = timer()
    sum_ref = scan.exprefixsumNumba(a, reference, init = 0)
    end = timer()

    dA = cuda.to_device(a)

    # e1, e2 = cuda.event(), cuda.event()

    # e1.record()
    # e2.record()


    start2 = timer()
    total_sum = scan.scan_gpu(dA)
    end2 = timer()
    

    dA.copy_to_host(ary = a)
    sum_gpu = total_sum.copy_to_host()
    

    print "sum_ref = ", sum_ref
    print "sum_gpu = ", sum_gpu
{'fraction_non_alphanumeric': 0.1358974358974359, 'fraction_numerical': 0.033012820512820513, 'mean_word_length': 2.4988789237668163, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7005139', 'n_tokens_mistral': 1327, 'n_tokens_neox': 1225, 'n_words': 292}