Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Env var settings #78

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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: 8 additions & 0 deletions Credit Card Fraud/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ @implementation AppDelegate

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
// Insert code here to initialize your application
NSDictionary *env = @{ @"HELAYERS_EXAMPLES_OUTPUT_DIR" : NSHomeDirectory()};
NSString *outputDir = [NSString stringWithFormat:@"%@/output", NSHomeDirectory()];
setenv("HELAYERS_EXAMPLES_OUTPUT_DIR", [outputDir cStringUsingEncoding:nil], 1);
NSLog(@"Looking for Env Var");
NSString *result = [[[NSProcessInfo processInfo] environment] objectForKey:@"HELAYERS_EXAMPLES_OUTPUT_DIR"];
NSLog(@"%@", result);


}


Expand Down
22 changes: 13 additions & 9 deletions Credit Card Fraud/ClientServer/ClientServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@
using namespace std;
using namespace helayers;

const string outDir = getExamplesOutputDir();
const string clientContext = outDir + "/client_context.bin";
const string serverContext = outDir + "/server_context.bin";
const string encryptedModelFile = outDir + "/encrypted_model.bin";
string outputDirectory;
string theClientContext;
string theServerContext;
string fullyEncryptedModelFile;

// paths from which to load the plain model, samples and labels
const string plainModelFile = "/model_42098.h5";
Expand All @@ -61,8 +61,12 @@ Client::~Client() {}

