• Stars
    star
    111
  • Rank 314,436 (Top 7 %)
  • Language
    C++
  • License
    MIT License
  • Created almost 7 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

NanoSTL, a small subset of C++ STL and libm

NanoSTL, a portable and small subset of C++ STL.

Build Status

NanoSTL is good for using STL-like feature in your C++ application and C++-like JIT compiler.

NanoSTL is portable, it should run well on many environments including Windows, Linux, macOS, x86, ARM, SPARC, etc.

NanoSTL should work well on C++11 compiler or later. (C++03 or earlier is not supported)

Status

Eearly testing stage. Not ready for the production use.

Features

  • Experimental CUDA support. You can use NanoSTL on device functions.
    • See sandbox/cuda/

Example

NanoSTL is header-only library. No need to compile/link with .cc Some function(e.g. std::to_string) requires the implementation, thus must define NANOSTL_IMPLEMENTATION in single *.cc file.

#define NANOSTL_IMPLEMENTATION
#include <nanosring.h>

...

Supported features

  • vector
  • string
    • to_string(float)(using ryu)
    • to_string(double)(using ryu)
    • stof(string to float. using ryu_parse)
    • stod(string to double. using ryu_parse)
  • algorithm
  • limits
    • numeric_limits<T>::min
    • numeric_limits<T>::max
    • numeric_limits<T>::epsilon()
    • numeric_limits<T>::digits10
    • numeric_limits<float>::denorm_min()
    • numeric_limits<double>::denorm_min()
    • numeric_limits<float>::inifinity()
    • numeric_limits<float>::quiet_NaN()
    • numeric_limits<float>::signaling_NaN()
    • numeric_limits<double>::inifinity()
    • numeric_limits<double>::quiet_NaN()
    • numeric_limits<double>::signaling_NaN()
  • map

Be careful! Not all C++ STL functions are supported for each module.

Limited support

  • math : Approximate math functions. Please keep in mind this is basically not be IEEE-754 compliant and does not consier a processor's rounding mode.
  • valarray
  • cstring
    • memcpy
    • memmove
    • strcpy
    • strncpy
    • strcat
    • strncat
    • memcmp
    • strcmp
    • strcoll
    • strncmp
    • strxfrm
    • memchr
    • strchr
    • strcspn
    • strpbrk
    • strrchr
    • strspn
    • strstr
    • strtok
    • memset
    • strerror
    • strlen
    • NULL
    • size_t
  • iostream
  • hash: Basic type
  • hash: string
  • thread
  • atomic
  • mutex
  • ratio
  • chrono

math functions

  • isnan
  • isinf
  • isfinite
  • isnormal
  • fabs(float)
  • copysign(float)
  • sqrt(float) Approximated.
  • exp(float)
  • pow(float)
  • log(float)
  • log10(float)
  • sin(float)
  • cos(float)
  • tanh(float)
  • cbrt(float)
  • erf(float)
  • erfc(float)
  • ierf(float)

Other list of implementation status

  • cassert
    • assert
      • CUDA
      • Other platform
  • To be filled...

Supported architectures

  • 64bit arctecture only.
  • Big endian and little endian
    • Some math functions may not run on big endian machine.
  • CUDA device.

Supported compilers

Even though NanoSTL should be compilable with older and various C++ compilers, at least following compilers shold work well.

  • gcc 4.4.7+
    • NanoSTL itself can be compilable with gcc 4.2.4(fails to compile Catch unit test code)
  • clang 3.4+

Supported threading library

For thread and parallel STL feature, threading library is required.

  • pthread(non-Windows)
  • Win32 thread(Windows)

Types

NanoSTL assumes following type definitions.

  • char : 8bit(NOTE: unsigned is default for some ARM compiler. Use signed char if you want signed 8bit type)
  • short : 16bit
  • int : 32bit
  • long long : 64bit
  • float : 32bit IEEE754 floating point.
  • double : 64bit IEEE754 floating point.

long and int long is not recommended to use. Please use cstdint typedefs.

Compiler macros

  • NANOSTL_BIG_ENDIAN Set endianness to big endian. Considering to support various compilers, user must explicitly specify endianness to the compiler. Default is little endian.
  • NANOSTL_NO_IO Disable all I/O operation(e.g. iostream). Useful for embedded devices.
  • NANOSTL_USE_EXCEPTION Enable exception feature(may not be available for all STL functions)
  • NANOSTL_NO_THREAD Disable thread, atomic and mutex feature.
  • NANOSTL_PSTL Enable parallel STL feature. Requires C++17 compiler. This also undefine NANOSTL_NO_THREAD

header-only mode

You can define NANOSTL_IMPLEMENTATION to define the implementation of some STL functions. This is useful if you want to use NanoSTL as a header-only library (No need to compile/add .cc)

#define NANOSTL_IMPLEMENTATION
#include <nanostl.h>

Differences compared to (full featured) C++ STL

  • No thread safety Currently NanoSTL is not thread safe
    • Application must care about the thread safety
    • For example, need to use mutex or lock for nanostl::vector::push_back() operation if you are accesing nanostl::vector object from multiple threads.
  • RTTI and exception is basically not supported.
    • some API may support it through NANOSTL_USE_EXCEPTION
  • Returns NULL when memory allocation failed(no bad_alloc)
  • stof, stod
    • Return (signaling) NaN for invalid input

