Skip to content
This repository was archived by the owner on Mar 28, 2023. It is now read-only.

[SYCL] Check cache directory settings #337

Merged
merged 3 commits into from
Jul 27, 2021
Merged
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
110 changes: 7 additions & 103 deletions SYCL/KernelAndProgram/cache_env_vars.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,108 +22,12 @@
// CPU OCL JIT 0.12 0.12 0.16 1.1 16
// CPU OCL Cache 0.01 0.01 0.01 0.02 0.08

// CHECK-BUILD: piProgramBuild
// CHECK-BUILD-NOT: piProgramCreateWithBinary
// CHECK-BUILD-NOT: piProgramCreateWithBinary(
// CHECK-BUILD: piProgramCreate(
// CHECK-BUILD: piProgramBuild(

// CHECK-CACHE-NOT: piProgramBuild
// CHECK-CACHE: piProgramCreateWithBinary
// CHECK-CACHE-NOT: piProgramCreate(
// CHECK-CACHE: piProgramCreateWithBinary(
// CHECK-CACHE: piProgramBuild(

#define INC1(x) ((x) = (x) + 1);

#define INC10(x) \
INC1(x) \
INC1(x) \
INC1(x) \
INC1(x) \
INC1(x) \
INC1(x) \
INC1(x) \
INC1(x) \
INC1(x) \
INC1(x)

#define INC100(x) \
INC10(x) \
INC10(x) \
INC10(x) \
INC10(x) \
INC10(x) \
INC10(x) \
INC10(x) \
INC10(x) \
INC10(x) \
INC10(x)

#define INC1000(x) \
INC100(x) \
INC100(x) \
INC100(x) \
INC100(x) \
INC100(x) \
INC100(x) \
INC100(x) \
INC100(x) \
INC100(x) \
INC100(x)

#define INC10000(x) \
INC1000(x) \
INC1000(x) \
INC1000(x) \
INC1000(x) \
INC1000(x) \
INC1000(x) \
INC1000(x) \
INC1000(x) \
INC1000(x) \
INC1000(x)

#define INC100000(x) \
INC10000(x) \
INC10000(x) \
INC10000(x) \
INC10000(x) \
INC10000(x) \
INC10000(x) \
INC10000(x) \
INC10000(x) \
INC10000(x) \
INC10000(x)

#include <CL/sycl.hpp>
#include <chrono>
#include <iostream>
class Inc;
template <class Kernel> void check_build_time(cl::sycl::queue &q) {
cl::sycl::program program(q.get_context());
auto start = std::chrono::steady_clock::now();
program.build_with_kernel_type<Kernel>();
auto end = std::chrono::steady_clock::now();

std::chrono::duration<double> elapsed_seconds = end - start;
std::cout << "elapsed build time: " << elapsed_seconds.count() << "s\n";
}
int main(int argc, char **argv) {
auto start = std::chrono::steady_clock::now();
// Test program and kernel APIs when building a kernel.
{
cl::sycl::queue q;
check_build_time<Inc>(q);

int data = 0;
{
cl::sycl::buffer<int, 1> buf(&data, cl::sycl::range<1>(1));
cl::sycl::range<1> NumOfWorkItems{buf.get_count()};

q.submit([&](cl::sycl::handler &cgh) {
auto acc = buf.get_access<cl::sycl::access::mode::read_write>(cgh);
cgh.parallel_for<class Inc>(
NumOfWorkItems, [=](cl::sycl::id<1> WIid) { TARGET_IMAGE(acc[0]) });
});
}
// check_build_time<Inc>(q);
auto end = std::chrono::steady_clock::now();
std::chrono::duration<double> elapsed_seconds = end - start;
std::cout << "elapsed kernel time: " << elapsed_seconds.count() << "s\n";
}
}
#include "cache_env_vars.hpp"
101 changes: 101 additions & 0 deletions SYCL/KernelAndProgram/cache_env_vars.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#define SYCL2020_DISABLE_DEPRECATION_WARNINGS

#define INC1(x) ((x) = (x) + 1);