void Client::init()
{
cout << "CLIENT: loading client side context . . ." << endl;
he = HeContext::loadHeContextFromFile(clientContext);
cout << "CLIENT: loading client side context . . ." << endl;
outputDirectory = getenv("HELAYERS_EXAMPLES_OUTPUT_DIR");
theClientContext = outputDirectory + "/client_context.bin";
theServerContext = outputDirectory + "/server_context.bin";
fullyEncryptedModelFile = outputDirectory + "/encrypted_model.bin";;
he = HeContext::loadHeContextFromFile(theClientContext);
he->printSignature(cout);
batchSize = he->slotCount();

Expand All @@ -80,7 +84,7 @@ void Client::init()
netHe.initFromNet(plainNet);

cout << "CLIENT: saving encrypted model . . ." << endl;
ofstream ofs(encryptedModelFile, ios::out | ios::binary);
ofstream ofs(fullyEncryptedModelFile, ios::out | ios::binary);
netHe.save(ofs);
ofs.close();

Expand Down Expand Up @@ -208,11 +212,11 @@ Server::~Server() {}
void Server::init()
{
cout << "SERVER: loading server side context . . ." << endl;
he = HeContext::loadHeContextFromFile(serverContext);
he = HeContext::loadHeContextFromFile(theServerContext);
he->printSignature(cout);

cout << "SERVER: loading encrypted model . . ." << endl;
ifstream ifs(encryptedModelFile, ios::in | ios::binary);
ifstream ifs(fullyEncryptedModelFile, ios::in | ios::binary);
SimpleNeuralNet net(*he);
net.load(ifs);
ifs.close();
Expand Down
11 changes: 7 additions & 4 deletions Credit Card Fraud/CreditCardInferenceViewController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@

// define names of files to be used for saving and loading of HE contexts and
// encrypted model
const string outDir = getExamplesOutputDir();
const string clientContext = outDir + "/client_context.bin";
const string serverContext = outDir + "/server_context.bin";
string outDir;
string clientContext;
string serverContext;
bool runAll = false;

/*
Expand All @@ -54,7 +54,10 @@ void createContexts()
cout << "Initalizing HElib . . ." << endl;

shared_ptr<HeContext> hePtr;

outDir = getenv("HELAYERS_EXAMPLES_OUTPUT_DIR");
clientContext = outDir + "/client_context.bin";
serverContext = outDir + "/server_context.bin";
cout << outDir << endl;
// Preset configuration with 512 slots: low security level, but fast, just for
// the demo
hePtr = HelibContext::create(HELIB_NOT_SECURE_CKKS_512_FAST);
Expand Down
7 changes: 4 additions & 3 deletions dependencies/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ build_helib()
cmake -S. -B../HElib_macOS -GXcode \
-DCMAKE_SYSTEM_NAME=Darwin \
"-DCMAKE_OSX_ARCHITECTURES=arm64;x86_64" \
-DCMAKE_OSX_DEPLOYMENT_TARGET=10.14 \
-DCMAKE_OSX_DEPLOYMENT_TARGET=11.0 \
-DCMAKE_INSTALL_PREFIX=`pwd`/_install \
-DCMAKE_XCODE_ATTRIBUTE_ONLY_ACTIVE_ARCH=NO \
-DCMAKE_IOS_INSTALL_COMBINED=YES \
Expand All @@ -211,7 +211,8 @@ build_boost()
{
CURRENT_DIR=`pwd`
if [ ! -s ${CURRENT_DIR}/boost_1_72_0.tar.gz ]; then
curl -k -L -o ${CURRENT_DIR}/boost_1_72_0.tar.gz "https://dl.bintray.com/boostorg/release/1.72.0/source/boost_1_72_0.tar.gz"
#curl -k -L -o ${CURRENT_DIR}/boost_1_72_0.tar.gz "https://dl.bintray.com/boostorg/release/1.72.0/source/boost_1_72_0.tar.gz"
curl -fL -o ${CURRENT_DIR}/boost_1_72_0.tar.gz "https://boostorg.jfrog.io/artifactory/main/release/1.72.0/source/boost_1_72_0.tar.gz"
fi
tar xvzf "boost_${BOOST_VERSION}.tar.gz"
}
Expand Down Expand Up @@ -239,7 +240,7 @@ build_hdf5()
CURRENT_DIR=`pwd`
mkdir hdf5-1.12.0
cd hdf5-1.12.0
cmake -G "Xcode" -DCMAKE_OSX_ARCHITECTURES="x86_64" -DCMAKE_BUILD_TYPE:STRING=Release -DBUILD_SHARED_LIBS:BOOL=OFF -DBUILD_TESTING:BOOL=OFF -DHDF5_BUILD_TOOLS:BOOL=ON ../CMake-hdf5-1.12.0/hdf5-1.12.0
cmake -G "Xcode" -DCMAKE_OSX_ARCHITECTURES="x86_64" -DCMAKE_OSX_DEPLOYMENT_TARGET=11.0 -DCMAKE_BUILD_TYPE:STRING=Release -DBUILD_SHARED_LIBS:BOOL=OFF -DBUILD_TESTING:BOOL=OFF -DHDF5_BUILD_TOOLS:BOOL=ON ../CMake-hdf5-1.12.0/hdf5-1.12.0
CURRENT_DIR=`pwd`
xcodebuild -target hdf5-static
cd ../
Expand Down
6 changes: 4 additions & 2 deletions fhe-toolkit-macos.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1622,6 +1622,7 @@
"$(PROJECT_DIR)/dependencies/hdf5-1.12.0/bin/Debug",
"$(PROJECT_DIR)/dependencies/lib",
);
MACOSX_DEPLOYMENT_TARGET = 11.0;
OTHER_LDFLAGS = (
"$(inherited)",
"-ObjC",
Expand Down Expand Up @@ -1674,6 +1675,7 @@
"$(PROJECT_DIR)/dependencies/hdf5-1.12.0/bin/Debug",
"$(PROJECT_DIR)/dependencies/lib",
);
MACOSX_DEPLOYMENT_TARGET = 11.0;
OTHER_LDFLAGS = (
"$(inherited)",
"-ObjC",
Expand Down Expand Up @@ -1743,7 +1745,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.15;
MACOSX_DEPLOYMENT_TARGET = 11.0;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
ONLY_ACTIVE_ARCH = YES;
Expand Down Expand Up @@ -1796,7 +1798,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.15;
MACOSX_DEPLOYMENT_TARGET = 11.0;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
SDKROOT = macosx;
Expand Down