forked from hyc/wolf-xmr-miner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ocl.h
78 lines (68 loc) · 2.63 KB
/
ocl.h
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
#ifndef __OCL_H
#define __OCL_H
#include <CL/cl.h>
#include <stdint.h>
// An OCLDevice structure contains information specific to one device,
// necessary for using it for any sort of work. How many command queues
// there are and their properties go in here - the properties of a given
// command queue likely influenced by the work that will be running on it.
// One device may have multiple command queues, and may execute different
// hash algos concurrently. Each hash algo being executed will get a
// command queue - but that won't be stored here; each hash algo will
// create at least one command queue, more if it requires them.
typedef struct _OCLDevice
{
char *DeviceName;
double OCLVersion;
cl_uint TotalShaders;
cl_uint ComputeUnits;
cl_device_id DeviceID;
size_t MaximumWorkSize;
size_t rawIntensity;
size_t WorkSize;
} OCLDevice;
// An OCLPlatform structure contains information necessary to
// interact with a subset of devices in one platform. It may
// only be associated with one platform, but it MAY have
// multiple devices. This allows for simpler management,
// having one cl_context for any number of devices, and
// allows freedom in choosing how to split them up, if you
// choose to do so.
typedef struct _OCLPlatform
{
cl_context Context;
cl_platform_id Platform;
OCLDevice *Devices;
uint32_t NumDevices;
} OCLPlatform;
// A AlgoContext structure contains information specific to one algo,
// necessary for executing the hash algorithm. How many extra command queues
// there are, their properties, what Program is loaded with, and the number
// of kernels and their arguments all depend on the hash, giving it
// flexibility in execution.
// Most hashes will require an input buffer, all will require an output
// buffer. There may be additional buffers required; this is hash-specific.
// Additional buffers can therefore be created using ExtraBuffers member,
// which must be freed in the hash-specific cleanup function.
typedef struct _AlgoContext
{
cl_command_queue *CommandQueues;
cl_mem InputBuffer;
cl_mem OutputBuffer;
int32_t (*SetKernelArgs)(struct _AlgoContext *, void *, uint64_t);
int32_t (*Execute)(struct _AlgoContext *, size_t);
int32_t (*GetResults)(struct _AlgoContext *, cl_uint *);
void (*Cleanup)(struct _AlgoContext *);
cl_mem *ExtraBuffers;
cl_program Program;
cl_kernel *Kernels;
size_t GlobalSize;
size_t WorkSize;
size_t *GPUIdxs;
void *ExtraData;
size_t Nonce;
uint32_t InputLen;
} AlgoContext;
int32_t InitOpenCLPlatformContext(OCLPlatform *OCL, uint32_t RequestedPlatformIdx, uint32_t NumDevicesRequested, uint32_t *RequestedDeviceIdxs);
void ReleaseOpenCLPlatformContext(OCLPlatform *OCL);
#endif