Skip to content
This repository has been archived by the owner on Feb 2, 2024. It is now read-only.

VTune integration #814

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions examples/vtune_integration/basic_usage_vtune_profiler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import pandas as pd
from numba import njit
import sdc
import sdc.vtune_integration as vt
import ctypes
import itt

handle = vt.ctypes_string_handle_create(b"Head\0")

functype_task_begin = ctypes.CFUNCTYPE(None, ctypes.c_void_p, ctypes.c_void_p)
ctypes_task_begin = functype_task_begin(itt.__itt_task_begin)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it should be done in vtune.py, not here. And here just import these functions


functype_task_end = ctypes.CFUNCTYPE(None, ctypes.c_void_p)
ctypes_task_end = functype_task_end(itt.__itt_task_end)


@njit
def dataframe_head(df):
ctypes_task_begin(vt.domain, handle)
new_df = df.head(n=5)
ctypes_task_end(vt.domain)
return new_df


df = pd.DataFrame({'A': [1,2,4,6,4,2], 'B': [3.,2.,77.,2.,5.,6.5]})

print(dataframe_head(df))
40 changes: 40 additions & 0 deletions vtune_integration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import ctypes
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's rename file somehow. Probably, simlpy vtune.py

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

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)

ll.add_symbol('__itt_task_begin_new', itt.__itt_task_begin)
ll.add_symbol('__itt_task_end_new', itt.__itt_task_end)

def vtune_profiling_boxing(name_handle):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this?

def task(func):
handle = ctypes_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