Commit 1818b134 by Tianxing Wang

finish LRU cache

parents
.cache/
cmake-build-debug
\ No newline at end of file
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
<?xml version="1.0" encoding="UTF-8"?>
<module classpath="CMake" type="CPP_MODULE" version="4" />
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CMakeWorkspace" PROJECT_DIR="$PROJECT_DIR$" />
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/gpucache.iml" filepath="$PROJECT_DIR$/.idea/gpucache.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
cmake_minimum_required(VERSION 3.16)
project(gpucache CXX CUDA)
file(GLOB SOURCE_FILES
${CMAKE_CURRENT_SOURCE_DIR}/src/cuda/*
${CMAKE_CURRENT_SOURCE_DIR}/src/hash/*
${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/*.cu
)
message(STATUS "source files:" ${SOURCE_FILES})
add_library(gpucache SHARED ${SOURCE_FILES})
set_target_properties(gpucache PROPERTIES
CUDA_SEPARABLE_COMPILATION ON
CUDA_ARCHITECTURES "86"
)
#include "common.cuh"
namespace gpucache {
struct CacheConfig {
enum CacheEvictStrategy {
FIFO,
LRU,
LFU
};
CacheEvictStrategy strategy;
uint64_t capacity;
uint32_t keySize;
uint32_t valueSize;
uint32_t maxQueryNum;
};
// Cache Interface
template<typename KeyType, typename ElemType>
class Cache {
public:
// using Strategy = CacheConfig::CacheEvictStrategy;
Cache() = default;
virtual ~Cache() = default;
Cache(const Cache &) = delete;
Cache &operator=(const Cache &) = delete;
Cache(Cache &&) = delete;
Cache &operator=(Cache &&) = delete;
virtual uint32_t KeySize() = 0;
virtual uint32_t ValueSize() = 0;
virtual CacheConfig::CacheEvictStrategy Strategy() = 0;
virtual uint64_t Capacity() = 0;
virtual uint32_t NumElemsPerValue() = 0;
virtual void Get(cudaStream_t *stream, uint32_t num_keys, KeyType *keys, ElemType *values) = 0;
virtual void Put(cudaStream_t *stream, uint32_t num_keys, KeyType *keys, ElemType *values) = 0;
virtual void Clear() = 0;
virtual uint32_t MaxQueryNum() = 0;
};
// TODO: 添加其他种类的cache
template<typename KeyType, typename ValueType>
std::unique_ptr<Cache<KeyType, ValueType>> NewCache(const CacheConfig &cfg) {
assert(cfg.keySize > 0);
assert(cfg.valueSize > 0);
assert(cfg.capacity > 0);
return nullptr;
}
}
#pragma once
#include <cstdint>
#include <cuda_runtime.h>
#include <memory>
#include <cassert>
#include <cstdio>
#define CHECK(call) \
{ \
const cudaError_t error = call; \
if (error != cudaSuccess) \
{ \
fprintf(stderr, "Error: %s:%d, ", __FILE__, __LINE__); \
fprintf(stderr, "code: %d, reason: %s\n", error, \
cudaGetErrorString(error)); \
} \
}
#include <cuda_runtime.h>
#include <iostream>
/*
* different
*/
#ifndef GPUCACHE_HASH_FUCNTION_H
#define GPUCACHE_HASH_FUCNTION_H
#include <string>
template<typename T>
class HashFunc;
template<typename T>
class DefaultHashFunc;
template<typename T>
void getHash(const T& obj, std::string type="default"){
if (type == "default") {
return DefaultHashFunc<T>()(obj);
}
}
#endif //GPUCACHE_HASH_FUCNTION_H
#include <functional>
template<typename T>
class HashFunc {
public:
virtual std::size_t operator()(T &obj) = 0;
};
template<typename T>
class DefaultHashFunc : public HashFunc<T> {
virtual std::size_t operator()(T &obj){
return std::hash<T>()(obj);
}
};
#include <cuda_runtime.h>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment