/
card.r
112 lines (85 loc) · 2.1 KB
/
card.r
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#' card class
#'
#' Storage and methods for GPU card data.
#'
#' @details
#' Data is held in an external pointer.
#'
#' @rdname gpu-card-class
#' @name gpu-card-class
cardR6 = R6::R6Class("card",
public = list(
#' @details
#' Class initializer.
#' @param id GPU id number.
#' @useDynLib fmlr R_card_init
initialize = function(id=0)
{
id = as.integer(id)
private$c_ptr = .Call(R_card_init, id)
},
#' @details
#' Set card to a different GPU.
#' @param id GPU id number.
#' @useDynLib fmlr R_card_set
set = function(id)
{
id = as.integer(id)
.Call(R_card_set, private$c_ptr, id)
invisible(self)
},
#' @details
#' Synchronizes the GPU, i.e. blocks further GPU execution until the device
#' completes all previously executed kernels.
#' @useDynLib fmlr R_card_synch
synch = function()
{
.Call(R_card_synch, private$c_ptr)
invisible(self)
},
#' @details
#' Print one-line information about the object.
#' @useDynLib fmlr R_card_info
info = function()
{
.Call(R_card_info, private$c_ptr)
invisible(self)
},
#' @details
#' Print one-line information about the object.
print = function()
{
self$info()
invisible(self)
},
#' @details
#' Returns GPU id number.
#' @useDynLib fmlr R_card_get_id
get_id = function() .Call(R_card_get_id, private$c_ptr),
#' @details
#' Returns whether or not the card object is valid.
#' @useDynLib fmlr R_card_valid_card
valid_card = function() .Call(R_card_valid_card, private$c_ptr),
#' @details
#' Returns the external pointer data. For developers only.
data_ptr = function() private$c_ptr
),
private = list(
c_ptr = NULL
)
)
#' card
#'
#' Constructor for GPU card objects.
#'
#' @details
#' Data is held in an external pointer.
#'
#' @param id GPU id number.
#' @return A card class object.
#'
#' @export
card = function(id=0)
{
cardR6$new(id=id)
}