Skip to content
This repository was archived by the owner on Feb 2, 2024. It is now read-only.
Merged
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
Review issues & conda recipe
  • Loading branch information
AlexanderKalistratov committed May 29, 2020
commit 7317e55241ec62015ef5db3dc260a68b5c5ac34f
5 changes: 5 additions & 0 deletions conda-recipe/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ requirements:
- pandas {{ PANDAS_VERSION }}
- pyarrow {{ PYARROW_VERSION }}
- wheel
- tbb
- tbb-devel

run:
- python
Expand All @@ -37,6 +39,7 @@ requirements:
- pyarrow {{ PYARROW_VERSION }}
- numba {{ NUMBA_VERSION }}
- setuptools
- tbb

test:
imports:
Expand All @@ -58,6 +61,8 @@ outputs:
- numpy
- pandas {{ PANDAS_VERSION }}
- pyarrow {{ PYARROW_VERSION }}
- tbb
- tbb-devel

about:
home: https://github.com/IntelPython/sdc
Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ numpy>=1.16
pandas==0.25.3
pyarrow==0.17.0
numba==0.49.1
tbb
tbb-devel
36 changes: 23 additions & 13 deletions sdc/functions/sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@

from sdc import concurrent_sort


def bind(sym, sig):
# Returns ctypes binding to symbol sym with signature sig
addr = getattr(concurrent_sort, sym)
return ct.cast(addr, sig)


parallel_sort_arithm_sig = ct.CFUNCTYPE(None, ct.c_void_p, ct.c_uint64)

parallel_sort_sig = ct.CFUNCTYPE(None, ct.c_void_p, ct.c_uint64,
ct.c_uint64, ct.c_void_p,)
ct.c_uint64, ct.c_void_p,)

parallel_sort_sym = bind('parallel_sort',
parallel_sort_sig)
Expand All @@ -30,7 +32,7 @@ def less(left, right):
pass


@overload(less, jit_options={'locals':{'result':types.int8}})
@overload(less, jit_options={'locals': {'result': types.int8}})
def less_overload(left, right):
def less_impl(left, right):
result = left < right
Expand Down Expand Up @@ -74,12 +76,15 @@ def deref(_ityctx, _x):
# to deref the void * passed. TODO: nrt awareness
catchthing = thing
sig = catchthing(_x)

def codegen(cgctx, builder, sig, args):
toty = cgctx.get_value_type(sig.return_type).as_pointer()
addressable = builder.bitcast(args[0], toty)
zero_intpt = cgctx.get_constant(types.intp, 0)
vref = builder.gep(addressable, [zero_intpt], inbounds=True)

return builder.load(vref)

return sig, codegen

@njit
Expand All @@ -103,11 +108,14 @@ def wrapper(a, b):
@intrinsic
def asvoidp(tyctx, thing):
sig = types.voidptr(thing)

def codegen(cgctx, builder, sig, args):
dm_thing = cgctx.data_model_manager[sig.args[0]]
data_thing = dm_thing.as_data(builder, args[0])
ptr_thing = cgutils.alloca_once_value(builder, data_thing)

return builder.bitcast(ptr_thing, cgutils.voidptr_t)

return sig, codegen


Expand All @@ -116,22 +124,22 @@ def sizeof(context, t):
sig = types.uint64(t)

def codegen(cgctx, builder, sig, args):
size = cgctx.get_abi_sizeof(t)
size = cgctx.get_abi_sizeof(t)
return cgctx.get_constant(types.uint64, size)

return sig, codegen


types_to_postfix = {types.int8 : 'i8',
types.uint8 : 'u8',
types.int16 : 'i16',
types.uint16 : 'u16',
types.int32 : 'i32',
types.uint32 : 'u32',
types.int64 : 'i64',
types.uint64 : 'u64',
types.float32 : 'f32',
types.float64 : 'f64' }
types_to_postfix = {types.int8: 'i8',
types.uint8: 'u8',
types.int16: 'i16',
types.uint16: 'u16',
types.int32: 'i32',
types.uint32: 'u32',
types.int64: 'i64',
types.uint64: 'u64',
types.float32: 'f32',
types.float64: 'f64'}


def load_symbols(name, sig, types):
Expand All @@ -148,6 +156,7 @@ def load_symbols(name, sig, types):
sort_map = load_symbols('parallel_sort', parallel_sort_arithm_sig, types_to_postfix)
stable_sort_map = load_symbols('parallel_stable_sort', parallel_sort_arithm_sig, types_to_postfix)


@intrinsic
def list_itemsize(tyctx, list_ty):
sig = types.uint64(list_ty)
Expand Down Expand Up @@ -209,6 +218,7 @@ def parallel_sort_impl(arr):

return parallel_sort_impl


def parallel_stable_sort(arr):
pass

