10000 Hwy dynamic dispatch by Micky774 · Pull Request #12 · Micky774/scikit-learn · GitHub
[go: up one dir, main page]

Skip to content

Hwy dynamic dispatch #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 19 commits into
base: main
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
Prev Previous commit
Next Next commit
Dynamic dispat 8000 ch attempt
  • Loading branch information
Micky774 committed Aug 30, 2023
commit dd77b65b7589f95b75d29e7cbc418207814da648
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ def check_package_status(package, min_version):
"language": "c++",
"extra_compile_args": ["-std=c++11"],
"define_macros": [("DIST_METRICS", None)],
"include_dirs": [".", join("..", "..", HWY_INCLUDE_PATH)],
"include_dirs": [join("..", "..", HWY_INCLUDE_PATH), "."],
},
],
"metrics.cluster": [
Expand Down Expand Up @@ -512,7 +512,7 @@ def configure_extension_modules():
{
"language": "c++",
"sources": [join(SIMD_DIRECTORY, "simd.cpp")],
"cflags": ["-std=c++14", "-mavx"],
"cflags": ["-std=c++14", "-march=native"],
"extra_link_args": ["-std=c++14"],
"include_dirs": [SIMD_DIRECTORY, HWY_INCLUDE_PATH],
},
Expand Down
3 changes: 2 additions & 1 deletion sklearn/metrics/_dist_metrics.pxd.tp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ cdef class DistanceMetric:
pass

cdef extern from "_simd/_dist_optim.cpp":
cdef Type simd_manhattan_dist[Type](Type * x, Type * y, intp_t size) nogil
cdef Type simd_manhattan_dist_scalar[Type](Type * x, Type * y, intp_t size) nogil
int WITH_SIMD
cdef extern from "_simd/_dist_optim.cpp" namespace "manhattan":
cdef Type simd_manhattan_dist[Type](Type * x, Type * y, intp_t size) nogil

{{for name_suffix, INPUT_DTYPE_t, INPUT_DTYPE in implementation_specific_values}}

Expand Down
8000 4 changes: 0 additions & 4 deletions sklearn/metrics/_simd/_dist_optim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ this file due to cimporting _dist_metrics
/* If built with SIMD support, include the compiled library code */
#if WITH_SIMD == 1
#include "simd.hpp"
#include "hwy/highway.h"

template<typename T>
auto simd_manhattan_dist = manhattan::_simd_manhattan_dist;
#else
#include <cstddef>

Expand Down
22 changes: 17 additions & 5 deletions sklearn/metrics/_simd/simd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
#define HWY_TARGET_INCLUDE "simd.cpp"
#include "hwy/foreach_target.h"
#include "hwy/highway.h"
HWY_BEFORE_NAMESPACE(); // at file scope

HWY_BEFORE_NAMESPACE();
namespace manhattan {

namespace HWY_NAMESPACE {
namespace hn = hwy::HWY_NAMESPACE;


template <typename Type>
HWY_ATTR Type manhattan_dist(
inline Type manhattan_dist(
const Type* x,
const Type* y,
const size_t size
Expand Down Expand Up @@ -49,8 +49,20 @@ namespace manhattan {
}
return scalar_sum;
}
auto manhattan_dist_float = manhattan_dist<float>;
auto manhattan_dist_double = manhattan_dist<double>;
inline float manhattan_dist_float(
const float* x,
const float* y,
const size_t size
) {
return manhattan_dist<float>(x, y, size);
}
inline double manhattan_dist_double(
const double* x,
const double* y,
const size_t size
) {
return manhattan_dist<double>(x, y, size);
}
}
}
HWY_AFTER_NAMESPACE();
Expand All @@ -63,7 +75,7 @@ namespace manhattan {
HWY_EXPORT(manhattan_dist_double);

template <typename Type>
HWY_DLLEXPORT Type _simd_manhattan_dist(
HWY_DLLEXPORT Type simd_manhattan_dist(
const Type* x,
const Type* y,
const size_t size
Expand Down
7 changes: 4 additions & 3 deletions sklearn/metrics/_simd/simd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@

namespace manhattan{

HWY_DLLEXPORT float _simd_manhattan_dist(
const float* x,
const float* y,
template <typename Type>
HWY_DLLEXPORT Type simd_manhattan_dist(
const Type* x,
const Type* y,
const size_t size
);
}
Expand Down
0