Giter Site home page Giter Site logo

add-on's Introduction

Add-on packages for vector class library

These packages are extensions to the C++ vector class library for specific applications:

  • containers. Container class tempates for arrays with fixed and dynamic size and matrixes.
  • random. Generates random number vectors of integers or floating point values. Excellent randomness. Suitable for large simulations and multi-threaded applications.
  • decimal. Conversion between integer vectors and comma-separated lists in human-readable form (decimal ASCII). Useful for reading and writing comma-separated files.
  • vector3d. Three-dimensional vector arithmetics, operators, cross product and dot product.
  • complex. Defines complex number vectors. Operators + - * / etc., and functions. Complex exponential function and logarithm.
  • quaternion. Hyper-complex numbers
  • physical_processors. Detect the number of physical and logical processors on an x86 computer

add-on's People

Contributors

agnerf avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

add-on's Issues

License

Hi. Would it be possible to add the license file in this add-on repository? As it is, the only mention (by name only) of a license seems to be in the manuals. Thanks.

Small modification of the constructor in ranvec1.h

Hi,

I was forced to make a small addition to the default constructor of the Ranvec1 class. I couldn't use the provided init(int seed,...) ... functions to initialize with the desired seeds because I used it as a static thread_local object. So the seed initialization must happen in this case in the constructor. Is this something that could be changed in your repository and can be of any use in other projects?

thanks

#if defined(DNN_AVX512BW) || defined(DNN_AVX512)
	typedef Vec16f VecFloat;
	constexpr auto VectorSize = 16ull;
#elif defined(DNN_AVX2) || defined(DNN_AVX)
	typedef Vec8f VecFloat;
	constexpr auto VectorSize = 8ull;
#elif defined(DNN_SSE42) || defined(DNN_SSE41)
	typedef Vec4f VecFloat;
	constexpr auto VectorSize = 4ull;
#endif

inline static auto BernoulliVecFloat(const Float p = Float(0.5)) noexcept
{
	static thread_local auto generator = Ranvec1(Seed<int>(), static_cast<int>(std::hash<std::thread::id>()(std::this_thread::get_id())), 3);
#if defined(DNN_AVX512BW) || defined(DNN_AVX512)
	return select(generator.random16f() < p, VecFloat(1), VecFloat(0));
#elif defined(DNN_AVX2) || defined(DNN_AVX)
	return select(generator.random8f() < p, VecFloat(1), VecFloat(0));
#elif defined(DNN_SSE42) || defined(DNN_SSE41)
	return select(generator.random4f() < p, VecFloat(1), VecFloat(0));
#endif
}

small addition to the default constructor (ranvec1.h beginning at line 290) :

/******************************************************************************
        Ranvec1: Class for combined random number generator

Make one instance of Ranvec1 for each thread.
Remember to initialize it with a seed. 
Each instance must have a different seed if you want different random sequences
******************************************************************************/