Expand Down
2 changes: 1 addition & 1 deletion sdc/native/module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,4 @@ PyMODINIT_FUNC PyInit_concurrent_sort()
REGISTER(parallel_stable_sort_f64)
#undef REGISTER
return m;
}
}
26 changes: 13 additions & 13 deletions sdc/native/sort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ declare_int_sort(64)
declare_sort(f32, float)
declare_sort(f64, double)

#undef declare_int_sort
#undef declare_sort

void parallel_sort(void* begin, uint64_t len, uint64_t size, void* compare)
{
auto compare_f = reinterpret_cast<compare_func>(compare);
Expand Down Expand Up @@ -64,15 +61,15 @@ void parallel_sort(void* begin, uint64_t len, uint64_t size, void* compare)
break;
default:
// fallback to c qsort?
if (size < 4) run_sort(_void_range<4>)
else if (size < 8) run_sort(_void_range<8>)
else if (size < 16) run_sort(_void_range<16>)
else if (size < 32) run_sort(_void_range<32>)
else if (size < 64) run_sort(_void_range<64>)
else if (size < 128) run_sort(_void_range<128>)
else if (size < 256) run_sort(_void_range<256>)
else if (size < 512) run_sort(_void_range<512>)
else if (size < 1024) run_sort(_void_range<1024>)
if (size <= 4) run_sort(_void_range<4>)
else if (size <= 8) run_sort(_void_range<8>)
else if (size <= 16) run_sort(_void_range<16>)
else if (size <= 32) run_sort(_void_range<32>)
else if (size <= 64) run_sort(_void_range<64>)
else if (size <= 128) run_sort(_void_range<128>)
else if (size <= 256) run_sort(_void_range<256>)
else if (size <= 512) run_sort(_void_range<512>)
else if (size <= 1024) run_sort(_void_range<1024>)
else
{
std::cout << "Unsupported item size " << size << std::endl;
Expand All @@ -84,4 +81,7 @@ void parallel_sort(void* begin, uint64_t len, uint64_t size, void* compare)
#undef run_sort
}

}
}

#undef declare_int_sort
#undef declare_sort
26 changes: 13 additions & 13 deletions sdc/native/stable_sort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,15 +227,15 @@ void stable_sort_inner_sort<void>(void* data, int begin, int end, int item_size,
break;
default:
// fallback to own implementation?
if (item_size < 4) run_sort(_void_range<4>)
else if (item_size < 8) run_sort(_void_range<8>)
else if (item_size < 16) run_sort(_void_range<16>)
else if (item_size < 32) run_sort(_void_range<32>)
else if (item_size < 64) run_sort(_void_range<64>)
else if (item_size < 128) run_sort(_void_range<128>)
else if (item_size < 256) run_sort(_void_range<256>)
else if (item_size < 512) run_sort(_void_range<512>)
else if (item_size < 1024) run_sort(_void_range<1024>)
if (item_size <= 4) run_sort(_void_range<4>)
else if (item_size <= 8) run_sort(_void_range<8>)
else if (item_size <= 16) run_sort(_void_range<16>)
else if (item_size <= 32) run_sort(_void_range<32>)
else if (item_size <= 64) run_sort(_void_range<64>)
else if (item_size <= 128) run_sort(_void_range<128>)
else if (item_size <= 256) run_sort(_void_range<256>)
else if (item_size <= 512) run_sort(_void_range<512>)
else if (item_size <= 1024) run_sort(_void_range<1024>)
else
{
std::cout << "Unsupported item size " << item_size << std::endl;
Expand Down Expand Up @@ -322,12 +322,12 @@ declare_int_sort(64)
declare_sort(f32, float)
declare_sort(f64, double)

#undef declare_int_sort
#undef declare_sort

void parallel_stable_sort(void* begin, uint64_t len, uint64_t size, void* compare)
{
parallel_stable_sort_<void>(begin, len, size, compare);
}

}
}

#undef declare_int_sort
#undef declare_sort
6 changes: 4 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ def check_file_at_path(path2file):
if not tbb_root:
tbb_root = check_file_at_path(['include', 'tbb', 'tbb.h'])

print("tbb_root", tbb_root)
if tbb_root is None:
raise RuntimeError("tbb headers were not found. Try to install tbb-devel package")

ind = [PREFIX_DIR + '/include', ]
lid = [PREFIX_DIR + '/lib', ]
Expand Down Expand Up @@ -375,7 +376,8 @@ def run(self):
'numpy>=1.16',
'pandas==0.25.3',
'pyarrow==0.17.0',
'numba>=0.49.1,<0.50.0'
'numba>=0.49.1,<0.50.0',
'tbb'
],
cmdclass=sdc_build_commands,
ext_modules=_ext_mods,
Expand Down