# \donttest{
if (ggml_vulkan_available() && ggml_vulkan_device_count() >= 4) {
K <- 64L
W1 <- matrix(rnorm(K * K), K); W2 <- matrix(rnorm(K * K), K)
make_stages <- function(devices, m) {
mk <- function(dev, Wt, relu) list(
device = dev, in_shape = c(K, m),
build = function(ctx, input) {
w <- ggml_new_tensor_2d(ctx, GGML_TYPE_F32, K, K)
z <- ggml_mul_mat(ctx, w, input)
list(output = if (relu) ggml_relu(ctx, z) else z,
set_weights = function() ggml_backend_tensor_set_data(w, as.numeric(Wt)))
})
list(mk(devices[1], W1, TRUE), mk(devices[2], W2, FALSE))
}
X <- matrix(rnorm(8 * K), nrow = 8) # batch of 8
Y <- ggml_pp_dp_forward(make_stages, X, replicas = list(c(0, 1), c(2, 3)),
out_ncol = K)
}
# }
Run the code above in your browser using DataLab