Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions deps/checksums/highway_1_2_0_tar_gz/sha256
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
7e0be78b8318e8bdbf6fa545d2ecb4c90f947df03f7aadc42c1967f019e63343
58 changes: 58 additions & 0 deletions deps/test/highway/test_install.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2026 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <hwy/highway.h>

#include <cstdio>

HWY_BEFORE_NAMESPACE();
namespace HWY_NAMESPACE {
namespace hn = hwy::HWY_NAMESPACE;

double SumLanes(const double* HWY_RESTRICT values, size_t num) {
const hn::ScalableTag<double> d;
hn::Vec<decltype(d)> sum = hn::Set(d, 0.0);
size_t i = 0;
for (; i + hn::Lanes(d) <= num; i += hn::Lanes(d)) {
sum = hn::Add(sum, hn::LoadU(d, values + i));
}
// Reduce the vector lanes to a single scalar.
alignas(64) double buf[64];
hn::Store(sum, d, buf);
double result = 0.0;
for (size_t j = 0; j < hn::Lanes(d); ++j) {
result += buf[j];
}
// Scalar tail for remaining elements.
for (; i < num; ++i) {
result += values[i];
}
return result;
}
} // namespace HWY_NAMESPACE
HWY_AFTER_NAMESPACE();

int main() {
double values[] = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0};
const double sum = HWY_STATIC_DISPATCH(SumLanes)(values, sizeof(values) / sizeof(values[0]));

std::printf("Highway installed successfully!\n");
std::printf("Detected target: %s\n", hwy::TargetName(HWY_TARGET));
std::printf("Sum of [1..8] = %0.1f\n", sum);
return 0;
}
3 changes: 3 additions & 0 deletions docs/contributing/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ The following external libraries can be automatically downloaded and compiled fr

- [Boost][boost]: portable C++ libraries
- [Cephes][cephes]: C/C++ special functions math library
- [Highway][highway]: Google's portable SIMD library
- [OpenBLAS][openblas]: optimized BLAS library
- [Electron][electron]: framework for cross-platform desktop applications
- [Emscripten][emscripten]: LLVM to JavaScript compiler
Expand Down Expand Up @@ -406,6 +407,8 @@ For contribution guidelines, see the [contributing guide][stdlib-contributing].

[cephes]: http://www.moshier.net/#Cephes

[highway]: https://github.com/google/highway

[openblas]: https://github.com/xianyi/OpenBLAS

[electron]: https://www.electronjs.org/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
#/
# @license Apache-2.0
#
# Copyright (c) 2026 The Stdlib Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#/

# VARIABLES #

ifndef VERBOSE
QUIET := @
else
QUIET :=
endif

# Determine the OS ([1][1], [2][2]).
#
# [1]: https://en.wikipedia.org/wiki/Uname#Examples
# [2]: http://stackoverflow.com/a/27776822/2225624
OS ?= $(shell uname)
ifneq (, $(findstring MINGW,$(OS)))
OS := WINNT
else
ifneq (, $(findstring MSYS,$(OS)))
OS := WINNT
else
ifneq (, $(findstring CYGWIN,$(OS)))
OS := WINNT
else
ifneq (, $(findstring Windows_NT,$(OS)))
OS := WINNT
endif
endif
endif
endif

# Define the program used for compiling C++ source files:
ifdef CXX_COMPILER
CXX := $(CXX_COMPILER)
else
CXX := g++
endif

# Define the command-line options when compiling C++ files:
CXXFLAGS ?= \
-std=c++17 \
-O3 \
-Wall \
-pedantic

# Determine whether to generate position independent code ([1][1], [2][2]).
#
# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options
# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option
ifeq ($(OS), WINNT)
fPIC ?=
else
fPIC ?= -fPIC
endif

# Define the package root:
pkg_dir := $(abspath $(dir $(lastword $(MAKEFILE_LIST)))/../../..)

# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`):
INCLUDE ?= \
-I$(pkg_dir)/include \
-I$(pkg_dir)/../shared/include \
-I$(pkg_dir)/../diagonal-types/include \
-I$(pkg_dir)/../layouts/include \
-I$(pkg_dir)/../matrix-orientations/include \
-I$(pkg_dir)/../matrix-triangles/include \
-I$(pkg_dir)/../operation-sides/include \
-I$(pkg_dir)/../transpose-operations/include \
-I$(pkg_dir)/../../strided/base/stride2offset/include \
-I$(HIGHWAY)

# List of source files:
SOURCE_FILES ?= \
$(pkg_dir)/src/daxpy_hwy.cpp \
$(HIGHWAY)/hwy/targets.cc

