File: compiler_cache.h

package info (click to toggle)
intel-compute-runtime 20.44.18297-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 34,780 kB
  • sloc: cpp: 379,729; lisp: 4,931; python: 299; sh: 196; makefile: 8
file content (47 lines) | stat: -rw-r--r-- 1,310 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
 * Copyright (C) 2017-2020 Intel Corporation
 *
 * SPDX-License-Identifier: MIT
 *
 */

#pragma once

#include "shared/source/utilities/arrayref.h"

#include <cstdint>
#include <cstring>
#include <memory>
#include <mutex>
#include <string>

namespace NEO {
struct HardwareInfo;

struct CompilerCacheConfig {
    bool enabled = true;
    std::string cacheFileExtension;
    std::string cacheDir;
};

class CompilerCache {
  public:
    static const std::string getCachedFileName(const HardwareInfo &hwInfo, ArrayRef<const char> input,
                                               ArrayRef<const char> options, ArrayRef<const char> internalOptions);

    CompilerCache(const CompilerCacheConfig &config);
    virtual ~CompilerCache() = default;

    CompilerCache(const CompilerCache &) = delete;
    CompilerCache(CompilerCache &&) = delete;
    CompilerCache &operator=(const CompilerCache &) = delete;
    CompilerCache &operator=(CompilerCache &&) = delete;

    MOCKABLE_VIRTUAL bool cacheBinary(const std::string kernelFileHash, const char *pBinary, uint32_t binarySize);
    MOCKABLE_VIRTUAL std::unique_ptr<char[]> loadCachedBinary(const std::string kernelFileHash, size_t &cachedBinarySize);

  protected:
    static std::mutex cacheAccessMtx;
    CompilerCacheConfig config;
};
} // namespace NEO