Skip to content
This repository was archived by the owner on Feb 2, 2024. It is now read-only.
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
Prev Previous commit
Next Next commit
style
  • Loading branch information
Ivan Butygin committed Feb 21, 2020
commit 213eccc62c382391508374a1b1730d94493950d4
59 changes: 51 additions & 8 deletions sdc/concurrent_hash.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,29 @@
# *****************************************************************************
# Copyright (c) 2020, Intel Corporation All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# *****************************************************************************

import numba
import sdc

Expand All @@ -10,15 +36,15 @@
from . import hconcurrent_hash
ll.add_symbol('create_int_hashmap', hconcurrent_hash.create_int_hashmap)
ll.add_symbol('delete_int_hashmap', hconcurrent_hash.delete_int_hashmap)
ll.add_symbol('addelem_int_hashmap',hconcurrent_hash.addelem_int_hashmap)
ll.add_symbol('addelem_int_hashmap', hconcurrent_hash.addelem_int_hashmap)

ll.add_symbol('createiter_int_hashmap',hconcurrent_hash.createiter_int_hashmap)
ll.add_symbol('enditer_int_hashmap',hconcurrent_hash.enditer_int_hashmap)
ll.add_symbol('nextiter_int_hashmap',hconcurrent_hash.nextiter_int_hashmap)
ll.add_symbol('iterkey_int_hashmap',hconcurrent_hash.iterkey_int_hashmap)
ll.add_symbol('itersize_int_hashmap',hconcurrent_hash.itersize_int_hashmap)
ll.add_symbol('iterelem_int_hashmap',hconcurrent_hash.iterelem_int_hashmap)
ll.add_symbol('deleteiter_int_hashmap',hconcurrent_hash.deleteiter_int_hashmap)
ll.add_symbol('createiter_int_hashmap', hconcurrent_hash.createiter_int_hashmap)
ll.add_symbol('enditer_int_hashmap', hconcurrent_hash.enditer_int_hashmap)
ll.add_symbol('nextiter_int_hashmap', hconcurrent_hash.nextiter_int_hashmap)
ll.add_symbol('iterkey_int_hashmap', hconcurrent_hash.iterkey_int_hashmap)
ll.add_symbol('itersize_int_hashmap', hconcurrent_hash.itersize_int_hashmap)
ll.add_symbol('iterelem_int_hashmap', hconcurrent_hash.iterelem_int_hashmap)
ll.add_symbol('deleteiter_int_hashmap', hconcurrent_hash.deleteiter_int_hashmap)

_create_int_hashmap = types.ExternalFunction("create_int_hashmap",
types.voidptr())
Expand Down Expand Up @@ -46,42 +72,53 @@
def create_int_hashmap():
pass


def delete_int_hashmap():
pass


def addelem_int_hashmap():
pass


def createiter_int_hashmap():
pass


def enditer_int_hashmap():
pass


def nextiter_int_hashmap():
pass


def iterkey_int_hashmap():
pass


def itersize_int_hashmap():
pass


def iterelem_int_hashmap():
pass


def deleteiter_int_hashmap():
pass


@overload(create_int_hashmap)
def create_int_hashmap_overload():
return lambda: _create_int_hashmap()


@overload(delete_int_hashmap)
def delete_int_hashmap_overload(h):
return lambda h: _delete_int_hashmap(h)


@overload(addelem_int_hashmap)
def addelem_int_hashmap_overload(h, key, val):
return lambda h, key, val: _addelem_int_hashmap(h, key, val)
Expand All @@ -91,26 +128,32 @@ def addelem_int_hashmap_overload(h, key, val):
def createiter_int_hashmap_overload(h):
return lambda h: _createiter_int_hashmap(h)


@overload(enditer_int_hashmap)
def enditer_int_hashmap_overload(h):
return lambda h: _enditer_int_hashmap(h)


@overload(nextiter_int_hashmap)
def nextiter_int_hashmap_overload(h):
return lambda h: _nextiter_int_hashmap(h)