#define INC10(x) \
INC1(x) \
INC1(x) \
INC1(x) \
INC1(x) \
INC1(x) \
INC1(x) \
INC1(x) \
INC1(x) \
INC1(x) \
INC1(x)

#define INC100(x) \
INC10(x) \
INC10(x) \
INC10(x) \
INC10(x) \
INC10(x) \
INC10(x) \
INC10(x) \
INC10(x) \
INC10(x) \
INC10(x)

#define INC1000(x) \
INC100(x) \
INC100(x) \
INC100(x) \
INC100(x) \
INC100(x) \
INC100(x) \
INC100(x) \
INC100(x) \
INC100(x) \
INC100(x)

#define INC10000(x) \
INC1000(x) \
INC1000(x) \
INC1000(x) \
INC1000(x) \
INC1000(x) \
INC1000(x) \
INC1000(x) \
INC1000(x) \
INC1000(x) \
INC1000(x)

#define INC100000(x) \
INC10000(x) \
INC10000(x) \
INC10000(x) \
INC10000(x) \
INC10000(x) \
INC10000(x) \
INC10000(x) \
INC10000(x) \
INC10000(x) \
INC10000(x)

#include <CL/sycl.hpp>
#include <chrono>
#include <iostream>
class Inc;
template <class Kernel> void check_build_time(cl::sycl::queue &q) {
cl::sycl::program program(q.get_context());
auto start = std::chrono::steady_clock::now();
program.build_with_kernel_type<Kernel>();
auto end = std::chrono::steady_clock::now();

std::chrono::duration<double> elapsed_seconds = end - start;
std::cout << "elapsed build time: " << elapsed_seconds.count() << "s\n";
}
int main(int argc, char **argv) {
auto start = std::chrono::steady_clock::now();
// Test program and kernel APIs when building a kernel.
{
cl::sycl::queue q;
check_build_time<Inc>(q);

int data = 0;
{
cl::sycl::buffer<int, 1> buf(&data, cl::sycl::range<1>(1));
cl::sycl::range<1> NumOfWorkItems{buf.get_count()};

q.submit([&](cl::sycl::handler &cgh) {
auto acc = buf.get_access<cl::sycl::access::mode::read_write>(cgh);
cgh.parallel_for<class Inc>(
NumOfWorkItems, [=](cl::sycl::id<1> WIid) { TARGET_IMAGE(acc[0]) });
});
}
// check_build_time<Inc>(q);
auto end = std::chrono::steady_clock::now();
std::chrono::duration<double> elapsed_seconds = end - start;
std::cout << "elapsed kernel time: " << elapsed_seconds.count() << "s\n";
}
}
33 changes: 33 additions & 0 deletions SYCL/KernelAndProgram/cache_env_vars_lin.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// No JITing for host devices and diffrent environment variables on linux and
// windows.
// REQUIRES: (level_zero || opencl) && linux

// RUN: rm -rf %t/cache_dir
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out -DTARGET_IMAGE=INC100

// When no environment variables pointing cache directory are set the cache is
// disabled
// RUN: env SYCL_CACHE_PERSISTENT=1 env -u SYCL_CACHE_DIR env -u HOME env -u XDG_CACHE_HOME SYCL_PI_TRACE=-1 %t.out | FileCheck %s --check-prefixes=CHECK-BUILD
// RUN: env SYCL_CACHE_PERSISTENT=1 env -u SYCL_CACHE_DIR env -u HOME env -u XDG_CACHE_HOME SYCL_PI_TRACE=-1 %t.out | FileCheck %s --check-prefixes=CHECK-BUILD