// Combined random number generator. Derived class with various output functions
// (Total size depends on INSTRSET and MAX_VECTOR_SIZE)
class Ranvec1 : public Ranvec1base {
public:
    // Constructor
     Ranvec1(int gtype = 3) : Ranvec1base(gtype), buf32(this), buf64(this), buf128(this)
#if MAX_VECTOR_SIZE >= 256
    , buf256(this)
#endif
#if MAX_VECTOR_SIZE >= 512
    , buf512(this)
#endif
    {
        randomixInterval = randomixLimit = 0;
    }
    Ranvec1(int seed1, int gtype = 3) : Ranvec1base(gtype), buf32(this), buf64(this), buf128(this)
#if MAX_VECTOR_SIZE >= 256
        , buf256(this)
#endif
#if MAX_VECTOR_SIZE >= 512
        , buf512(this)
#endif
    {
        randomixInterval = randomixLimit = 0;
        Ranvec1base::init(seed1);
        resetBuffers();
    }
    Ranvec1(int seed1, int seed2, int gtype = 3) : Ranvec1base(gtype), buf32(this), buf64(this), buf128(this)
#if MAX_VECTOR_SIZE >= 256
    , buf256(this)
#endif
#if MAX_VECTOR_SIZE >= 512
    , buf512(this)
#endif
    {
        randomixInterval = randomixLimit = 0;
        Ranvec1base::init(seed1, seed2);
        resetBuffers();
    }
    Ranvec1(int32_t const seeds[], int numSeeds, int gtype = 3) : Ranvec1base(gtype), buf32(this), buf64(this), buf128(this)
#if MAX_VECTOR_SIZE >= 256
        , buf256(this)
#endif
#if MAX_VECTOR_SIZE >= 512
        , buf512(this)
#endif
    {
        randomixInterval = randomixLimit = 0;
        Ranvec1base::initByArray(seeds, numSeeds);
        resetBuffers();
    }

Efficient way to convert between interleaved and seperate real/imag

Hi,

I think it would be very useful if there was a built-in utility to convert between Vec4f real, Vec4f imag -> Complex4f complexVec and vice-versa, i.e. Complex4f complexVec -> Vec4f real, Vec4f imag.

Sometimes you maybe want to use atan2 which requires separate x and y vectors, or have to do some calculations on complex numbers which are stored in seperate real / imag arrays because your function is called from an external library, etc...

Code in physical_processors.cpp is not within VCL_NAMESPACE

The code in physical_processors.cpp is not within VCL_NAMESPACE causing a conflict with the prototypes in vectorclass/instrset.h when VCL_NAMESPACE is defined.

// functions in instrset_detect.cpp:
#ifdef VCL_NAMESPACE
namespace VCL_NAMESPACE {
#endif
    int  instrset_detect(void);        // tells which instruction sets are supported
    bool hasFMA3(void);                // true if FMA3 instructions supported
    bool hasFMA4(void);                // true if FMA4 instructions supported
    bool hasXOP(void);                 // true if XOP  instructions supported
    bool hasAVX512ER(void);            // true if AVX512ER instructions supported
    bool hasAVX512VBMI(void);          // true if AVX512VBMI instructions supported
    bool hasAVX512VBMI2(void);         // true if AVX512VBMI2 instructions supported

