IntelĀ® Machine Learning Scaling Library  2018
A library providing an efficient implementation of communication patterns used in deep learning.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
mlsl.hpp
Go to the documentation of this file.
1 
5 #ifndef MLSL_HPP
6 #define MLSL_HPP
7 
8 #include <cstddef>
9 
10 /* API version (which is not necessarily the same as the tarball/mlsl package version number) */
11 
13 #define MLSL_MAJOR_VERSION 1
14 
16 #define MLSL_MINOR_VERSION 0
17 
23 #define MLSL_VERSION(major, minor) ((major << 16) | (minor))
24 
29 #define MLSL_MAJOR(version) (version >> 16)
30 
35 #define MLSL_MINOR(version) (version & 0xFFFF)
36 
42 #define MLSL_VERSION_GE(v1, v2) ((MLSL_MAJOR(v1) > MLSL_MAJOR(v2)) || \
43  (MLSL_MAJOR(v1) == MLSL_MAJOR(v2) && MLSL_MINOR(v1) == MLSL_MINOR(v2)) || \
44  (MLSL_MAJOR(v1) == MLSL_MAJOR(v2) && MLSL_MINOR(v1) > MLSL_MINOR(v2)))
45 
51 #define MLSL_VERSION_LT(v1, v2) ((MLSL_MAJOR(v1) < MLSL_MAJOR(v2)) || \
52  (MLSL_MAJOR(v1) == MLSL_MAJOR(v2) && MLSL_MINOR(v1) < MLSL_MINOR(v2)))
53 
55 #define NO_EXPLICIT_CREATION(ClassName) \
56  protected: \
57  ClassName() {} \
58  ~ClassName() {} \
59  private: \
60  ClassName(const ClassName&); \
61  ClassName& operator=(const ClassName&); \
62 
63 
67 namespace MLSL
68 {
70  typedef int CommReq;
71 
73  enum DataType
74  {
75  DT_FLOAT = 0,
76  DT_DOUBLE = 1,
77  DT_BYTE = 2
78  };
79 
81  enum PhaseType
82  {
83  PT_TRAIN = 0,
84  PT_TEST = 1
85  };
86 
99  enum GroupType
100  {
101  GT_DATA = 0,
102  GT_MODEL = 1,
104  };
105 
108  {
109  RT_SUM = 0,
110  RT_MIN = 1,
111  RT_MAX = 2
112  };
113 
121  enum OpType
122  {
123  OT_CC = 0,
124  OT_BIAS = 1,
125  OT_ACT = 2,
126  OT_POOL = 3,
127  OT_SPLIT = 4,
128  OT_CONCAT = 5,
129  OT_BCAST = 6,
130  OT_REDUCE = 7,
131  OT_DATA = 8,
132  OT_EVAL = 9
133  };
134 
137  {
138  CT_NONE = 0,
140  };
141 
147  typedef struct
148  {
149  char* lib_path;
153  size_t block_size;
154  size_t elem_in_block;
155  } QuantParams;
156 
163  {
165 
166  public:
167 
169  size_t GetMbOffset();
170 
172  size_t GetMbCount();
173 
175  size_t GetFmOffset();
176 
178  size_t GetFmCount();
179 
181  size_t GetFmSize();
182 
185 
187  size_t GetBufOffset();
188  };
189 
196  {
198 
199  public:
200 
202  size_t GetGlobalFmCount();
203 
205  size_t GetGlobalFmOffset();
206 
208  size_t GetLocalFmCount();
209 
211  size_t GetPackBlockCount();
212 
214  size_t GetUnpackBlockCount();
215 
221  CommBlockInfo* GetPackBlock(size_t idx);
222 
228  CommBlockInfo* GetUnpackBlock(size_t idx);
229 
232 
234  size_t GetFmSize();
235 
237  void* GetCommBuf();
238 
240  size_t GetCommBufSize();
241 
246  void StartComm(void* buf);
247 
252  void* WaitComm();
253  };
254 
262  {
264 
265  public:
266 
268  size_t GetGlobalKernelCount();
269 
271  size_t GetGlobalKernelOffset();
272 
274  size_t GetLocalKernelCount();
275 
280  size_t GetOwnedKernelCount();
281 
283  size_t GetOwnedKernelOffset();
284 
287 
289  size_t GetKernelSize();
290 
295  bool IsDistributedUpdate();
296 
301  void StartGradientComm(void* buf);
302 
307  void StartIncrementComm(void* buf);
308 
312  void* WaitGradientComm();
313 
319  void* TestGradientComm(bool* isCompleted);
320 
324  void* WaitIncrementComm();
325  };
326 
336  {
338 
339  public:
340 
346  size_t GetProcessIdx(GroupType groupType);
347 
353  size_t GetProcessCount(GroupType groupType);
354 
364  CommReq* Bcast(void* buffer, size_t count, DataType dataType, size_t rootIdx, GroupType groupType);
365 
377  CommReq* Reduce(void* sendBuffer, void* recvBuffer, size_t count, DataType dataType, ReductionType redType, size_t rootIdx, GroupType groupType);
378 
389  CommReq* AllReduce(void* sendBuffer, void* recvBuffer, size_t count, DataType dataType, ReductionType redType, GroupType groupType);
390 
402  CommReq* AlltoAll(void* sendBuffer, size_t sendCount, void* recvBuffer, DataType dataType, GroupType groupType);
403 
417  CommReq* AlltoAllv(void* sendBuffer, size_t* sendCounts, size_t* sendOffsets, void* recvBuffer, size_t* recvCounts, size_t* recvOffsets, DataType dataType, GroupType groupType);
418 
430  CommReq* Gather(void* sendBuffer, size_t sendCount, void* recvBuffer, DataType dataType, size_t rootIdx, GroupType groupType);
431 
442  CommReq* AllGather(void* sendBuffer, size_t sendCount, void* recvBuffer, DataType dataType, GroupType groupType);
443 
455  CommReq* Scatter(void* sendBuffer, void* recvBuffer, size_t recvCount, DataType dataType, size_t rootIdx, GroupType groupType);
456 
467  CommReq* ReduceScatter(void* sendBuffer, void* recvBuffer, size_t recvCount, DataType dataType, ReductionType redType, GroupType groupType);
468 
473  void Barrier(GroupType groupType);
474  };
475 
483  {
485 
486  public:
487 
492  void SetName(const char* name);
493 
501  size_t AddInput(size_t featureMapCount, size_t featureMapSize, DataType dataType);
502 
510  size_t AddOutput(size_t featureMapCount, size_t featureMapSize, DataType dataType);
511 
521  size_t AddParameterSet(size_t kernelCount, size_t kernelSize, DataType dataType, bool distributedUpdate = false, CompressionType compressType = CT_NONE);
522 
527  void Validate(Distribution* dist = NULL);
528  };
529 
530  class Session;
531 
536  class Operation
537  {
539 
540  public:
541 
546  void SetDistribution(Distribution* dist);
547 
550 
552  Session* GetSession();
553 
555  OpType GetOpType();
556 
563  void SetPrev(Operation* prev, size_t actIdx, size_t prevOpActIdx);
564 
571  void SetNext(Operation* next, size_t actIdx, size_t nextOpActIdx);
572 
574  const char* GetName();
575 
577  size_t GetGlobalMinibatchSize();
578 
580  size_t GetLocalMinibatchSize();
581 
583  size_t GetGlobalMinibatchOffset();
584 
586  size_t GetInputCount();
587 
593  Activation* GetInput(size_t idx);
594 
596  size_t GetOutputCount();
597 
603  Activation* GetOutput(size_t idx);
604 
606  bool HasParameterSets();
607 
609  size_t GetParameterSetCount();
610 
616  ParameterSet* GetParameterSet(size_t idx);
617  };
618 
624  {
626 
627  public:
628 
630  void Start();
631 
633  void Stop();
634 
636  void Reset();
637 
639  bool IsStarted();
640 
642  bool IsEnabled();
643 
645  void Print();
646 
652  unsigned long long GetIsolationCommCycles(size_t opIdx);
653 
659  size_t GetCommSize(size_t opIdx);
660 
666  unsigned long long GetCommCycles(size_t opIdx);
667 
673  unsigned long long GetComputeCycles(size_t opIdx);
674 
679  unsigned long long GetTotalIsolationCommCycles();
680 
685  size_t GetTotalCommSize();
686 
691  unsigned long long GetTotalCommCycles();
692 
697  unsigned long long GetTotalComputeCycles();
698  };
699 
703  class Session
704  {
706 
707  public:
712  void SetGlobalMinibatchSize(size_t globalMinibatchSize);
713 
715  size_t GetGlobalMinibatchSize();
716 
719 
726 
732 
739  size_t AddOperation(OperationRegInfo* info, Distribution* dist = NULL);
740 
742  void RemoveOperations();
743 
745  size_t GetOperationCount();
746 
752  Operation* GetOperation(size_t idx);
753 
759  void Commit();
760 
765  Statistics* GetStats();
766  };
767 
772  {
774 
775  public:
776 
778  static Environment& GetEnv();
779 
781  static int GetVersion();
782 
788  void Configure(const char* config = NULL);
789 
795  void Init(int* argc, char** argv[]);
796 
798  void Finalize();
799 
801  bool IsInitialized();
802 
804  size_t GetProcessIdx();
805 
807  size_t GetProcessCount();
808 
814  Session* CreateSession(PhaseType phaseType = PT_TRAIN);
815 
820  void DeleteSession(Session* session);
821 
828  Distribution* CreateDistribution(size_t dataPartitions, size_t modelPartitions);
829 
836  Distribution* CreateDistributionWithColors(int dataColor, int modelColor);
837 
842  void DeleteDistribution(Distribution* distribution);
843 
848  void Wait(CommReq* req);
849 
855  void Test(CommReq* req, bool* isCompleted);
856 
865  void* Alloc(size_t size, size_t alignment);
866 
871  void Free(void* ptr);
872 
878  void SetQuantizationParams(QuantParams* params);
879 
884  };
885 };
886 
887 #endif /* MLSL_HPP */
bool IsDistributedUpdate()
#define NO_EXPLICIT_CREATION(ClassName)
Definition: mlsl.hpp:55
void DeleteDistribution(Distribution *distribution)
size_t GetProcessIdx()
Distribution * GetDistribution()
Definition: mlsl.hpp:129
Definition: mlsl.hpp:102
void * GetCommBuf()
A class to hold information about the parallelism scheme being used.
Definition: mlsl.hpp:335
ParameterSet * GetParameterSet(size_t idx)
void Free(void *ptr)
size_t GetProcessCount()
size_t AddParameterSet(size_t kernelCount, size_t kernelSize, DataType dataType, bool distributedUpdate=false, CompressionType compressType=CT_NONE)
size_t elem_in_block
Definition: mlsl.hpp:154
A class to measure and store performance statistics of communication among processes that perform com...
Definition: mlsl.hpp:623
CommBlockInfo * GetPackBlock(size_t idx)
unsigned long long GetTotalIsolationCommCycles()
PhaseType GetPhaseType()
void * WaitGradientComm()
size_t GetLocalKernelCount()
size_t GetOwnedKernelOffset()
void StartComm(void *buf)
unsigned long long GetTotalCommCycles()
void SetPrev(Operation *prev, size_t actIdx, size_t prevOpActIdx)
A struct to hold quantization parameters.
Definition: mlsl.hpp:147
A class to hold block information for activations packing/unpacking.
Definition: mlsl.hpp:162
char * quant_buffer_func_name
Definition: mlsl.hpp:150
size_t GetKernelSize()
size_t GetCommBufSize()
Operation * GetOperation(size_t idx)
size_t GetGlobalFmCount()
CommReq * AlltoAll(void *sendBuffer, size_t sendCount, void *recvBuffer, DataType dataType, GroupType groupType)
void Test(CommReq *req, bool *isCompleted)
CommBlockInfo * GetUnpackBlock(size_t idx)
Definition: mlsl.hpp:84
void Barrier(GroupType groupType)
PhaseType
Definition: mlsl.hpp:81
static int GetVersion()
const char * GetName()
void * TestGradientComm(bool *isCompleted)
char * dequant_buffer_func_name
Definition: mlsl.hpp:151
DataType GetDataType()
void DeleteSession(Session *session)
A class to hold Operation registration information.
Definition: mlsl.hpp:482
OpType
Compute operation types.
Definition: mlsl.hpp:121
DataType
Definition: mlsl.hpp:73
char * lib_path
Definition: mlsl.hpp:149
CommReq * Bcast(void *buffer, size_t count, DataType dataType, size_t rootIdx, GroupType groupType)
size_t block_size
Definition: mlsl.hpp:153
size_t GetGlobalMinibatchSize()
Session * CreateSession(PhaseType phaseType=PT_TRAIN)
void StartGradientComm(void *buf)
Definition: mlsl.hpp:77
size_t GetProcessIdx(GroupType groupType)
size_t GetProcessCount(GroupType groupType)
Definition: mlsl.hpp:110
void RemoveOperations()
size_t GetUnpackBlockCount()
void * WaitIncrementComm()
Definition: mlsl.hpp:123
Definition: mlsl.hpp:125
A class to represent a collection of Operation objects with the same global mini-batch size...
Definition: mlsl.hpp:703
unsigned long long GetCommCycles(size_t opIdx)
Distribution * CreateDistributionWithColors(int dataColor, int modelColor)
Statistics * GetStats()
unsigned long long GetIsolationCommCycles(size_t opIdx)
CommReq * AllReduce(void *sendBuffer, void *recvBuffer, size_t count, DataType dataType, ReductionType redType, GroupType groupType)
CommReq * ReduceScatter(void *sendBuffer, void *recvBuffer, size_t recvCount, DataType dataType, ReductionType redType, GroupType groupType)
void SetDistribution(Distribution *dist)
void Wait(CommReq *req)
Definition: mlsl.hpp:75
Definition: mlsl.hpp:76
Definition: mlsl.hpp:130
Definition: mlsl.hpp:103
A class to hold information about learnable parameters (parameter sets) and activations corresponding...
Definition: mlsl.hpp:536
Definition: mlsl.hpp:101
size_t GetPackBlockCount()
static Environment & GetEnv()
size_t GetGlobalMinibatchSize()
size_t GetFmSize()
size_t GetOutputCount()
size_t GetGlobalKernelOffset()
A wrapper class for operation input and output activations.
Definition: mlsl.hpp:195
size_t GetOwnedKernelCount()
size_t GetTotalCommSize()
Definition: mlsl.hpp:83
size_t GetParameterSetCount()
OpType GetOpType()
CommReq * AllGather(void *sendBuffer, size_t sendCount, void *recvBuffer, DataType dataType, GroupType groupType)
void SetQuantizationParams(QuantParams *params)
OperationRegInfo * CreateOperationRegInfo(OpType opType)
CommReq * AlltoAllv(void *sendBuffer, size_t *sendCounts, size_t *sendOffsets, void *recvBuffer, size_t *recvCounts, size_t *recvOffsets, DataType dataType, GroupType groupType)
size_t GetGlobalMinibatchOffset()
void Configure(const char *config=NULL)
CommReq * Scatter(void *sendBuffer, void *recvBuffer, size_t recvCount, DataType dataType, size_t rootIdx, GroupType groupType)
CommReq * Gather(void *sendBuffer, size_t sendCount, void *recvBuffer, DataType dataType, size_t rootIdx, GroupType groupType)
CompressionType
Definition: mlsl.hpp:136
Definition: mlsl.hpp:127
Definition: mlsl.hpp:111
DataType GetDataType()
Activation * GetOutput(size_t idx)
void * Alloc(size_t size, size_t alignment)
Definition: mlsl.hpp:126
Distribution * CreateDistribution(size_t dataPartitions, size_t modelPartitions)
Definition: mlsl.hpp:132
void SetNext(Operation *next, size_t actIdx, size_t nextOpActIdx)
size_t AddOperation(OperationRegInfo *info, Distribution *dist=NULL)
CommReq * Reduce(void *sendBuffer, void *recvBuffer, size_t count, DataType dataType, ReductionType redType, size_t rootIdx, GroupType groupType)
GroupType
Groups of processes supported by Intel MLSL.
Definition: mlsl.hpp:99
size_t GetGlobalKernelCount()
Definition: mlsl.hpp:124
char * reduce_sum_func_name
Definition: mlsl.hpp:152
size_t GetOperationCount()
A wrapper class for operation parameters.
Definition: mlsl.hpp:261
Definition: mlsl.hpp:138
size_t AddOutput(size_t featureMapCount, size_t featureMapSize, DataType dataType)
Definition: mlsl.hpp:131
unsigned long long GetComputeCycles(size_t opIdx)
void Validate(Distribution *dist=NULL)
Definition: mlsl.hpp:139
Activation * GetInput(size_t idx)
void DeleteOperationRegInfo(OperationRegInfo *info)
Session * GetSession()
DataType GetDataType()
bool HasParameterSets()
A singleton object that holds global Intel MLSL functions.
Definition: mlsl.hpp:771
size_t GetGlobalFmOffset()
ReductionType
Definition: mlsl.hpp:107
size_t GetLocalMinibatchSize()
void Init(int *argc, char **argv[])
void SetName(const char *name)
size_t GetCommSize(size_t opIdx)
Definition: mlsl.hpp:109
size_t AddInput(size_t featureMapCount, size_t featureMapSize, DataType dataType)
void StartIncrementComm(void *buf)
int CommReq
Definition: mlsl.hpp:70
QuantParams * GetQuantizationParams()
size_t GetInputCount()
size_t GetLocalFmCount()
Definition: mlsl.hpp:128
unsigned long long GetTotalComputeCycles()
void SetGlobalMinibatchSize(size_t globalMinibatchSize)