Required changes resolved

This commit is contained in:
doinachiroiu 2020-08-27 12:54:57 +00:00
parent 5ae99706e2
commit bb623d4c0b
3 changed files with 79 additions and 67 deletions

View File

@ -88,7 +88,7 @@ add_sapi_library(pffft_sapi
INPUTS master/pffft.h master/fftpack.h INPUTS master/pffft.h master/fftpack.h
LIBRARY pffft LIBRARY pffft
LIBRARY_NAME pffft LIBRARY_NAME Pffft
NAMESPACE "" NAMESPACE ""
) )

View File

@ -4,7 +4,9 @@ Build System: CMake
OS: Linux OS: Linux
### Check out the PFFFT library & CMake set up ### Check out the PFFFT library & CMake set up
`git submodule add https://bitbucket.org/jpommier/pffft.git` `git clone https://github.com/doinachiroiu/sandboxed-api/tree/master/oss-internship-2020/pffft`
`git submodule update --init --recursive`
`mkdir -p build && cd build` `mkdir -p build && cd build`
@ -22,7 +24,7 @@ display custom info with
## ***About the project*** ## ***About the project***
*PFFFT library is concerned with 1D Fast-Fourier Transformations finding a *PFFFT library is concerned with 1D Fast-Fourier Transformations finding a
compromise between accuracy and speed. It deals with real and complex compromise between accuracy and speed. It deals with real and complex
vectors, both cases being illustrated in the testing part (`main_pffft.c` vectors, both cases being illustrated in the testing part (`test_pffft.c`
for initially and original version, `main_pffft_sandboxed.cc` for our for initially and original version, `main_pffft_sandboxed.cc` for our
currently implemented sandboxed version). currently implemented sandboxed version).
The original files can be found at: https://bitbucket.org/jpommier/pffft/src.* The original files can be found at: https://bitbucket.org/jpommier/pffft/src.*
@ -62,7 +64,8 @@ In the end, the performance of PFFFT library it is outlined by the output.*
### Bugs history ### Bugs history
1. [Solved] pffft benchmark bug: "Sandbox not active" 1. [Solved] pffft benchmark bug: "Sandbox not active"
N = 64, status OK, pffft_transform generates error N = 64, status OK, pffft_transform generates error
N > 64, status not OK N > 64, status not OK
Problem on initialising sapi::StatusOr<PFFFT_Setup *> s; the memory that stays Problem on initialising sapi::StatusOr<PFFFT_Setup *> s; the memory that stays
@ -75,7 +78,8 @@ In the end, the performance of PFFFT library it is outlined by the output.*
Solution: using "sapi::v::RemotePtr" instead of "sapi::v::GenericPtr" Solution: using "sapi::v::RemotePtr" instead of "sapi::v::GenericPtr"
to access the memory of object s to access the memory of object s
2. [Unresolved] compiling bug: "No space left on device" 2. [Unresolved] compiling bug: "No space left on device"
The building process creates some `embed` files that use lots of The building process creates some `embed` files that use lots of
memory, trying to write them on /tmp. memory, trying to write them on /tmp.

View File