TODO

  • iostream(stdout)
  • iostream: Custom output/input sink.
  • fstream(file IO)
  • Math complex type
  • CUDA support(experimental)
  • isnan/isinf/isfinite support
  • Unit tests
    • Unit tests on CUDA platform
    • Write mote unit tests for CPU platform
  • Multithread support
  • Backport of some C++11 features(e.g. unordered_map)
  • Replace oiio math functions so that we can have clean MIT licensed code.
  • FLOAT16 and BFLOAT16 support.
  • C++17 parallel STL

Developer note

Generate single header file.

$ python scripts/generateSingleHeader.py

Each .h must have wrapped with like this:

#ifndef NANOSTL_*_H_`
#define NANOSTL_*_H_`

// comment after `#endif` is required!
#endif // NANOSTL_*_H_

to extract codes for single header generation. (no #pragma once)

Unit tests

Compiling unit test requires C++11 compiler since unit test uses some C++11 math functions for the reference.

$ cd tests
$ make
$ ./test

Debugging

Use NANOSTL_DEBUG define for debugging.

Licenss

Unless otherwise expressed, NanoSTL is licensed under MIT license. Some functions in nanomath is licenced under modified BSD license.

Third party licenses

More Repositories

1

nanort

NanoRT, single header only modern ray tracing kernel.
C++
1,019
star
2

nanogi

A small, reference GI renderer
C++
153
star
3

nnview

A neural network visualizer
C
90
star
4

colorcorrectionmatrix

Compute color correction matrix in python and C++
C++
86
star
5

prnet-infer

C++11 port of YadiraF's PRNet(inference only)
C
68
star
6

mallie

Mallie, bootstrap for your own ray tracer.
C
57
star
7

embree-aarch64

AARCH64 port of Embree ray tracing library
C++
47
star
8

softcompute

SoftCompute, CPU JIT execution of SPIR-V compute shader
C++
42
star
9

lighttransportequation-orb

Light Transport Equation Orb
40
star
10

pbrlab

`pbrlab` is well-verified(through brute force human verification and debugging) path tracing + PBR shading/rendering implementation.
C++
35
star
11

japanese-llama-experiment

Japanese LLaMa experiment
C
33
star
12

nanocsv

Multithreaded header only C++11 CSV parser
C
29
star
13

gltf-insight

C++11 based glTF 2.0 data insight tool
C
25
star
14

nanosnap

Nanoscale Signal, Noise and Audio Processing library in C++11
C
22
star
15

c-libtorch

Experimental C binding for libtorch
C++
15
star
16

lighttransportequation-glass

Light Transport Equation Glass
15
star
17

nanolog

Nanoscale logging library in C++11
C++
13
star
18

simple_vulkan

simple vulkan framework
C++
13
star
19

oclc

Simple OpenCL offline compiler
C++
13
star
20

VisemeNet-infer

CPU inference version of VisemeNet-tensorflow
Jupyter Notebook
11
star
21

vermeer-box

Vermeer box scene
11
star
22

tf-frozen2cc

TensorFlow frozen forward model to plain C++ converter
Python
10
star
23

francine

Highly scalable renderer backend
C++
10
star
24

procedural-eyeball-shader

Fully procedural GLSL eyeball shader
JavaScript
10
star
25

sss-model

Test model for subsurface scattering
9
star
26

mlspv

Machine Learning with SPIR-V(Experimental)
C
8
star
27

cpp-guidelines

Light Transport Entertainment's C/C++ coding guidelines
8
star
28

nanolibc

Nanoscale libc
C
7
star
29

kuroga

Kuroga, simple & single python file meta-build system for ninja
Python
7
star
30

obj2eson

Wavefront obj to ESON converter.
C++
7
star
31

tubular-cpp

Curves to tube mesh conversion in cpp
C++
6
star
32

rainbowmist

RainbowMist 🌈🌫️ is a simple C++ macro and template based unified compute kernel utility.
C++
5
star
33

ZoCap

C++
4
star
34

objlab

Simple wavefront .obj viewer
C
4
star
35

tinyvtkxml

Tiny VTK XML parser in C++.
C++
4
star
36

brdfview

C++
3
star
37

francine-ui

francine viewer
JavaScript
3
star
38

usd-fuzz

USD(USDA, USDC, USDZ) poc and regression files for fuzzing test
3
star
39

chainer2tflite

Chainer model to TensorFlow-Lite converter
3
star
40

rcopy-win

Windows port of rcopy from librdmacm
C
3
star
41

tinyplotlib

Tiny plotting library in C++11
3
star
42

jagger-python

Python binding for Jagger(C++ implementation of Pattern-based Japanese Morphological Analyzer)
C++
3
star
43

japanese-normalizer-cpp

Header-only Japanese Normalizer in C++11
C++
2
star
44

is

Interstellar: file sync utility for multiple remote servers with terabytes of files
Go
2
star
45

USD-android

Building USD(Universal Scene Description) on Android
C++
2
star
46

nanodenoise-example

GUI and other example codes for nanodenoise
2
star
47

nanozlib

Nanoscale secure zlib library
C
1
star
48

imagediffview

Image diff view in HTML.
JavaScript
1
star
49

simpleVK

C++
1
star
50

english-text-to-sequence

English text to sequence conversion in Python
Python
1
star