Skip to content
Open

SIMD #13

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
8 changes: 4 additions & 4 deletions common/encryption/serialization.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <vector>
#include "flatbuffers/model_generated.h"

uint8_t* serialize(std::map<std::string, std::vector<double>> model,
uint8_t* serialize(std::map<std::string, std::vector<float>> model,
int* serialized_buffer_size) {
flatbuffers::FlatBufferBuilder builder;
std::vector<flatbuffers::Offset<secagg::KVPair>> features;
Expand All @@ -29,14 +29,14 @@ uint8_t* serialize(std::map<std::string, std::vector<double>> model,
return ret_buffer;
}

std::map<std::string, std::vector<double>> deserialize(uint8_t* serialized_buffer) {
std::map<std::string, std::vector<double>> demodel;
std::map<std::string, std::vector<float>> deserialize(uint8_t* serialized_buffer) {
std::map<std::string, std::vector<float>> demodel;

auto model = secagg::GetModel(serialized_buffer);
auto kvpairs = model->kv();
auto num_kvs = kvpairs->size();
for (int i = 0; i < num_kvs; i++) {
std::vector<double> feature_values;
std::vector<float> feature_values;
auto pair = kvpairs->Get(i);

// Key is a string
Expand Down
2 changes: 1 addition & 1 deletion common/flatbuffers/model.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ namespace secagg;

table KVPair {
key:string;
value:[double];
value:[float];
}

table Model {
Expand Down
12 changes: 6 additions & 6 deletions common/flatbuffers/model_generated.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ struct KVPair FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
const flatbuffers::String *key() const {
return GetPointer<const flatbuffers::String *>(VT_KEY);
}
const flatbuffers::Vector<double> *value() const {
return GetPointer<const flatbuffers::Vector<double> *>(VT_VALUE);
const flatbuffers::Vector<float> *value() const {
return GetPointer<const flatbuffers::Vector<float> *>(VT_VALUE);
}
bool Verify(flatbuffers::Verifier &verifier) const {
return VerifyTableStart(verifier) &&
Expand All @@ -43,7 +43,7 @@ struct KVPairBuilder {
void add_key(flatbuffers::Offset<flatbuffers::String> key) {
fbb_.AddOffset(KVPair::VT_KEY, key);
}
void add_value(flatbuffers::Offset<flatbuffers::Vector<double>> value) {
void add_value(flatbuffers::Offset<flatbuffers::Vector<float>> value) {
fbb_.AddOffset(KVPair::VT_VALUE, value);
}
explicit KVPairBuilder(flatbuffers::FlatBufferBuilder &_fbb)
Expand All @@ -61,7 +61,7 @@ struct KVPairBuilder {
inline flatbuffers::Offset<KVPair> CreateKVPair(
flatbuffers::FlatBufferBuilder &_fbb,
flatbuffers::Offset<flatbuffers::String> key = 0,
flatbuffers::Offset<flatbuffers::Vector<double>> value = 0) {
flatbuffers::Offset<flatbuffers::Vector<float>> value = 0) {
KVPairBuilder builder_(_fbb);
builder_.add_value(value);
builder_.add_key(key);
Expand All @@ -71,9 +71,9 @@ inline flatbuffers::Offset<KVPair> CreateKVPair(
inline flatbuffers::Offset<KVPair> CreateKVPairDirect(
flatbuffers::FlatBufferBuilder &_fbb,
const char *key = nullptr,
const std::vector<double> *value = nullptr) {
const std::vector<float> *value = nullptr) {
auto key__ = key ? _fbb.CreateString(key) : 0;
auto value__ = value ? _fbb.CreateVector<double>(*value) : 0;
auto value__ = value ? _fbb.CreateVector<float>(*value) : 0;
return secagg::CreateKVPair(
_fbb,
key__,
Expand Down
81 changes: 81 additions & 0 deletions common/intrinsics/adxintrin.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/* Copyright (C) 2012-2017 Free Software Foundation, Inc.

This file is part of GCC.

GCC is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.

GCC is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

Under Section 7 of GPL version 3, you are granted additional
permissions described in the GCC Runtime Library Exception, version
3.1, as published by the Free Software Foundation.

You should have received a copy of the GNU General Public License and
a copy of the GCC Runtime Library Exception along with this program;
see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
<http://www.gnu.org/licenses/>. */

#if !defined _X86INTRIN_H_INCLUDED && !defined _IMMINTRIN_H_INCLUDED
# error "Never use <adxintrin.h> directly; include <x86intrin.h> instead."
#endif

#ifndef _ADXINTRIN_H_INCLUDED
#define _ADXINTRIN_H_INCLUDED

extern __inline unsigned char
__attribute__((__gnu_inline__, __always_inline__, __artificial__))
_subborrow_u32 (unsigned char __CF, unsigned int __X,
unsigned int __Y, unsigned int *__P)
{
return __builtin_ia32_sbb_u32 (__CF, __X, __Y, __P);
}

extern __inline unsigned char
__attribute__((__gnu_inline__, __always_inline__, __artificial__))
_addcarry_u32 (unsigned char __CF, unsigned int __X,
unsigned int __Y, unsigned int *__P)
{
return __builtin_ia32_addcarryx_u32 (__CF, __X, __Y, __P);
}

extern __inline unsigned char
__attribute__((__gnu_inline__, __always_inline__, __artificial__))
_addcarryx_u32 (unsigned char __CF, unsigned int __X,
unsigned int __Y, unsigned int *__P)
{
return __builtin_ia32_addcarryx_u32 (__CF, __X, __Y, __P);
}

#ifdef __x86_64__
extern __inline unsigned char
__attribute__((__gnu_inline__, __always_inline__, __artificial__))
_subborrow_u64 (unsigned char __CF, unsigned long long __X,
unsigned long long __Y, unsigned long long *__P)
{
return __builtin_ia32_sbb_u64 (__CF, __X, __Y, __P);
}

extern __inline unsigned char
__attribute__((__gnu_inline__, __always_inline__, __artificial__))
_addcarry_u64 (unsigned char __CF, unsigned long long __X,
unsigned long long __Y, unsigned long long *__P)
{
return __builtin_ia32_addcarryx_u64 (__CF, __X, __Y, __P);
}

extern __inline unsigned char
__attribute__((__gnu_inline__, __always_inline__, __artificial__))
_addcarryx_u64 (unsigned char __CF, unsigned long long __X,
unsigned long long __Y, unsigned long long *__P)
{
return __builtin_ia32_addcarryx_u64 (__CF, __X, __Y, __P);
}
#endif

#endif /* _ADXINTRIN_H_INCLUDED */
93 changes: 93 additions & 0 deletions common/intrinsics/ammintrin.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/* Copyright (C) 2007-2017 Free Software Foundation, Inc.

This file is part of GCC.

GCC is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.

GCC is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

Under Section 7 of GPL version 3, you are granted additional
permissions described in the GCC Runtime Library Exception, version
3.1, as published by the Free Software Foundation.

You should have received a copy of the GNU General Public License and
a copy of the GCC Runtime Library Exception along with this program;
see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
<http://www.gnu.org/licenses/>. */

/* Implemented from the specification included in the AMD Programmers
Manual Update, version 2.x */

#ifndef _AMMINTRIN_H_INCLUDED
#define _AMMINTRIN_H_INCLUDED

/* We need definitions from the SSE3, SSE2 and SSE header files*/
#include <intrinsics/pmmintrin.h>

#ifndef __SSE4A__
#pragma GCC push_options
#pragma GCC target("sse4a")
#define __DISABLE_SSE4A__
#endif /* __SSE4A__ */

extern __inline void __attribute__((__gnu_inline__, __always_inline__, __artificial__))
_mm_stream_sd (double * __P, __m128d __Y)
{
__builtin_ia32_movntsd (__P, (__v2df) __Y);
}

extern __inline void __attribute__((__gnu_inline__, __always_inline__, __artificial__))
_mm_stream_ss (float * __P, __m128 __Y)
{
__builtin_ia32_movntss (__P, (__v4sf) __Y);
}

extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
_mm_extract_si64 (__m128i __X, __m128i __Y)
{
return (__m128i) __builtin_ia32_extrq ((__v2di) __X, (__v16qi) __Y);
}

#ifdef __OPTIMIZE__
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
_mm_extracti_si64 (__m128i __X, unsigned const int __I, unsigned const int __L)
{
return (__m128i) __builtin_ia32_extrqi ((__v2di) __X, __I, __L);
}
#else
#define _mm_extracti_si64(X, I, L) \
((__m128i) __builtin_ia32_extrqi ((__v2di)(__m128i)(X), \
(unsigned int)(I), (unsigned int)(L)))
#endif

extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
_mm_insert_si64 (__m128i __X,__m128i __Y)
{
return (__m128i) __builtin_ia32_insertq ((__v2di)__X, (__v2di)__Y);
}

#ifdef __OPTIMIZE__
extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
_mm_inserti_si64(__m128i __X, __m128i __Y, unsigned const int __I, unsigned const int __L)
{
return (__m128i) __builtin_ia32_insertqi ((__v2di)__X, (__v2di)__Y, __I, __L);
}
#else
#define _mm_inserti_si64(X, Y, I, L) \
((__m128i) __builtin_ia32_insertqi ((__v2di)(__m128i)(X), \
(__v2di)(__m128i)(Y), \
(unsigned int)(I), (unsigned int)(L)))
#endif

#ifdef __DISABLE_SSE4A__
#undef __DISABLE_SSE4A__
#pragma GCC pop_options
#endif /* __DISABLE_SSE4A__ */

#endif /* _AMMINTRIN_H_INCLUDED */
Loading