<commit_before>"""
Sample low-level HSA runtime example.

This sample tries to mimick the vector_copy example
"""
from __future__ import print_function, division

import numpy as np
from numba.hsa.hsadrv.driver import hsa, BrigModule
from numba.hsa.hsadrv import drvapi, enums

def create_program(device, brig_file, symbol):
    brig_module = BrigModule.from_file(brig_file)
    symbol_offset = brig_module.find_symbol_offset(symbol)
    print("symbol {0} at offset {1}".format(symbol, symbol_offset))
    program = hsa.create_program([device])
    module = program.add_module(brig_module)

    code_descriptor = program.finalize(device, module, symbol_offset)

    return program, code_descriptor


def get_kernarg(region, result):
    flags = drvapi.hsa_region_flag_t()
    hsa.hsa_region_get_info(region, enums.HSA_REGION_INFO_FLAGS, ctypes.byref(flags))
    print("region {0} with flags {1}".format(hex(region), hex(flags.value)))
    if flags & enums.HSA_REGION_FLAG_KERNARG:
        result.value = region.value

    return enums.HSA_STATUS_SUCCESS
<commit_msg>added ctypes import<commit_after>"""
Sample low-level HSA runtime example.

This sample tries to mimick the vector_copy example
"""
from __future__ import print_function, division

import numpy as np
from numba.hsa.hsadrv.driver import hsa, BrigModule
from numba.hsa.hsadrv import drvapi, enums
import ctypes

def create_program(device, brig_file, symbol):
    brig_module = BrigModule.from_file(brig_file)
    symbol_offset = brig_module.find_symbol_offset(symbol)
    print("symbol {0} at offset {1}".format(symbol, symbol_offset))
    program = hsa.create_program([device])
    module = program.add_module(brig_module)

    code_descriptor = program.finalize(device, module, symbol_offset)

    return program, code_descriptor


def get_kernarg(region, result):
    flags = drvapi.hsa_region_flag_t()
    hsa.hsa_region_get_info(region, enums.HSA_REGION_INFO_FLAGS, ctypes.byref(flags))
    print("region {0} with flags {1}".format(hex(region), hex(flags.value)))
    if flags & enums.HSA_REGION_FLAG_KERNARG:
        result.value = region.value

    return enums.HSA_STATUS_SUCCESS

{'fraction_non_alphanumeric': 0.09479553903345725, 'fraction_numerical': 0.0037174721189591076, 'mean_word_length': 5.0647887323943666, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, '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': '4981965', 'n_tokens_mistral': 710, 'n_tokens_neox': 703, 'n_words': 162}