MCPcopy Create free account
hub / github.com/Tiiny-AI/PowerInfer / ggml_cl_transform_tensor

Function ggml_cl_transform_tensor

ggml-opencl.cpp:1872–1899  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1870}
1871
1872void ggml_cl_transform_tensor(void * data, ggml_tensor * tensor) {
1873 const int64_t ne0 = tensor->ne[0];
1874 const int64_t ne1 = tensor->ne[1];
1875 const int64_t ne2 = tensor->ne[2];
1876 const int64_t ne3 = tensor->ne[3];
1877
1878 const ggml_type type = tensor->type;
1879 const size_t s_sz = ggml_type_size(type) * (size_t) (ne0 * ne1 / ggml_blck_size(type));
1880 const size_t q_sz = s_sz * (size_t) (ne2 * ne3);
1881
1882 size_t q_size;
1883 cl_mem dst = ggml_cl_pool_malloc(q_sz, &q_size);
1884
1885 tensor->data = data;
1886 // copy tensor to device
1887 size_t offset = 0;
1888 for (int64_t i3 = 0; i3 < ne3; i3++) {
1889 for (int64_t i2 = 0; i2 < ne2; i2++) {
1890 CL_CHECK(ggml_cl_h2d_tensor_2d(queue, dst, offset, tensor, i3, i2, NULL));
1891 offset += s_sz;
1892 }
1893 }
1894
1895 CL_CHECK(clFinish(queue));
1896
1897 tensor->extra = dst;
1898 GGML_ASSERT(tensor->backend == GGML_BACKEND_GPU);
1899}

Callers 1

load_all_dataMethod · 0.85

Calls 4

ggml_cl_pool_mallocFunction · 0.85
ggml_cl_h2d_tensor_2dFunction · 0.85
ggml_type_sizeFunction · 0.70
ggml_blck_sizeFunction · 0.70

Tested by

no test coverage detected