@ -30,10 +30,10 @@
ABSL_DECLARE_FLAG(string, sandbox2_danger_danger_permit_all); ABSL_DECLARE_FLAG(string, sandbox2_danger_danger_permit_all);
ABSL_DECLARE_FLAG(string, sandbox2_danger_danger_permit_all_and_log); ABSL_DECLARE_FLAG(string, sandbox2_danger_danger_permit_all_and_log);
class PffftSapiSandbox : public pffftSandbox { class PffftSapiSandbox : public PffftSandbox {
public: public:
std::unique_ptr<sandbox2::Policy> ModifyPolicy( std::unique_ptr<sandbox2::Policy> ModifyPolicy(
sandbox2::PolicyBuilder*) override { sandbox2::PolicyBuilder*) {
return sandbox2::PolicyBuilder() return sandbox2::PolicyBuilder()
.AllowStaticStartup() .AllowStaticStartup()
.AllowOpen() .AllowOpen()
@ -50,11 +50,11 @@ class PffftSapiSandbox : public pffftSandbox {
} }
}; };
double UclockSec(void) { return (double)clock() / (double)CLOCKS_PER_SEC; } double UclockSec() { return static_cast<double>(clock()) / CLOCKS_PER_SEC; }
int array_output_format = 0; int array_output_format = 0;
void ShowOutput(const char* name, int N, int cplx, float flops, float t0, void ShowOutput(const char* name, int n, int cplx, float flops, float t0,
float t1, int max_iter) { float t1, int max_iter) {
float mflops = flops / 1e6 / (t1 - t0 + 1e-16); float mflops = flops / 1e6 / (t1 - t0 + 1e-16);
if (array_output_format) { if (array_output_format) {
@ -64,7 +64,7 @@ void ShowOutput(const char* name, int N, int cplx, float flops, float t0,
printf("| n/a "); printf("| n/a ");
} else { } else {
if (flops != -1) { if (flops != -1) {
printf("N=%5d, %s %16s : %6.0f MFlops [t=%6.0f ns, %d runs]\n", N, printf("n=%5d, %s %16s : %6.0f MFlops [t=%6.0f ns, %d runs]\n", n,
(cplx ? "CPLX" : "REAL"), name, mflops, (cplx ? "CPLX" : "REAL"), name, mflops,
(t1 - t0) / 2 / max_iter * 1e9, max_iter); (t1 - t0) / 2 / max_iter * 1e9, max_iter);
} }
@ -72,55 +72,64 @@ void ShowOutput(const char* name, int N, int cplx, float flops, float t0,
fflush(stdout); fflush(stdout);
} }
int main(int argc, char* argv[]) { absl::Status PffftMain() {
PffftSapiSandbox sandbox;
SAPI_RETURN_IF_ERROR(sandbox.Init());
return absl::OkStatus();
}
int main(int argc, char* argv[]) {
// Initialize Google's logging library. // Initialize Google's logging library.
google::InitGoogleLogging(argv[0]); google::InitGoogleLogging(argv[0]);
gflags::ParseCommandLineFlags(&argc, &argv, true); gflags::ParseCommandLineFlags(&argc, &argv, true);
// Nvalues is a vector keeping the values by which iterates N, its value // kTransformSizes is a vector keeping the values by which iterates n, its value
// representing the input length. More concrete, N is the number of // representing the input length. More concrete, n is the number of
// data points the caclulus is up to (determinating its accuracy). // data points the caclulus is up to (determinating its accuracy).
// To show the performance of Fast-Fourier Transformations the program is // To show the performance of Fast-Fourier Transformations the program is
// testing for various values of N. // testing for various values of n.
int Nvalues[] = {64, 96, 128, 160, 192, 256, constexpr int kTransformSizes[] = {64, 96, 128, 160, 192, 256,
384, 5 * 96, 512, 5 * 128, 3 * 256, 800, 384, 5 * 96, 512, 5 * 128, 3 * 256, 800,
1024, 2048, 2400, 4096, 8192, 9 * 1024, 1024, 2048, 2400, 4096, 8192, 9 * 1024,
16384, 32768}; 16384, 32768};
int i;
LOG(INFO) << "Initializing sandbox...\n"; LOG(INFO) << "Initializing sandbox...\n";
PffftSapiSandbox sandbox; PffftSapiSandbox sandbox;
absl::Status init_status = sandbox.Init(); absl::Status init_status = sandbox.Init();
LOG(INFO) << "Initialization: " << init_status.ToString().c_str() << "\n"; if (absl::Status status = PffftMain(); !status.ok()) {
LOG(ERROR) << "Initialization failed: " << status.ToString();
return EXIT_FAILURE;
}
pffftApi api(&sandbox); LOG(INFO) << "Initialization: " << init_status.ToString();
PffftApi api(&sandbox);
int cplx = 0; int cplx = 0;
do { do {
for (int N : Nvalues) { for (int n : kTransformSizes) {
const int Nfloat = N * (cplx ? 2 : 1); const int n_float = n * (cplx ? 2 : 1);
int Nbytes = Nfloat * sizeof(float); int n_bytes = n_float * sizeof(float);
float wrk[2 * Nfloat + 15 * sizeof(float)]; std::vector<float> work(2 * n_float + 15, 0.0);
sapi::v::Array<float> wrk_(wrk, 2 * Nfloat + 15 * sizeof(float)); sapi::v::Array<float> work_array(&work[0], work.size());
float X[Nbytes], Y[Nbytes], Z[Nbytes]; float x[n_bytes], y[n_bytes], z[n_bytes];
sapi::v::Array<float> X_(X, Nbytes), Y_(Y, Nbytes), Z_(Z, Nbytes); sapi::v::Array<float> x_array(x, n_bytes), y_array(y, n_bytes), z_array(z, n_bytes);
double t0, t1, flops; double t0;
double t1;
double flops;
int max_iter = 5120000 / N * 4; int k;
#ifdef __arm__ int max_iter = 5120000 / n * 4;
max_iter /= 4;
#endif
int iter, k;
for (k = 0; k < Nfloat; ++k) { for (k = 0; k < n_float; ++k) {
X[k] = 0; x[k] = 0;
} }
// FFTPack benchmark // FFTPack benchmark
@ -130,50 +139,49 @@ int main(int argc, char* argv[]) {
if (max_iter_ == 0) max_iter_ = 1; if (max_iter_ == 0) max_iter_ = 1;
if (cplx) { if (cplx) {
api.cffti(N, wrk_.PtrBoth()).IgnoreError(); api.cffti(n, work_array.PtrBoth()).IgnoreError();
} else { } else {
api.rffti(N, wrk_.PtrBoth()).IgnoreError(); api.rffti(n, work_array.PtrBoth()).IgnoreError();
} }
t0 = UclockSec(); t0 = UclockSec();
for (iter = 0; iter < max_iter_; ++iter) { for (int iter = 0; iter < max_iter_; ++iter) {
if (cplx) { if (cplx) {
api.cfftf(N, X_.PtrBoth(), wrk_.PtrBoth()).IgnoreError(); api.cfftf(n, x_array.PtrBoth(), work_array.PtrBoth()).IgnoreError();
api.cfftb(N, X_.PtrBoth(), wrk_.PtrBoth()).IgnoreError(); api.cfftb(n, x_array.PtrBoth(), work_array.PtrBoth()).IgnoreError();
} else { } else {
api.rfftf(N, X_.PtrBoth(), wrk_.PtrBoth()).IgnoreError(); api.rfftf(n, x_array.PtrBoth(), work_array.PtrBoth()).IgnoreError();
api.rfftb(N, X_.PtrBoth(), wrk_.PtrBoth()).IgnoreError(); api.rfftb(n, x_array.PtrBoth(), work_array.PtrBoth()).IgnoreError();
} }
} }
t1 = UclockSec(); t1 = UclockSec();
flops = flops =
(max_iter_ * 2) * ((cplx ? 5 : 2.5) * N * log((double)N) / M_LN2); (max_iter_ * 2) * ((cplx ? 5 : 2.5) * n * log((double)n) / M_LN2);
ShowOutput("FFTPack", N, cplx, flops, t0, t1, max_iter_); ShowOutput("FFTPack", n, cplx, flops, t0, t1, max_iter_);
} }
// PFFFT benchmark // PFFFT benchmark
{ {
sapi::StatusOr<PFFFT_Setup*> s = sapi::StatusOr<PFFFT_Setup*> s =
api.pffft_new_setup(N, cplx ? PFFFT_COMPLEX : PFFFT_REAL); api.pffft_new_setup(n, cplx ? PFFFT_COMPLEX : PFFFT_REAL);
LOG(INFO) << "Setup status is: " << s.status().ToString().c_str() LOG(INFO) << "Setup status is: " << s.status().ToString();
<< "\n";
if (!s.ok()) { if (!s.ok()) {
printf("Sandbox failed.\n"); printf("Sandbox failed.\n");
return 1; return EXIT_FAILURE;
} }
sapi::v::RemotePtr s_reg(s.value()); sapi::v::RemotePtr s_reg(s.value());
t0 = UclockSec(); t0 = UclockSec();
for (iter = 0; iter < max_iter; ++iter) { for (int iter = 0; iter < max_iter; ++iter) {
api.pffft_transform(&s_reg, X_.PtrBoth(), Z_.PtrBoth(), api.pffft_transform(&s_reg, x_array.PtrBoth(), z_array.PtrBoth(),
Y_.PtrBoth(), PFFFT_FORWARD) y_array.PtrBoth(), PFFFT_FORWARD)
.IgnoreError(); .IgnoreError();
api.pffft_transform(&s_reg, X_.PtrBoth(), Z_.PtrBoth(), api.pffft_transform(&s_reg, x_array.PtrBoth(), z_array.PtrBoth(),
Y_.PtrBoth(), PFFFT_FORWARD) y_array.PtrBoth(), PFFFT_FORWARD)
.IgnoreError(); .IgnoreError();
} }
@ -181,15 +189,15 @@ int main(int argc, char* argv[]) {
api.pffft_destroy_setup(&s_reg).IgnoreError(); api.pffft_destroy_setup(&s_reg).IgnoreError();
flops = flops =
(max_iter * 2) * ((cplx ? 5 : 2.5) * N * log((double)N) / M_LN2); (max_iter * 2) * ((cplx ? 5 : 2.5) * n * log((double)n) / M_LN2);
ShowOutput("PFFFT", N, cplx, flops, t0, t1, max_iter); ShowOutput("PFFFT", n, cplx, flops, t0, t1, max_iter);
LOG(INFO) << "N = " << N << " SUCCESSFULLY\n\n"; LOG(INFO) << "n = " << n << " SUCCESSFULLY";
} }
} }
cplx = !cplx; cplx = !cplx;
} while (cplx); } while (cplx);
return 0; return EXIT_SUCCESS;
} }