This repository has been archived by the owner on Feb 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 61
VTune integration #814
Open
1e-to
wants to merge
4
commits into
IntelPython:master
Choose a base branch
from
1e-to:vtune_i
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
VTune integration #814
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import pandas as pd | ||
from numba import njit | ||
import sdc | ||
import vtune as vt | ||
from vtune import task_begin, task_end, domain, string_handle_create | ||
import ctypes | ||
import itt | ||
|
||
handle = string_handle_create("Function") | ||
|
||
|
||
@njit | ||
def dataframe_head(df): | ||
task_begin(domain, handle) | ||
series = df['A'].head(n=4) | ||
task_end(domain) | ||
return series | ||
|
||
|
||
df = pd.DataFrame({'A': [1, 2, 4, 6, 4, 2], 'B': [3., 2., 77., 2., 5., 6.5]}) | ||
|
||
print(dataframe_head(df)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import ctypes | ||
import itt | ||
import llvmlite.binding as ll | ||
from llvmlite.llvmpy.core import Type as LLType | ||
from llvmlite import ir as lir | ||
from llvmlite.llvmpy.core import Constant | ||
from inspect import signature | ||
import numba | ||
|
||
functype_domain = ctypes.CFUNCTYPE(ctypes.c_void_p, ctypes.c_char_p) | ||
ctypes_domain = functype_domain(itt.__itt_domain_create) | ||
domain = ctypes_domain(b"VTune.Profiling.SDC\0") | ||
|
||
functype_string_handle_create = ctypes.CFUNCTYPE(ctypes.c_void_p, ctypes.c_char_p) | ||
ctypes_string_handle_create = functype_string_handle_create(itt.__itt_string_handle_create) | ||
|
||
functype_task_begin = ctypes.CFUNCTYPE(None, ctypes.c_void_p, ctypes.c_void_p) | ||
task_begin = functype_task_begin(itt.__itt_task_begin) | ||
|
||
functype_task_end = ctypes.CFUNCTYPE(None, ctypes.c_void_p) | ||
task_end = functype_task_end(itt.__itt_task_end) | ||
|
||
ll.add_symbol('__itt_task_begin_new', itt.__itt_task_begin) | ||
ll.add_symbol('__itt_task_end_new', itt.__itt_task_end) | ||
|
||
|
||
def string_handle_create(string): | ||
return ctypes_string_handle_create(string.encode()) | ||
|
||
|
||
def vtune_profiling_boxing(name_handle): | ||
def task(func): | ||
handle = string_handle_create(name_handle) | ||
|
||
def wrapper(typ, val, c): | ||
fnty = LLType.function(LLType.void(), [c.pyapi.voidptr, c.pyapi.voidptr]) | ||
fn = c.pyapi._get_function(fnty, name="__itt_task_begin_new") | ||
domain_const = lir.Constant(LLType.int(64), domain) | ||
handle_const = lir.Constant(LLType.int(64), handle) | ||
c.builder.call(fn, [Constant.inttoptr(domain_const, c.pyapi.voidptr), | ||
Constant.inttoptr(handle_const, c.pyapi.voidptr)]) | ||
|
||
return_value = func(typ, val, c) | ||
|
||
fnty_end = LLType.function(LLType.void(), [c.pyapi.voidptr]) | ||
fn_end = c.pyapi._get_function(fnty_end, name="__itt_task_end_new") | ||
c.builder.call(fn_end, [Constant.inttoptr(domain_const, c.pyapi.voidptr)]) | ||
|
||
return return_value | ||
|
||
return wrapper | ||
|
||
return task | ||
|
||
|
||
def vtune_profiling_overload(name_handle): | ||
def task(func): | ||
handle = string_handle_create(name_handle) | ||
args = signature(func) | ||
return exec_impl(func, handle) | ||
|
||
return task | ||
|
||
|
||
def codegen_exec_impl(func, handle): | ||
sig = signature(func) | ||
sig_str = str(sig) | ||
args_str = ', '.join(sig.parameters.keys()) | ||
func_lines = [f"def wrapper{sig_str}:", | ||
f" overload_result = func({args_str})", | ||
f" result = numba.njit(overload_result)", | ||
f" def for_jit{sig_str}:", | ||
f" task_begin(domain, handle)", | ||
f" return_value = result({args_str})", | ||
f" task_end(domain)", | ||
f" return return_value", | ||
f" return for_jit"] | ||
|
||
func_text = '\n'.join(func_lines) | ||
global_vars = {"func": func, | ||
"numba": numba, | ||
"domain": domain, | ||
"handle": handle, | ||
"task_begin": task_begin, | ||
"task_end": task_end | ||
} | ||
|
||
return func_text, global_vars | ||
|
||
|
||
def exec_impl(func, handle): | ||
func_text, global_vars = codegen_exec_impl(func, handle) | ||
loc_vars = {} | ||
exec(func_text, global_vars, loc_vars) | ||
_impl = loc_vars['wrapper'] | ||
|
||
return _impl |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be part of
sdc_overload_method
decorator. We can extract type name and method name from where.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You actually could call this decorator inside
sdc_overload_method