MCPcopy Create free account
hub / github.com/AnswerDotAI/gpu.cpp / createTensor

Function createTensor

gpu.hpp:575–594  ·  view source on GitHub ↗

* @brief Tensor factory function to create a tensor (a Tensor type is simply * an Array with an N-dimensional Shape specification) on the GPU. The tensor * is created with the given shape, data type, and usage flags, added to the * TensorPool, and returned. * * This is the core implementation which takes the minimal set of parameters in * terms of the raw WebGPU API, and is used by the othe

Source from the content-addressed store, hash-verified

573 * @endcode
574 */
575inline Tensor
576createTensor(TensorPool &pool, WGPUDevice &device, const Shape &shape,
577 NumType dtype,
578 WGPUBufferUsageFlags usage = WGPUBufferUsage_Storage |
579 WGPUBufferUsage_CopyDst |
580 WGPUBufferUsage_CopySrc) {
581 LOG(kDefLog, kTrace, "Creating tensor");
582 size_t numElements = size(shape);
583 size_t size = sizeBytes(dtype) * numElements;
584 WGPUBufferDescriptor bufferDesc = {
585 .usage = usage,
586 .size = size,
587 };
588 WGPUBuffer buffer = wgpuDeviceCreateBuffer(device, &bufferDesc);
589 pool.data[buffer] = Tensor{
590 .data = Array{.buffer = buffer, .usage = usage, .size = size},
591 .shape = shape,
592 };
593 return pool.data[buffer];
594}
595
596/**
597 * @brief Overload of the tensor factory function to instantiate a tensor on

Callers 15

runTestFunction · 0.85
puzzle1Function · 0.85
puzzle2Function · 0.85
puzzle3Function · 0.85
puzzle4Function · 0.85
puzzle5Function · 0.85
puzzle6Function · 0.85
puzzle7Function · 0.85
puzzle8Function · 0.85
puzzle9Function · 0.85
puzzle10Function · 0.85
puzzle11Function · 0.85

Calls 3

LOGFunction · 0.85
sizeFunction · 0.85
sizeBytesFunction · 0.85

Tested by 15

testResidualFunction · 0.68
testHadamardFunction · 0.68
testMatmulFunction · 0.68
testTensorPoolFunction · 0.68
testGeluFunction · 0.68
testLayerNormFunction · 0.68
testSoftmaxFunction · 0.68
ENCODER_FORWARD_GPUFunction · 0.68
ENCODER_BACKWARD_GPUFunction · 0.68
LAYERNORM_FORWARD_GPUFunction · 0.68
LAYERNORM_BACKWARD_GPUFunction · 0.68
MATMUL_FORWARD_GPUFunction · 0.68