// When any of environment variables pointing to cache root is present cache is
// enabled
// RUN: rm -rf %t/cache_dir
// RUN: env SYCL_CACHE_PERSISTENT=1 XDG_CACHE_HOME=%t/cache_dir SYCL_PI_TRACE=-1 env -u SYCL_CACHE_DIR env -u HOME %t.out | FileCheck %s --check-prefixes=CHECK-BUILD
// RUN: env SYCL_CACHE_PERSISTENT=1 XDG_CACHE_HOME=%t/cache_dir SYCL_PI_TRACE=-1 env -u SYCL_CACHE_DIR env -u HOME %t.out | FileCheck %s --check-prefixes=CHECK-CACHE
// RUN: rm -rf %t/cache_dir
// RUN: env SYCL_CACHE_PERSISTENT=1 SYCL_CACHE_DIR=%t/cache_dir SYCL_PI_TRACE=-1 env -u XDG_CACHE_HOME env -u HOME %t.out | FileCheck %s --check-prefixes=CHECK-BUILD
// RUN: env SYCL_CACHE_PERSISTENT=1 SYCL_CACHE_DIR=%t/cache_dir SYCL_PI_TRACE=-1 env -u XDG_CACHE_HOME env -u HOME %t.out %t.out | FileCheck %s --check-prefixes=CHECK-CACHE
// RUN: rm -rf %t/cache_dir
// RUN: env SYCL_CACHE_PERSISTENT=1 HOME=%t/cache_dir SYCL_PI_TRACE=-1 env -u XDG_CACHE_HOME env -u SYCL_CACHE_DIR %t.out | FileCheck %s --check-prefixes=CHECK-BUILD
// RUN: env SYCL_CACHE_PERSISTENT=1 HOME=%t/cache_dir SYCL_PI_TRACE=-1 env -u XDG_CACHE_HOME env -u SYCL_CACHE_DIR %t.out | FileCheck %s --check-prefixes=CHECK-CACHE

// CHECK-BUILD-NOT: piProgramCreateWithBinary(
// CHECK-BUILD: piProgramCreate(
// CHECK-BUILD: piProgramBuild(

// CHECK-CACHE-NOT: piProgramCreate(
// CHECK-CACHE: piProgramCreateWithBinary(
// CHECK-CACHE: piProgramBuild(

#include "cache_env_vars.hpp"
30 changes: 30 additions & 0 deletions SYCL/KernelAndProgram/cache_env_vars_win.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// No JITing for host devices and diffrent environment variables on linux and
// windows.
// REQUIRES: (level_zero || opencl) && windows

// RUN: rm -rf %t/cache_dir
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out -DTARGET_IMAGE=INC100

// When no environment variables pointing cache directory are set the cache is
// disabled
// RUN: env SYCL_CACHE_PERSISTENT=1 env -u SYCL_CACHE_DIR env -u AppData SYCL_PI_TRACE=-1 %t.out | FileCheck %s --check-prefixes=CHECK-BUILD
// RUN: env SYCL_CACHE_PERSISTENT=1 env -u SYCL_CACHE_DIR env -u AppData SYCL_PI_TRACE=-1 %t.out | FileCheck %s --check-prefixes=CHECK-BUILD

// When any of environment variables pointing to cache root is present cache is
// enabled
// RUN: rm -rf %t/cache_dir
// RUN: env SYCL_CACHE_PERSISTENT=1 SYCL_CACHE_DIR=%t/cache_dir SYCL_PI_TRACE=-1 env -u AppData %t.out | FileCheck %s --check-prefixes=CHECK-BUILD
// RUN: env SYCL_CACHE_PERSISTENT=1 SYCL_CACHE_DIR=%t/cache_dir SYCL_PI_TRACE=-1 env -u AppData %t.out %t.out | FileCheck %s --check-prefixes=CHECK-CACHE
// RUN: rm -rf %t/cache_dir
// RUN: env SYCL_CACHE_PERSISTENT=1 AppData=%t/cache_dir SYCL_PI_TRACE=-1 env -u SYCL_CACHE_DIR %t.out | FileCheck %s --check-prefixes=CHECK-BUILD
// RUN: env SYCL_CACHE_PERSISTENT=1 AppData=%t/cache_dir SYCL_PI_TRACE=-1 env -u SYCL_CACHE_DIR %t.out | FileCheck %s --check-prefixes=CHECK-CACHE

// CHECK-BUILD-NOT: piProgramCreateWithBinary(
// CHECK-BUILD: piProgramCreate(
// CHECK-BUILD: piProgramBuild(

// CHECK-CACHE-NOT: piProgramCreate(
// CHECK-CACHE: piProgramCreateWithBinary(
// CHECK-CACHE: piProgramBuild(

#include "cache_env_vars.hpp"