Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/jcl/src/openj9.cuda/share/classes/com/ibm/cuda/CudaDevice.java
12927 views
1
/*[INCLUDE-IF Sidecar18-SE]*/
2
/*******************************************************************************
3
* Copyright (c) 2013, 2021 IBM Corp. and others
4
*
5
* This program and the accompanying materials are made available under
6
* the terms of the Eclipse Public License 2.0 which accompanies this
7
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
8
* or the Apache License, Version 2.0 which accompanies this distribution and
9
* is available at https://www.apache.org/licenses/LICENSE-2.0.
10
*
11
* This Source Code may also be made available under the following
12
* Secondary Licenses when the conditions for such availability set
13
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
14
* General Public License, version 2 with the GNU Classpath
15
* Exception [1] and GNU General Public License, version 2 with the
16
* OpenJDK Assembly Exception [2].
17
*
18
* [1] https://www.gnu.org/software/classpath/license.html
19
* [2] http://openjdk.java.net/legal/assembly-exception.html
20
*
21
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception
22
*******************************************************************************/
23
package com.ibm.cuda;
24
25
import java.util.Objects;
26
27
/**
28
* The {@code CudaDevice} class represents a CUDA-capable device.
29
*/
30
public final class CudaDevice {
31
32
/**
33
* {@code CacheConfig} identifies the cache configuration choices for
34
* a device.
35
*/
36
public static enum CacheConfig {
37
38
/** prefer equal sized L1 cache and shared memory */
39
PREFER_EQUAL(0),
40
41
/** prefer larger L1 cache and smaller shared memory */
42
PREFER_L1(1),
43
44
/** no preference for shared memory or L1 (default) */
45
PREFER_NONE(2),
46
47
/** prefer larger shared memory and smaller L1 cache */
48
PREFER_SHARED(3);
49
50
final int nativeValue;
51
52
CacheConfig(int value) {
53
this.nativeValue = value;
54
}
55
}
56
57
/**
58
* {@code Limit} identifies device limits that may be queried or configured.
59
*/
60
public static enum Limit {
61
62
/** maximum number of outstanding device runtime launches that can be made from this context */
63
DEV_RUNTIME_PENDING_LAUNCH_COUNT(0),
64
65
/** maximum grid depth at which a thread can issue the device runtime call ::cudaDeviceSynchronize() to wait on child grid launches to complete */
66
DEV_RUNTIME_SYNC_DEPTH(1),
67
68
/** size in bytes of the heap used by the ::malloc() and ::free() device system calls */
69
MALLOC_HEAP_SIZE(2),
70
71
/** size in bytes of the FIFO used by the ::printf() device system call */
72
PRINTF_FIFO_SIZE(3),
73
74
/** stack size in bytes of each GPU thread */
75
STACK_SIZE(4);
76
77
final int nativeValue;
78
79
private Limit(int value) {
80
this.nativeValue = value;
81
}
82
}
83
84
public static enum SharedMemConfig {
85
86
/**
87
* default shared memory bank size
88
*/
89
DEFAULT_BANK_SIZE(0),
90
91
/**
92
* eight byte shared memory bank width
93
*/
94
EIGHT_BYTE_BANK_SIZE(2),
95
96
/**
97
* four byte shared memory bank width
98
*/
99
FOUR_BYTE_BANK_SIZE(1);
100
101
final int nativeValue;
102
103
SharedMemConfig(int value) {
104
this.nativeValue = value;
105
}
106
}
107
108
/** Number of asynchronous engines. */
109
public static final int ATTRIBUTE_ASYNC_ENGINE_COUNT = 40;
110
111
/** Device can map host memory into CUDA address space. */
112
public static final int ATTRIBUTE_CAN_MAP_HOST_MEMORY = 19;
113
114
/** Typical clock frequency in kilohertz. */
115
public static final int ATTRIBUTE_CLOCK_RATE = 13;
116
117
/**
118
* Compute capability version number. This value is the major compute
119
* capability version * 10 + the minor compute capability version, so
120
* a compute capability version 3.5 function would return the value 35.
121
*/
122
public static final int ATTRIBUTE_COMPUTE_CAPABILITY = -1;
123
124
/** Major compute capability version number. */
125
public static final int ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR = 75;
126
127
/** Minor compute capability version number. */
128
public static final int ATTRIBUTE_COMPUTE_CAPABILITY_MINOR = 76;
129
130
/** Compute mode (see COMPUTE_MODE_XXX for details). */
131
public static final int ATTRIBUTE_COMPUTE_MODE = 20;
132
133
/** Device can possibly execute multiple kernels concurrently. */
134
public static final int ATTRIBUTE_CONCURRENT_KERNELS = 31;
135
136
/** Device has ECC support enabled. */
137
public static final int ATTRIBUTE_ECC_ENABLED = 32;
138
139
/** Global memory bus width in bits. */
140
public static final int ATTRIBUTE_GLOBAL_MEMORY_BUS_WIDTH = 37;
141
142
/** Device is integrated with host memory. */
143
public static final int ATTRIBUTE_INTEGRATED = 18;
144
145
/** Specifies whether there is a run time limit on kernels. */
146
public static final int ATTRIBUTE_KERNEL_EXEC_TIMEOUT = 17;
147
148
/** Size of L2 cache in bytes. */
149
public static final int ATTRIBUTE_L2_CACHE_SIZE = 38;
150
151
/** Maximum block dimension X. */
152
public static final int ATTRIBUTE_MAX_BLOCK_DIM_X = 2;
153
154
/** Maximum block dimension Y. */
155
public static final int ATTRIBUTE_MAX_BLOCK_DIM_Y = 3;
156
157
/** Maximum block dimension Z. */
158
public static final int ATTRIBUTE_MAX_BLOCK_DIM_Z = 4;
159
160
/** Maximum grid dimension X. */
161
public static final int ATTRIBUTE_MAX_GRID_DIM_X = 5;
162
163
/** Maximum grid dimension Y. */
164
public static final int ATTRIBUTE_MAX_GRID_DIM_Y = 6;
165
166
/** Maximum grid dimension Z. */
167
public static final int ATTRIBUTE_MAX_GRID_DIM_Z = 7;
168
169
/** Maximum pitch in bytes allowed by memory copies. */
170
public static final int ATTRIBUTE_MAX_PITCH = 11;
171
172
/** Maximum number of 32-bit registers available per block. */
173
public static final int ATTRIBUTE_MAX_REGISTERS_PER_BLOCK = 12;
174
175
/** Maximum shared memory available per block in bytes. */
176
public static final int ATTRIBUTE_MAX_SHARED_MEMORY_PER_BLOCK = 8;
177
178
/** Maximum number of threads per block. */
179
public static final int ATTRIBUTE_MAX_THREADS_PER_BLOCK = 1;
180
181
/** Maximum resident threads per multiprocessor. */
182
public static final int ATTRIBUTE_MAX_THREADS_PER_MULTIPROCESSOR = 39;
183
184
/** Maximum layers in a 1D layered surface. */
185
public static final int ATTRIBUTE_MAXIMUM_SURFACE1D_LAYERED_LAYERS = 62;
186
187
/** Maximum 1D layered surface width. */
188
public static final int ATTRIBUTE_MAXIMUM_SURFACE1D_LAYERED_WIDTH = 61;
189
190
/** Maximum 1D surface width. */
191
public static final int ATTRIBUTE_MAXIMUM_SURFACE1D_WIDTH = 55;
192
193
/** Maximum 2D surface height. */
194
public static final int ATTRIBUTE_MAXIMUM_SURFACE2D_HEIGHT = 57;
195
196
/** Maximum 2D layered surface height. */
197
public static final int ATTRIBUTE_MAXIMUM_SURFACE2D_LAYERED_HEIGHT = 64;
198
199
/** Maximum layers in a 2D layered surface. */
200
public static final int ATTRIBUTE_MAXIMUM_SURFACE2D_LAYERED_LAYERS = 65;
201
202
/** Maximum 2D layered surface width. */
203
public static final int ATTRIBUTE_MAXIMUM_SURFACE2D_LAYERED_WIDTH = 63;
204
205
/** Maximum 2D surface width. */
206
public static final int ATTRIBUTE_MAXIMUM_SURFACE2D_WIDTH = 56;
207
208
/** Maximum 3D surface depth. */
209
public static final int ATTRIBUTE_MAXIMUM_SURFACE3D_DEPTH = 60;
210
211
/** Maximum 3D surface height. */
212
public static final int ATTRIBUTE_MAXIMUM_SURFACE3D_HEIGHT = 59;
213
214
/** Maximum 3D surface width. */
215
public static final int ATTRIBUTE_MAXIMUM_SURFACE3D_WIDTH = 58;
216
217
/** Maximum layers in a cubemap layered surface. */
218
public static final int ATTRIBUTE_MAXIMUM_SURFACECUBEMAP_LAYERED_LAYERS = 68;
219
220
/** Maximum cubemap layered surface width. */
221
public static final int ATTRIBUTE_MAXIMUM_SURFACECUBEMAP_LAYERED_WIDTH = 67;
222
223
/** Maximum cubemap surface width. */
224
public static final int ATTRIBUTE_MAXIMUM_SURFACECUBEMAP_WIDTH = 66;
225
226
/** Maximum layers in a 1D layered texture. */
227
public static final int ATTRIBUTE_MAXIMUM_TEXTURE1D_LAYERED_LAYERS = 43;
228
229
/** Maximum 1D layered texture width. */
230
public static final int ATTRIBUTE_MAXIMUM_TEXTURE1D_LAYERED_WIDTH = 42;
231
232
/** Maximum 1D linear texture width. */
233
public static final int ATTRIBUTE_MAXIMUM_TEXTURE1D_LINEAR_WIDTH = 69;
234
235
/** Maximum mipmapped 1D texture width. */
236
public static final int ATTRIBUTE_MAXIMUM_TEXTURE1D_MIPMAPPED_WIDTH = 77;
237
238
/** Maximum 1D texture width. */
239
public static final int ATTRIBUTE_MAXIMUM_TEXTURE1D_WIDTH = 21;
240
241
/** Maximum 2D texture height if CUDA_ARRAY3D_TEXTURE_GATHER is set. */
242
public static final int ATTRIBUTE_MAXIMUM_TEXTURE2D_GATHER_HEIGHT = 46;
243
244
/** Maximum 2D texture width if CUDA_ARRAY3D_TEXTURE_GATHER is set. */
245
public static final int ATTRIBUTE_MAXIMUM_TEXTURE2D_GATHER_WIDTH = 45;
246
247
/** Maximum 2D texture height. */
248
public static final int ATTRIBUTE_MAXIMUM_TEXTURE2D_HEIGHT = 23;
249
250
/** Maximum 2D layered texture height. */
251
public static final int ATTRIBUTE_MAXIMUM_TEXTURE2D_LAYERED_HEIGHT = 28;
252
253
/** Maximum layers in a 2D layered texture. */
254
public static final int ATTRIBUTE_MAXIMUM_TEXTURE2D_LAYERED_LAYERS = 29;
255
256
/** Maximum 2D layered texture width. */
257
public static final int ATTRIBUTE_MAXIMUM_TEXTURE2D_LAYERED_WIDTH = 27;
258
259
/** Maximum 2D linear texture height. */
260
public static final int ATTRIBUTE_MAXIMUM_TEXTURE2D_LINEAR_HEIGHT = 71;
261
262
/** Maximum 2D linear texture pitch in bytes. */
263
public static final int ATTRIBUTE_MAXIMUM_TEXTURE2D_LINEAR_PITCH = 72;
264
265
/** Maximum 2D linear texture width. */
266
public static final int ATTRIBUTE_MAXIMUM_TEXTURE2D_LINEAR_WIDTH = 70;
267
268
/** Maximum mipmapped 2D texture height. */
269
public static final int ATTRIBUTE_MAXIMUM_TEXTURE2D_MIPMAPPED_HEIGHT = 74;
270
271
/** Maximum mipmapped 2D texture width. */
272
public static final int ATTRIBUTE_MAXIMUM_TEXTURE2D_MIPMAPPED_WIDTH = 73;
273
274
/** Maximum 2D texture width. */
275
public static final int ATTRIBUTE_MAXIMUM_TEXTURE2D_WIDTH = 22;
276
277
/** Maximum 3D texture depth. */
278
public static final int ATTRIBUTE_MAXIMUM_TEXTURE3D_DEPTH = 26;
279
280
/** Alternate maximum 3D texture depth. */
281
public static final int ATTRIBUTE_MAXIMUM_TEXTURE3D_DEPTH_ALTERNATE = 49;
282
283
/** Maximum 3D texture height. */
284
public static final int ATTRIBUTE_MAXIMUM_TEXTURE3D_HEIGHT = 25;
285
286
/** Alternate maximum 3D texture height. */
287
public static final int ATTRIBUTE_MAXIMUM_TEXTURE3D_HEIGHT_ALTERNATE = 48;
288
289
/** Maximum 3D texture width. */
290
public static final int ATTRIBUTE_MAXIMUM_TEXTURE3D_WIDTH = 24;
291
292
/** Alternate maximum 3D texture width. */
293
public static final int ATTRIBUTE_MAXIMUM_TEXTURE3D_WIDTH_ALTERNATE = 47;
294
295
/** Maximum layers in a cubemap layered texture. */
296
public static final int ATTRIBUTE_MAXIMUM_TEXTURECUBEMAP_LAYERED_LAYERS = 54;
297
298
/** Maximum cubemap layered texture width/height. */
299
public static final int ATTRIBUTE_MAXIMUM_TEXTURECUBEMAP_LAYERED_WIDTH = 53;
300
301
/** Maximum cubemap texture width/height. */
302
public static final int ATTRIBUTE_MAXIMUM_TEXTURECUBEMAP_WIDTH = 52;
303
304
/** Peak memory clock frequency in kilohertz. */
305
public static final int ATTRIBUTE_MEMORY_CLOCK_RATE = 36;
306
307
/** Number of multiprocessors on device. */
308
public static final int ATTRIBUTE_MULTIPROCESSOR_COUNT = 16;
309
310
/** PCI bus ID of the device. */
311
public static final int ATTRIBUTE_PCI_BUS_ID = 33;
312
313
/** PCI device ID of the device. */
314
public static final int ATTRIBUTE_PCI_DEVICE_ID = 34;
315
316
/** PCI domain ID of the device. */
317
public static final int ATTRIBUTE_PCI_DOMAIN_ID = 50;
318
319
/** Device supports stream priorities. */
320
public static final int ATTRIBUTE_STREAM_PRIORITIES_SUPPORTED = 78;
321
322
/** Alignment requirement for surfaces. */
323
public static final int ATTRIBUTE_SURFACE_ALIGNMENT = 30;
324
325
/** Device is using TCC driver model. */
326
public static final int ATTRIBUTE_TCC_DRIVER = 35;
327
328
/** Alignment requirement for textures. */
329
public static final int ATTRIBUTE_TEXTURE_ALIGNMENT = 14;
330
331
/** Pitch alignment requirement for textures. */
332
public static final int ATTRIBUTE_TEXTURE_PITCH_ALIGNMENT = 51;
333
334
/** Memory available on device for __constant__ variables in a kernel in bytes. */
335
public static final int ATTRIBUTE_TOTAL_CONSTANT_MEMORY = 9;
336
337
/** Device shares a unified address space with the host. */
338
public static final int ATTRIBUTE_UNIFIED_ADDRESSING = 41;
339
340
/** Warp size in threads. */
341
public static final int ATTRIBUTE_WARP_SIZE = 10;
342
343
/** Default compute mode (multiple contexts allowed per device). */
344
public static final int COMPUTE_MODE_DEFAULT = 0;
345
346
/**
347
* Compute exclusive process mode (at most one context used by a single process
348
* can be present on this device at a time).
349
*/
350
public static final int COMPUTE_MODE_PROCESS_EXCLUSIVE = 3;
351
352
/** Compute prohibited mode (no contexts can be created on this device at this time). */
353
public static final int COMPUTE_MODE_PROHIBITED = 2;
354
355
/**
356
* Exclusive thread mode (at most one context, used by a single thread,
357
* can be present on this device at a time).
358
*/
359
public static final int COMPUTE_MODE_THREAD_EXCLUSIVE = 1;
360
361
/** Keep local memory allocation after launch. */
362
public static final int FLAG_LMEM_RESIZE_TO_MAX = 0x10;
363
364
/** Support mapped pinned allocations. */
365
public static final int FLAG_MAP_HOST = 0x08;
366
367
/** Automatic scheduling. */
368
public static final int FLAG_SCHED_AUTO = 0x00;
369
370
/** Set blocking synchronization as default scheduling. */
371
public static final int FLAG_SCHED_BLOCKING_SYNC = 0x04;
372
373
/** Set spin as default scheduling. */
374
public static final int FLAG_SCHED_SPIN = 0x01;
375
376
/** Set yield as default scheduling. */
377
public static final int FLAG_SCHED_YIELD = 0x02;
378
379
public static final int MASK_SCHED = 0x07;
380
381
static native void addCallback(int deviceId, long streamHandle,
382
Runnable callback) throws CudaException;
383
384
private static native boolean canAccessPeer(int deviceId, int peerDeviceId)
385
throws CudaException;
386
387
private static native void disablePeerAccess(int deviceId, int peerDeviceId)
388
throws CudaException;
389
390
private static native void enablePeerAccess(int deviceId, int peerDeviceId)
391
throws CudaException;
392
393
private static native int getAttribute(int deviceId, int attribute)
394
throws CudaException;
395
396
private static native int getCacheConfig(int deviceId) throws CudaException;
397
398
/**
399
* Returns the number of CUDA-capable devices available to the Java host.
400
*
401
* @return the number of available CUDA-capable devices
402
* @throws CudaException
403
* if a CUDA exception occurs
404
*/
405
public static int getCount() throws CudaException {
406
return Cuda.getDeviceCount();
407
}
408
409
/**
410
* Returns a number identifying the driver version.
411
*
412
* @return
413
* the driver version number
414
* @throws CudaException
415
* if a CUDA exception occurs
416
* @deprecated
417
* Use Cuda.getDriverVersion() instead.
418
*/
419
@Deprecated
420
public static int getDriverVersion() throws CudaException {
421
return Cuda.getDriverVersion();
422
}
423
424
private static native long getFreeMemory(int deviceId) throws CudaException;
425
426
private static native int getGreatestStreamPriority(int deviceId)
427
throws CudaException;
428
429
private static native int getLeastStreamPriority(int deviceId)
430
throws CudaException;
431
432
private static native long getLimit(int deviceId, int limit)
433
throws CudaException;
434
435
private static native String getName(int deviceId) throws CudaException;
436
437
/**
438
* Returns a number identifying the runtime version.
439
*
440
* @return
441
* the runtime version number
442
* @throws CudaException
443
* if a CUDA exception occurs
444
* @deprecated
445
* Use Cuda.getRuntimeVersion() instead.
446
*/
447
@Deprecated
448
public static int getRuntimeVersion() throws CudaException {
449
return Cuda.getRuntimeVersion();
450
}
451
452
private static native int getSharedMemConfig(int deviceId)
453
throws CudaException;
454
455
private static native long getTotalMemory(int deviceId)
456
throws CudaException;
457
458
private static native void setCacheConfig(int deviceId, int config)
459
throws CudaException;
460
461
private static native void setLimit(int deviceId, int limit, long value)
462
throws CudaException;
463
464
private static native void setSharedMemConfig(int deviceId, int config)
465
throws CudaException;
466
467
private static native void synchronize(int deviceId) throws CudaException;
468
469
private final int deviceId;
470
471
/**
472
* Creates a device handle corresponding to {@code deviceId}.
473
* <p>
474
* No checking is done on {@code deviceId}, but it must be non-negative
475
* and less than the value returned {@link #getCount()} to be useful.
476
*
477
* @param deviceId
478
* an integer identifying the device of interest
479
*/
480
public CudaDevice(int deviceId) {
481
super();
482
this.deviceId = deviceId;
483
Cuda.loadNatives();
484
}
485
486
/**
487
* Queues the given {@code callback} to be executed when the associated
488
* device has completed all previous actions in the default stream.
489
*
490
* @param callback
491
* code to run
492
* @throws CudaException
493
* if a CUDA exception occurs
494
*/
495
public void addCallback(Runnable callback) throws CudaException {
496
Objects.requireNonNull(callback);
497
addCallback(deviceId, 0, callback);
498
}
499
500
/**
501
* Returns whether this device can access memory of the specified
502
* {@code peerDevice}.
503
*
504
* @param peerDevice
505
* the peer device
506
* @return
507
* true if this device can access memory of {@code peerDevice},
508
* false otherwise
509
* @throws CudaException
510
* if a CUDA exception occurs
511
*/
512
public boolean canAccessPeer(CudaDevice peerDevice) throws CudaException {
513
return canAccessPeer(deviceId, peerDevice.deviceId);
514
}
515
516
/**
517
* Disable access to memory of {@code peerDevice} by this device.
518
*
519
* @param peerDevice
520
* the peer device
521
* @throws CudaException
522
* if a CUDA exception occurs
523
* @throws SecurityException
524
* if a security manager exists and the calling thread
525
* does not have permission to disable peer access
526
*/
527
public void disablePeerAccess(CudaDevice peerDevice) throws CudaException {
528
@SuppressWarnings("removal")
529
SecurityManager security = System.getSecurityManager();
530
531
if (security != null) {
532
security.checkPermission(CudaPermission.DisablePeerAccess);
533
}
534
535
disablePeerAccess(deviceId, peerDevice.deviceId);
536
}
537
538
/**
539
* Enable access to memory of {@code peerDevice} by this device.
540
*
541
* @param peerDevice
542
* the peer device
543
* @throws CudaException
544
* if a CUDA exception occurs
545
* @throws SecurityException
546
* if a security manager exists and the calling thread
547
* does not have permission to enable peer access
548
*/
549
public void enablePeerAccess(CudaDevice peerDevice) throws CudaException {
550
@SuppressWarnings("removal")
551
SecurityManager security = System.getSecurityManager();
552
553
if (security != null) {
554
security.checkPermission(CudaPermission.EnablePeerAccess);
555
}
556
557
enablePeerAccess(deviceId, peerDevice.deviceId);
558
}
559
560
/**
561
* Does the argument represent the same device as this?
562
*/
563
@Override
564
public boolean equals(Object other) {
565
if (this == other) {
566
return true;
567
}
568
569
if (other instanceof CudaDevice) {
570
CudaDevice that = (CudaDevice) other;
571
572
if (this.deviceId == that.deviceId) {
573
return true;
574
}
575
}
576
577
return false;
578
}
579
580
/**
581
* Returns the value of the specified {@code attribute}.
582
*
583
* @param attribute
584
* the attribute to be queried (see ATTRIBUTE_XXX)
585
* @return
586
* the attribute value
587
* @throws CudaException
588
* if a CUDA exception occurs
589
*/
590
public int getAttribute(int attribute) throws CudaException {
591
return getAttribute(deviceId, attribute);
592
}
593
594
/**
595
* Returns the current cache configuration of this device.
596
*
597
* @return
598
* the current cache configuration
599
* @throws CudaException
600
* if a CUDA exception occurs
601
*/
602
public CacheConfig getCacheConfig() throws CudaException {
603
switch (getCacheConfig(deviceId)) {
604
default:
605
case 0:
606
return CacheConfig.PREFER_NONE;
607
case 1:
608
return CacheConfig.PREFER_SHARED;
609
case 2:
610
return CacheConfig.PREFER_L1;
611
case 3:
612
return CacheConfig.PREFER_EQUAL;
613
}
614
}
615
616
/**
617
* Returns an integer identifying this device (the value provided when
618
* this object was constructed).
619
*
620
* @return an integer identifying this device
621
*/
622
public int getDeviceId() {
623
return deviceId;
624
}
625
626
/**
627
* Returns the amount of free device memory in bytes.
628
*
629
* @return
630
* the number of bytes of free device memory
631
* @throws CudaException
632
* if a CUDA exception occurs
633
*/
634
public long getFreeMemory() throws CudaException {
635
return getFreeMemory(deviceId);
636
}
637
638
/**
639
* Returns the greatest possible priority of a stream on this device.
640
* Note that stream priorities follow a convention where lower numbers imply
641
* greater priorities.
642
*
643
* @return
644
* the greatest possible priority of a stream on this device
645
* @throws CudaException
646
* if a CUDA exception occurs
647
*/
648
public int getGreatestStreamPriority() throws CudaException {
649
return getGreatestStreamPriority(deviceId);
650
}
651
652
/**
653
* Returns the least possible priority of a stream on this device.
654
* Note that stream priorities follow a convention where lower numbers imply
655
* greater priorities.
656
*
657
* @return
658
* the greatest possible priority of a stream on this device
659
* @throws CudaException
660
* if a CUDA exception occurs
661
*/
662
public int getLeastStreamPriority() throws CudaException {
663
return getLeastStreamPriority(deviceId);
664
}
665
666
/**
667
* Returns the value of the specified {@code limit}.
668
*
669
* @param limit
670
* the limit to be queried
671
* @return
672
* the value of the specified limit
673
* @throws CudaException
674
* if a CUDA exception occurs
675
*/
676
public long getLimit(Limit limit) throws CudaException {
677
return getLimit(deviceId, limit.nativeValue);
678
}
679
680
/**
681
* Returns the name of this device.
682
*
683
* @return
684
* the name of this device
685
* @throws CudaException
686
* if a CUDA exception occurs
687
*/
688
public String getName() throws CudaException {
689
return getName(deviceId);
690
}
691
692
/**
693
* Returns the current shared memory configuration of this device.
694
*
695
* @return
696
* the current shared memory configuration
697
* @throws CudaException
698
* if a CUDA exception occurs
699
*/
700
public SharedMemConfig getSharedMemConfig() throws CudaException {
701
switch (getSharedMemConfig(deviceId)) {
702
default:
703
case 0:
704
return SharedMemConfig.DEFAULT_BANK_SIZE;
705
case 1:
706
return SharedMemConfig.FOUR_BYTE_BANK_SIZE;
707
case 2:
708
return SharedMemConfig.EIGHT_BYTE_BANK_SIZE;
709
}
710
}
711
712
/**
713
* Returns the total amount of memory on this device in bytes.
714
*
715
* @return
716
* the number of bytes of device memory
717
* @throws CudaException
718
* if a CUDA exception occurs
719
*/
720
public long getTotalMemory() throws CudaException {
721
return getTotalMemory(deviceId);
722
}
723
724
@Override
725
public int hashCode() {
726
return deviceId;
727
}
728
729
/**
730
* Configures the cache of this device.
731
*
732
* @param config
733
* the desired cache configuration
734
* @throws CudaException
735
* if a CUDA exception occurs
736
* @throws SecurityException
737
* if a security manager exists and the calling thread
738
* does not have permission to set device cache configurations
739
*/
740
public void setCacheConfig(CacheConfig config) throws CudaException {
741
@SuppressWarnings("removal")
742
SecurityManager security = System.getSecurityManager();
743
744
if (security != null) {
745
security.checkPermission(CudaPermission.SetCacheConfig);
746
}
747
748
setCacheConfig(deviceId, config.nativeValue);
749
}
750
751
/**
752
* Configures the specified {@code limit}.
753
*
754
* @param limit
755
* the limit to be configured
756
* @param value
757
* the desired limit value
758
* @throws CudaException
759
* if a CUDA exception occurs
760
* @throws SecurityException
761
* if a security manager exists and the calling thread
762
* does not have permission to set device limits
763
*/
764
public void setLimit(Limit limit, long value) throws CudaException {
765
@SuppressWarnings("removal")
766
SecurityManager security = System.getSecurityManager();
767
768
if (security != null) {
769
security.checkPermission(CudaPermission.SetLimit);
770
}
771
772
setLimit(deviceId, limit.nativeValue, value);
773
}
774
775
/**
776
* Configures the shared memory of this device.
777
*
778
* @param config
779
* the desired shared memory configuration
780
* @throws CudaException
781
* if a CUDA exception occurs
782
* @throws SecurityException
783
* if a security manager exists and the calling thread does
784
* not have permission to set device shared memory configurations
785
*/
786
public void setSharedMemConfig(SharedMemConfig config) throws CudaException {
787
@SuppressWarnings("removal")
788
SecurityManager security = System.getSecurityManager();
789
790
if (security != null) {
791
security.checkPermission(CudaPermission.SetSharedMemConfig);
792
}
793
794
setSharedMemConfig(deviceId, config.nativeValue);
795
}
796
797
/**
798
* Synchronizes on this device. This method blocks until the associated
799
* device has completed all previous actions in the default stream.
800
*
801
* @throws CudaException
802
* if a CUDA exception occurs
803
*/
804
public void synchronize() throws CudaException {
805
synchronize(deviceId);
806
}
807
}
808
809