Add simple Tensor class

This commit is contained in:
2025-11-16 19:31:09 +01:00
parent 98ad4ac760
commit 64bf9197ff
3 changed files with 70 additions and 0 deletions

View File

@@ -0,0 +1,21 @@
#pragma once
#include <cstddef>
namespace CUDANet::Backend
{
class IBackend
{
public:
// Memory management
virtual void* allocate(size_t bytes) = 0;
virtual void deallocate(void* ptr) = 0;
virtual void copyToDevice(void* devicePtr, const void* hostPtr, size_t bytes) = 0;
virtual void copyToHost(void* hostPtr, const void* devicePtr, size_t bytes) = 0;
};
} // namespace CUDANet::Backend

View File

@@ -0,0 +1,38 @@
#pragma once
#include <cstddef>
#include "backend/backend.hpp"
#include <vector>
namespace CUDANet::Backend
{
enum class DType
{
FLOAT32,
// FLOAT16, // Not implemented yet
// INT32, // Not implemented yet
};
typedef std::vector<size_t> Shape;
class Tensor
{
public:
Tensor(Shape shape, DType dtype, IBackend* backend);
~Tensor();
void* allocate();
void deallocate();
void toDevice(const void* hostPtr);
void toHost(void* hostPtr);
private:
Shape shape;
DType dtype;
IBackend* backend;
void* devicePtr;
void* hostPtr;
};
} // namespace CUDANet::Backend