mirror of https://github.com/microsoft/vcpkg.git
[vcpkg-ci-highway] New ci port (#51363)
This commit is contained in:
parent
fd7b7f4e89
commit
3909e67a63
|
|
@ -0,0 +1,4 @@
|
|||
set(VCPKG_POLICY_EMPTY_PACKAGE enabled)
|
||||
|
||||
vcpkg_cmake_configure(SOURCE_PATH "${CURRENT_PORT_DIR}/project")
|
||||
vcpkg_cmake_build()
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
cmake_minimum_required(VERSION 3.15)
|
||||
project(vcpkg_ci_highway)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
|
||||
find_package(hwy CONFIG REQUIRED)
|
||||
|
||||
# Dynamic Dispatch
|
||||
add_executable(vcpkg_ci_highway main.cpp scale.cpp scale.hpp)
|
||||
target_include_directories(vcpkg_ci_highway PRIVATE ${CMAKE_CURRENT_LIST_DIR})
|
||||
target_link_libraries(vcpkg_ci_highway PRIVATE hwy::hwy)
|
||||
|
||||
# Static Dispatch
|
||||
add_executable(vcpkg_ci_highway_static main.cpp scale.cpp scale.hpp)
|
||||
target_include_directories(vcpkg_ci_highway_static PRIVATE ${CMAKE_CURRENT_LIST_DIR})
|
||||
target_link_libraries(vcpkg_ci_highway_static PRIVATE hwy::hwy)
|
||||
target_compile_definitions(vcpkg_ci_highway_static PRIVATE HWY_COMPILE_ONLY_STATIC)
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
#include <random>
|
||||
#include <vector>
|
||||
#include "scale.hpp"
|
||||
|
||||
std::vector<float> generate_random_floats(size_t n) {
|
||||
std::vector<float> data(n);
|
||||
std::random_device rd;
|
||||
std::mt19937 gen(rd());
|
||||
std::uniform_real_distribution<float> dist(0.0f, 1.0f);
|
||||
for (auto &x : data) {
|
||||
x = dist(gen);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
int main() {
|
||||
std::vector<float> src = generate_random_floats(1000);
|
||||
std::vector<float> dst(src.size());
|
||||
scale(dst.data(), src.data(), src.size(), 0.75f);
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
#undef HWY_TARGET_INCLUDE
|
||||
#define HWY_TARGET_INCLUDE "scale.cpp"
|
||||
#include "hwy/foreach_target.h"
|
||||
#include "hwy/highway.h"
|
||||
|
||||
HWY_BEFORE_NAMESPACE();
|
||||
namespace HWY_NAMESPACE {
|
||||
|
||||
namespace hn = hwy::HWY_NAMESPACE;
|
||||
|
||||
void scale(float *HWY_RESTRICT dst, const float *HWY_RESTRICT src, size_t size, float factor) {
|
||||
size_t i = 0;
|
||||
|
||||
constexpr hn::ScalableTag<float> d;
|
||||
const auto vf = hn::Set(d, factor);
|
||||
const size_t N = hn::Lanes(d);
|
||||
|
||||
for (; i + 4 * N <= size; i += 4 * N) {
|
||||
auto x0 = hn::Load(d, src + i + 0 * N);
|
||||
auto x1 = hn::Load(d, src + i + 1 * N);
|
||||
auto x2 = hn::Load(d, src + i + 2 * N);
|
||||
auto x3 = hn::Load(d, src + i + 3 * N);
|
||||
hn::Store(hn::Mul(x0, vf), d, dst + i + 0 * N);
|
||||
hn::Store(hn::Mul(x1, vf), d, dst + i + 1 * N);
|
||||
hn::Store(hn::Mul(x2, vf), d, dst + i + 2 * N);
|
||||
hn::Store(hn::Mul(x3, vf), d, dst + i + 3 * N);
|
||||
}
|
||||
|
||||
for (; i + N <= size; i += N) {
|
||||
auto x = hn::Load(d, src + i);
|
||||
hn::Store(hn::Mul(x, vf), d, dst + i);
|
||||
}
|
||||
|
||||
for (; i < size; ++i) {
|
||||
dst[i] = src[i] * factor;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace HWY_NAMESPACE
|
||||
HWY_AFTER_NAMESPACE();
|
||||
|
||||
#if HWY_ONCE
|
||||
|
||||
#include "scale.hpp"
|
||||
|
||||
HWY_EXPORT(scale);
|
||||
void scale(float *HWY_RESTRICT dst, const float *HWY_RESTRICT src, size_t size, float factor) {
|
||||
HWY_DYNAMIC_DISPATCH(scale)(dst, src, size, factor);
|
||||
}
|
||||
|
||||
#endif // HWY_ONCE
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
#if !defined(HWY_RESTRICT)
|
||||
#if defined(_MSC_VER)
|
||||
#define HWY_RESTRICT __restrict
|
||||
#else
|
||||
#define HWY_RESTRICT __restrict__
|
||||
#endif
|
||||
#endif
|
||||
|
||||
void scale(float *HWY_RESTRICT dst, const float *HWY_RESTRICT src, size_t size, float factor);
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
"name": "vcpkg-ci-highway",
|
||||
"version-string": "ci",
|
||||
"description": "Validates highway",
|
||||
"dependencies": [
|
||||
"highway",
|
||||
{
|
||||
"name": "vcpkg-cmake",
|
||||
"host": true
|
||||
}
|
||||
]
|
||||
}
|
||||
Loading…
Reference in New Issue