-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
34 changed files
with
2,450 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
70 changes: 70 additions & 0 deletions
70
tee-provider/non_sgx_gramine/alexnet/pytorch.manifest.template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# PyTorch manifest template | ||
|
||
loader.entrypoint = "file:{{ gramine.libos }}" | ||
libos.entrypoint = "{{ entrypoint }}" | ||
|
||
loader.log_level = "{{ log_level }}" | ||
|
||
loader.env.LD_LIBRARY_PATH = "/lib:/usr/lib:{{ arch_libdir }}:/usr/{{ arch_libdir }}" | ||
|
||
# Restrict the maximum number of threads to prevent insufficient memory | ||
# issue, observed on CentOS/RHEL. | ||
loader.env.OMP_NUM_THREADS = "8" | ||
|
||
loader.insecure__use_cmdline_argv = true | ||
loader.insecure__use_host_env = true | ||
|
||
loader.pal_internal_mem_size = "128M" | ||
|
||
fs.mounts = [ | ||
{ uri = "file:{{ gramine.runtimedir() }}", path = "/lib" }, | ||
{ uri = "file:{{ arch_libdir }}", path = "{{ arch_libdir }}" }, | ||
{ uri = "file:/usr", path = "/usr" }, | ||
{ uri = "file:/etc", path = "/etc" }, | ||
{ uri = "file:{{ pillow_path }}", path = "{{ pillow_path }}" }, | ||
|
||
{ type = "tmpfs", path = "/tmp" }, | ||
] | ||
|
||
# PyTorch loads its pre-trained models from here | ||
# Add below uncommented line to fs.mounts array if you want to use torchvision.model.alexnet(pretrained=True) | ||
# { type = "chroot", uri = "file:{{ env.HOME }}/.cache/torch", path = "{{ env.HOME }}/.cache/torch" } | ||
|
||
sgx.nonpie_binary = true | ||
sgx.enclave_size = "4G" | ||
sgx.thread_num = 32 | ||
|
||
sgx.trusted_files = [ | ||
"file:{{ gramine.libos }}", | ||
"file:{{ entrypoint }}", | ||
"file:{{ gramine.runtimedir() }}/", | ||
"file:{{ arch_libdir }}/", | ||
"file:/usr/{{ arch_libdir }}/", | ||
"file:{{ python.stdlib }}/", | ||
"file:{{ python.distlib }}/", | ||
"file:{{ pillow_path }}", | ||
"file:{{ python.get_path('stdlib', vars={'installed_base': '/usr/local'}) }}/", | ||
|
||
"file:pytorchexample.py", | ||
|
||
"file:classes.txt", | ||
"file:input.jpg", | ||
"file:alexnet-pretrained.pt", # Pre-trained model saved as a file | ||
|
||
# Uncomment line below if you want to use torchvision.model.alexnet(pretrained=True) | ||
# "file:{{ env.HOME }}/.cache/torch/checkpoints/alexnet-owt-4df8aa71.pth", | ||
] | ||
|
||
sgx.allowed_files = [ | ||
"file:result.txt", | ||
] | ||
|
||
# Gramine optionally provides patched OpenMP runtime library that runs faster | ||
# inside SGX enclaves (execute `make -C LibOS gcc` to generate it). Uncomment | ||
# the lines below to use the patched library. PyTorch's SGX perf overhead | ||
# decreases on some workloads from 25% to 8% with this patched library. Note | ||
# that we need to preload the library because PyTorch's distribution renames | ||
# libgomp.so to smth like libgomp-7c85b1e2.so.1, so it's not just a matter of | ||
# searching in the Gramine's Runtime path first, but a matter of intercepting | ||
# OpenMP functions. | ||
# loader.env.LD_PRELOAD = "/lib/libgomp.so.1" |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# PyTorch and the pre-trained model must be installed on the system. See README for details. | ||
|
||
ARCH_LIBDIR ?= /lib/$(shell $(CC) -dumpmachine) | ||
|
||
# PyTorch uses the Pillow backend; detect where Pillow was installed | ||
PILLOW_PATH ?= $(shell pip3 show pillow | grep Location: | cut -d" " -f2)/ | ||
|
||
ifeq ($(DEBUG),1) | ||
GRAMINE_LOG_LEVEL = debug | ||
else | ||
GRAMINE_LOG_LEVEL = error | ||
endif | ||
|
||
.PHONY: all | ||
all: pytorch.manifest | ||
ifeq ($(SGX),1) | ||
all: pytorch.manifest.sgx pytorch.sig pytorch.token | ||
endif | ||
|
||
pytorch.manifest: pytorch.manifest.template | ||
gramine-manifest \ | ||
-Dlog_level=$(GRAMINE_LOG_LEVEL) \ | ||
-Dpillow_path=$(PILLOW_PATH) \ | ||
-Darch_libdir=$(ARCH_LIBDIR) \ | ||
-Dentrypoint=$(realpath $(shell sh -c "command -v python3")) \ | ||
$< > $@ | ||
|
||
# Make on Ubuntu <= 20.04 doesn't support "Rules with Grouped Targets" (`&:`), | ||
# for details on this workaround see | ||
# https://github.com/gramineproject/gramine/blob/e8735ea06c/CI-Examples/helloworld/Makefile | ||
pytorch.manifest.sgx pytorch.sig: sgx_sign | ||
@: | ||
|
||
.INTERMEDIATE: sgx_sign | ||
sgx_sign: pytorch.manifest | ||
gramine-sgx-sign \ | ||
--manifest $< \ | ||
--output $<.sgx | ||
|
||
pytorch.token: pytorch.sig | ||
gramine-sgx-get-token --output $@ --sig $< | ||
|
||
.PHONY: clean | ||
clean: | ||
$(RM) *.token *.sig *.manifest.sgx *.manifest | ||
|
||
.PHONY: distclean | ||
distclean: clean | ||
$(RM) *.pt result.txt |
File renamed without changes.
8 changes: 8 additions & 0 deletions
8
tee-provider/sgx_gramine/encrypted_model/alexnet/download-pretrained-model.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from torchvision import models | ||
import torch | ||
|
||
output_filename = "alexnet-pretrained.pt" | ||
alexnet = models.alexnet(pretrained=True) | ||
torch.save(alexnet, output_filename) | ||
|
||
print("Pre-trained model was saved in \"%s\"" % output_filename) |
File renamed without changes
Oops, something went wrong.