# List of libraries (e.g., `-lopenblas -lpthread`):
LIBRARIES ?=

# List of library paths (e.g., `-L /foo/bar -L /beep/boop`):
LIBPATH ?=

# List of C++ targets:
cxx_targets := benchmark.out


# RULES #

#/
# Compiles source files.
#
# @param {string} [CXX_COMPILER] - C++ compiler (e.g., `g++`)
# @param {string} [CXXFLAGS] - C++ compiler options
# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`)
# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`)
# @param {string} [SOURCE_FILES] - list of source files
# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`)
# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`)
#
# @example
# make
#
# @example
# make all
#/
all: $(cxx_targets)

.PHONY: all

#/
# Compiles C++ source files.
#
# @private
# @param {string} CXX - C++ compiler (e.g., `g++`)
# @param {string} CXXFLAGS - C++ compiler options
# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`)
# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`)
# @param {string} SOURCE_FILES - list of source files
# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`)
# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`)
#/
$(cxx_targets): %.out: %.cpp
$(QUIET) $(CXX) $(CXXFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES)

#/
# Runs compiled benchmarks.
#
# @example
# make run
#/
run: $(cxx_targets)
$(QUIET) ./$<

.PHONY: run

#/
# Removes generated files.
#
# @example
# make clean
#/
clean:
$(QUIET) -rm -f *.o *.out

.PHONY: clean
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2026 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <stdint.h>
#include <sys/time.h>

#include "stdlib/blas/base/daxpy_hwy.h"

#ifndef NAME
#define NAME "daxpy"
#endif

#define ITERATIONS 10000000
#define REPEATS 3
#define MIN 1
#define MAX 6

/**
* Prints the TAP version.
*/
static void print_version( void ) {
printf( "TAP version 13\n" );
}

/**
* Prints the TAP summary.
*
* @param total total number of tests
* @param passing total number of passing tests
*/
static void print_summary( int total, int passing ) {
printf( "#\n" );
printf( "1..%d\n", total ); // TAP plan
printf( "# total %d\n", total );
printf( "# pass %d\n", passing );
printf( "#\n" );
printf( "# ok\n" );
}

/**
* Prints benchmarks results.
*
* @param iterations number of iterations
* @param elapsed elapsed time in seconds
*/
static void print_results( int iterations, double elapsed ) {
double rate = (double)iterations / elapsed;
printf( " ---\n" );
printf( " iterations: %d\n", iterations );
printf( " elapsed: %0.9f\n", elapsed );
printf( " rate: %0.9f\n", rate );
printf( " ...\n" );
}

/**
* Returns a clock time.
*/
static double tic( void ) {
struct timeval now;
gettimeofday( &now, NULL );
return (double)now.tv_sec + (double)now.tv_usec/1.0e6;
}

/**
* Generates a random number on the interval [0,1).
*
* @return random number
*/
static double rand_double( void ) {
int r = rand();
return (double)r / ( (double)RAND_MAX + 1.0 );
}

/**
* Runs a benchmark.
*
* @param iterations number of iterations
* @param len array length
* @return elapsed time in seconds
*/
static double benchmark_hwy( int iterations, int len ) {
double elapsed;
double *x;
double *y;
double t;
int i;

x = (double *) malloc( len * sizeof( double ) );
y = (double *) malloc( len * sizeof( double ) );
for ( i = 0; i < len; i++ ) {
x[ i ] = ( rand_double()*200.0 ) - 100.0;
y[ i ] = ( rand_double()*200.0 ) - 100.0;
}
t = tic();
for ( i = 0; i < iterations; i++ ) {
daxpy_simd( len, 5.0, x, 1, 0, y, 1, 0 );
if ( y[ 0 ] != y[ 0 ] ) {
printf( "should not return NaN\n" );
break;
}
}
elapsed = tic() - t;
if ( y[ 0 ] != y[ 0 ] ) {
printf( "should not return NaN\n" );
}
free( x );
free( y );
return elapsed;
}

/**
* Main execution sequence.
*/
int main( void ) {
double elapsed;
int count;
int iter;
int len;
int i;
int j;

// Use the current time to seed the random number generator:
srand( time( NULL ) );

print_version();
count = 0;
for ( i = MIN; i <= MAX; i++ ) {
len = pow( 10, i );
iter = ITERATIONS / pow( 10, i-1 );
for ( j = 0; j < REPEATS; j++ ) {
count += 1;
printf( "# cpp::highway::%s:len=%d\n", NAME, len );
elapsed = benchmark_hwy( iter, len );
print_results( iter, elapsed );
printf( "ok %d benchmark finished\n", count );
}
}
print_summary( count, count );
}
Loading