    // function in physical_processors.cpp:
    int physicalProcessors(int * logical_processors = 0);

#ifdef VCL_NAMESPACE
}
#endif

complexvec1.h ignores MAX_VECTOR_SIZE

When you set MAX_VECTOR_SIZE=256, vectorclass1.h fails to compile:

In file included from ../src/functionality/generateBalloon.cpp:10:
../secret-project-name/external/vectorclass-version2/include/add-on/complex/complexvec1.h:1010:5: error: unknown type name 'Vec16f'
    Vec16f y; // vector of 8 floats
    ^
../secret-project-name/external/vectorclass-version2/include/add-on/complex/complexvec1.h:1058:15: error: unknown type name 'Vec16f'
    Complex8f(Vec16f const x) {  // constructor to convert from emulated Vec16f
              ^
../secret-project-name/external/vectorclass-version2/include/add-on/complex/complexvec1.h:1076:5: error: unknown type name 'Vec16f'
    Vec16f to_vector() const {
    ^
../secret-project-name/external/vectorclass-version2/include/add-on/complex/complexvec1.h:1025:13: error: use of undeclared identifier 'Vec16f'
        y = Vec16f(Vec8f(a2), Vec8f(a2));
            ^
../secret-project-name/external/vectorclass-version2/include/add-on/complex/complexvec1.h:1034:13: error: use of undeclared identifier 'Vec16f'
        y = Vec16f(Vec8f(a2), Vec8f(a2));
            ^
../secret-project-name/external/vectorclass-version2/include/add-on/complex/complexvec1.h:1039:13: error: use of undeclared identifier 'Vec16f'
        y = Vec16f(Vec8f(a), Vec8f(b));
            ^
../secret-project-name/external/vectorclass-version2/include/add-on/complex/complexvec1.h:1044:13: error: use of undeclared identifier 'Vec16f'
        y = Vec16f(Vec8f(Complex4f(Complex2f(a0,a1),Complex2f(a2,a3))),
            ^
../secret-project-name/external/vectorclass-version2/include/add-on/complex/complexvec1.h:1081:13: error: use of undeclared identifier 'Vec16f'
        y = Vec16f().load(p);
            ^
../secret-project-name/external/vectorclass-version2/include/add-on/complex/complexvec1.h:1201:15: error: unknown type name 'Vec16fb'
static inline Vec16fb operator == (Complex8f const a, Complex8f const b) {
              ^
../secret-project-name/external/vectorclass-version2/include/add-on/complex/complexvec1.h:1208:12: error: use of undeclared identifier 'Vec16fb'
    return Vec16fb(a.get_low() == b.get_low(), a.get_high() == b.get_high());
           ^
../secret-project-name/external/vectorclass-version2/include/add-on/complex/complexvec1.h:1213:15: error: unknown type name 'Vec16fb'
static inline Vec16fb operator != (Complex8f const a, Complex8f const b) {
              ^
../secret-project-name/external/vectorclass-version2/include/add-on/complex/complexvec1.h:1261:38: error: use of undeclared identifier 'Vec16f'
    return Complex8f(a.to_vector() / Vec16f(b));
                                     ^
../secret-project-name/external/vectorclass-version2/include/add-on/complex/complexvec1.h:1331:33: error: unknown type name 'Vec16fb'
static inline Complex8f select (Vec16fb const s, Complex8f const a, Complex8f const b) {
                                ^
../secret-project-name/external/vectorclass-version2/include/add-on/complex/complexvec1.h:1947:5: error: unknown type name 'Vec8d'
    Vec8d y; // vector of 4 doubles
    ^
../secret-project-name/external/vectorclass-version2/include/add-on/complex/complexvec1.h:1985:15: error: unknown type name 'Vec8d'
    Complex4d(Vec8d const x) {
              ^
../secret-project-name/external/vectorclass-version2/include/add-on/complex/complexvec1.h:1993:29: error: unknown type name 'Vec8d'
    Complex4d & operator = (Vec8d const x) {
                            ^
../secret-project-name/external/vectorclass-version2/include/add-on/complex/complexvec1.h:2005:5: error: unknown type name 'Vec8d'
    Vec8d to_vector() const {
    ^
../secret-project-name/external/vectorclass-version2/include/add-on/complex/complexvec1.h:1961:13: error: use of undeclared identifier 'Vec8d'
        y = Vec8d(Complex2d(a).to_vector(), Complex2d(a).to_vector());
            ^
../secret-project-name/external/vectorclass-version2/include/add-on/complex/complexvec1.h:1966:13: error: use of undeclared identifier 'Vec8d'
        y = Vec8d(Vec4d(Complex2d(a0,a1)), Vec4d(Complex2d(a2,a3)));

Complex4d is not used, of course.

const pointers to load and question on casting "SIMD" type to float

First of all, this is a great library. Has been really helpful in my machine learning algorithms implementations.

I wanted to suggest a change in vector_containers.h on the load method

It should take const void* type instead void*

Related issue

Questions

In the excellent vc_manual, on page 73, there is the following snippet:

// Access array as single elements :
float* mydataf = (float*)mydata ;
int i;
for (i = 0; i < datasize ; ++i) {
  mydataf[i] = (float)i ;
}

But I have seen that although casting from float to "simd_type" is fine, it may not be okay, the other way around.

float x ;
__m128* x_simd = reinterpret_cast<__m128*>(&x) ; // <--- This is fine

but

__m128 x _simd;
float* x = reinterpret_cast<float*>(&x_simd) ; // <--- This may not be fine

See for reference this stackoverflow answer and this stack overflow post

I had raised a similar question in the Vc library which is also used in some of the codebases I had worked on.

possible bug in Ranvec1 class version 2.0 under windows 10 x64 with Zen2 cpu?

Hi,
First of all, thanks for your great code!

I'm having a strange bug when using the version 2.0 of the ranvec1 class when using gentype 3
under Windows10 x64 with the VS2019 compiler on a ryzen 3900x processor

The following code works flawless when using version 1.25 of the ranvec1 class:

static const Vec8f BernoulliVecFloat(const Float& keepRate)
{
__declspec(align(64)) static thread_local Ranvec1* generator;

if (!generator)
{
	generator = new Ranvec1(3);
	generator->init(int(std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::high_resolution_clock::now().time_since_epoch()).count() + std::hash<std::thread::id>()(std::this_thread::get_id())));
}
return select((*generator).random8f() < keepRate, Vec8f(1), Vec8f(0));

}

I must make a small change to Ranvec1base class to get the aligment requirements right:
__declspec(align(64)) class Ranvec1base {
public:
Ranvec1base(int gtype = 3); // Constructor
void* operator new(size_t i)
{
return _aligned_malloc(i, 64);
}
void operator delete(void* p)
{
_aligned_free(p);
}

The bug doesn't happen in Debug mode. And on a Intel Haswell platform it strangly doesn't occur!
Has this something to do with the problem Zen2 has with the rdrand instruction?

thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.