@overload(iterkey_int_hashmap)
def iterkey_int_hashmap_overload(h):
return lambda h: _iterkey_int_hashmap(h)


@overload(itersize_int_hashmap)
def itersize_int_hashmap_overload(h):
return lambda h: _itersize_int_hashmap(h)


@overload(iterelem_int_hashmap)
def iterelem_int_hashmap_overload(h, i):
return lambda h, i: _iterelem_int_hashmap(h, i)


@overload(deleteiter_int_hashmap)
def deleteiter_int_hashmap_overload(h):
return lambda h: _deleteiter_int_hashmap(h)
11 changes: 6 additions & 5 deletions sdc/tests/test_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -1793,14 +1793,15 @@ def test_impl():

def test_tbb(self):
import sdc.concurrent_hash

def test_impl():
h = sdc.concurrent_hash.create_int_hashmap()

sdc.concurrent_hash.addelem_int_hashmap(h,1,2)
sdc.concurrent_hash.addelem_int_hashmap(h,1,3)
sdc.concurrent_hash.addelem_int_hashmap(h,1,4)
sdc.concurrent_hash.addelem_int_hashmap(h,1,5)
sdc.concurrent_hash.addelem_int_hashmap(h,2,6)
sdc.concurrent_hash.addelem_int_hashmap(h, 1, 2)
sdc.concurrent_hash.addelem_int_hashmap(h, 1, 3)
sdc.concurrent_hash.addelem_int_hashmap(h, 1, 4)
sdc.concurrent_hash.addelem_int_hashmap(h, 1, 5)
sdc.concurrent_hash.addelem_int_hashmap(h, 2, 6)

it = sdc.concurrent_hash.createiter_int_hashmap(h)
while 0 == sdc.concurrent_hash.enditer_int_hashmap(it):
Expand Down
56 changes: 29 additions & 27 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,35 +198,37 @@ def readme():
if _has_opencv:
_ext_mods.append(ext_cv_wrapper)


# Copypaste from numba
def check_file_at_path(path2file):
"""
Takes a list as a path, a single glob (*) is permitted as an entry which
indicates that expansion at this location is required (i.e. version
might not be known).
"""
found = None
path2check = [os.path.split(os.path.split(sys.executable)[0])[0]]
path2check += [os.getenv(n, '') for n in ['CONDA_PREFIX', 'PREFIX']]
if sys.platform.startswith('win'):
path2check += [os.path.join(p, 'Library') for p in path2check]
for p in path2check:
if p:
if '*' in path2file:
globloc = path2file.index('*')
searchroot = os.path.join(*path2file[:globloc])
try:
potential_locs = os.listdir(os.path.join(p, searchroot))
except BaseException:
continue
searchfor = path2file[globloc + 1:]
for x in potential_locs:
potpath = os.path.join(p, searchroot, x, *searchfor)
if os.path.isfile(potpath):
found = p # the latest is used
elif os.path.isfile(os.path.join(p, *path2file)):
found = p # the latest is used
return found
"""
Takes a list as a path, a single glob (*) is permitted as an entry which
indicates that expansion at this location is required (i.e. version
might not be known).
"""
found = None
path2check = [os.path.split(os.path.split(sys.executable)[0])[0]]
path2check += [os.getenv(n, '') for n in ['CONDA_PREFIX', 'PREFIX']]
if sys.platform.startswith('win'):
path2check += [os.path.join(p, 'Library') for p in path2check]
for p in path2check:
if p:
if '*' in path2file:
globloc = path2file.index('*')
searchroot = os.path.join(*path2file[:globloc])
try:
potential_locs = os.listdir(os.path.join(p, searchroot))
except BaseException:
continue
searchfor = path2file[globloc + 1:]
for x in potential_locs:
potpath = os.path.join(p, searchroot, x, *searchfor)
if os.path.isfile(potpath):
found = p # the latest is used
elif os.path.isfile(os.path.join(p, *path2file)):
found = p # the latest is used
return found


# Search for Intel TBB, first check env var TBBROOT then conda locations
tbb_root = os.getenv('TBBROOT')
Expand Down