|
| 1 | +# Basic NCCL Tuner Plugin |
| 2 | + |
| 3 | +This directory contains a minimal placeholder implementation of an NCCL tuner plugin. It serves as a starting point for developing custom tuner plugins by providing the essential function stubs and interface structure required by NCCL. |
| 4 | + |
| 5 | +## Purpose |
| 6 | + |
| 7 | +This basic plugin is designed to: |
| 8 | +- Provide a minimal working example of the NCCL tuner plugin interface |
| 9 | +- Serve as a template for developing custom tuner plugins |
| 10 | +- Demonstrate the required function signatures and structure |
| 11 | +- Implement placeholder functionality that can be extended |
| 12 | + |
| 13 | + |
| 14 | +## Implementation Details |
| 15 | + |
| 16 | +The plugin implements the following functions: |
| 17 | + |
| 18 | +### `pluginInit` |
| 19 | +```c |
| 20 | +ncclResult_t pluginInit(size_t nRanks, size_t nNodes, ncclDebugLogger_t logFunction, void **context) |
| 21 | +``` |
| 22 | +- **Purpose**: Initialize the plugin with communicator information |
| 23 | +- **Current Implementation**: Simple placeholder that returns success |
| 24 | +- **Parameters**: |
| 25 | + - `nRanks`: Total number of ranks in the communicator |
| 26 | + - `nNodes`: Total number of nodes in the communicator |
| 27 | + - `logFunction`: NCCL debug logging function |
| 28 | + - `context`: Plugin context pointer (output) |
| 29 | +
|
| 30 | +### `pluginGetCollInfo` |
| 31 | +```c |
| 32 | +ncclResult_t pluginGetCollInfo(void* context, ncclFunc_t collType, size_t nBytes, |
| 33 | + int numPipeOps, float** collCostTable, int numAlgo, int numProto, |
| 34 | + int regBuff, int* nChannels) |
| 35 | +``` |
| 36 | +- **Purpose**: Modify cost tables for collective operations |
| 37 | +- **Current Implementation**: |
| 38 | + - Sets RING+SIMPLE algorithm to cost 0.0 (highest preference) |
| 39 | + - Sets channel count to 1 |
| 40 | +- **Parameters**: |
| 41 | + - `context`: Plugin context from init |
| 42 | + - `collType`: Type of collective operation |
| 43 | + - `nBytes`: Message size in bytes |
| 44 | + - `numPipeOps`: Number of pipeline operations |
| 45 | + - `collCostTable`: Cost table to modify |
| 46 | + - `numAlgo`: Number of algorithms |
| 47 | + - `numProto`: Number of protocols |
| 48 | + - `regBuff`: Whether buffer can be registered |
| 49 | + - `nChannels`: Number of channels to use (output) |
| 50 | + |
| 51 | +### `pluginDestroy` |
| 52 | +```c |
| 53 | +ncclResult_t pluginDestroy(void* context) |
| 54 | +``` |
| 55 | +- **Purpose**: Clean up plugin resources |
| 56 | +- **Current Implementation**: Simple placeholder that returns success |
| 57 | +
|
| 58 | +## Cost Table Structure |
| 59 | +
|
| 60 | +The plugin demonstrates how to modify NCCL's cost tables: |
| 61 | +
|
| 62 | +```c |
| 63 | +float (*table)[NCCL_NUM_PROTOCOLS] = (float (*)[NCCL_NUM_PROTOCOLS])collCostTable; |
| 64 | +``` |
| 65 | + |
| 66 | +The cost table is a 2D array where: |
| 67 | +- First dimension: Algorithm index (e.g., `NCCL_ALGO_RING`) |
| 68 | +- Second dimension: Protocol index (e.g., `NCCL_PROTO_SIMPLE`) |
| 69 | +- Values: Cost for that algorithm/protocol combination |
| 70 | + |
| 71 | +### Cost Values |
| 72 | +- **0.0**: Highest preference (lowest cost) |
| 73 | +- **Positive values**: Relative costs (lower is better) |
| 74 | +- **`NCCL_ALGO_PROTO_IGNORE`**: Disable this combination |
| 75 | + |
| 76 | +## Building |
| 77 | + |
| 78 | +```bash |
| 79 | +make |
| 80 | +``` |
| 81 | + |
| 82 | +This creates `libnccl-tuner-basic.so` which can be loaded by NCCL. |
| 83 | + |
| 84 | +## Usage |
| 85 | + |
| 86 | +### Loading the Plugin |
| 87 | + |
| 88 | +```bash |
| 89 | +export LD_LIBRARY_PATH=/path/to/basic:$LD_LIBRARY_PATH |
| 90 | +mpirun -np 4 your_nccl_application |
| 91 | +``` |
| 92 | + |
| 93 | +```bash |
| 94 | +export NCCL_TUNER_PLUGIN=basic |
| 95 | +export NCCL_TUNER_PLUGIN=libnccl-tuner-basic.so |
| 96 | +export NCCL_TUNER_PLUGIN=/path/to/your/plugin/libnccl-tuner-basic.so |
| 97 | +``` |
| 98 | + |
| 99 | +### Verifying Plugin Loading |
| 100 | + |
| 101 | +Enable NCCL debug output to see if the plugin is loaded: |
| 102 | + |
| 103 | +```bash |
| 104 | +export NCCL_DEBUG=INFO |
| 105 | +``` |
| 106 | + |
| 107 | +You should see messages indicating the tuner plugin is being used. |
| 108 | + |
| 109 | +## Extending the Plugin |
| 110 | + |
| 111 | +This basic plugin provides a foundation that you can extend: |
| 112 | + |
| 113 | +### 1. Add Configuration Logic |
| 114 | + |
| 115 | +Modify `pluginGetCollInfo` to implement your tuning strategy: |
| 116 | + |
| 117 | +```c |
| 118 | +__hidden ncclResult_t pluginGetCollInfo(void* context, ncclFunc_t collType, size_t nBytes, |
| 119 | + int numPipeOps, float** collCostTable, int numAlgo, int numProto, |
| 120 | + int regBuff, int* nChannels) { |
| 121 | + // Your custom tuning logic here |
| 122 | + if (nBytes < 1024) { |
| 123 | + // Small message optimization |
| 124 | + table[NCCL_ALGO_TREE][NCCL_PROTO_SIMPLE] = 0.0; |
| 125 | + } else { |
| 126 | + // Large message optimization |
| 127 | + table[NCCL_ALGO_RING][NCCL_PROTO_LL128] = 0.0; |
| 128 | + } |
| 129 | + |
| 130 | + // Dynamic channel selection |
| 131 | + *nChannels = (nBytes > 1024*1024) ? 4 : 1; |
| 132 | + |
| 133 | + return ncclSuccess; |
| 134 | +} |
| 135 | +``` |
| 136 | +
|
| 137 | +### 2. Add Context Management |
| 138 | +
|
| 139 | +Use the context pointer to store plugin state: |
| 140 | +
|
| 141 | +```c |
| 142 | +struct pluginContext { |
| 143 | + int initialized; |
| 144 | + size_t nRanks; |
| 145 | + size_t nNodes; |
| 146 | + // Add your plugin-specific data here |
| 147 | +}; |
| 148 | +``` |
| 149 | + |
| 150 | +### 3. Add File-Based Configuration |
| 151 | + |
| 152 | +Read configuration from files, environment variables, or other sources. |
| 153 | + |
| 154 | +### 4. Add Topology Awareness |
| 155 | + |
| 156 | +Use the `nRanks` and `nNodes` parameters to implement topology-specific tuning. |
| 157 | + |
| 158 | +## File Structure |
| 159 | + |
| 160 | +``` |
| 161 | +basic/ |
| 162 | +├── README.md # This file |
| 163 | +├── plugin.c # Plugin implementation |
| 164 | +├── Makefile # Build configuration |
| 165 | +└── nccl/ # NCCL header files |
| 166 | + └── tuner.h # Tuner plugin interface definitions |
| 167 | +``` |
| 168 | + |
| 169 | +## Next Steps |
| 170 | + |
| 171 | +1. **Understand the Interface**: Study the function signatures and parameters |
| 172 | +2. **Implement Your Logic**: Add your tuning strategy to `pluginGetCollInfo` |
| 173 | +3. **Test Thoroughly**: Verify your plugin works with different message sizes and topologies |
| 174 | +4. **Add Error Handling**: Implement proper error checking and resource management |
| 175 | +5. **Document Your Changes**: Update this README with your specific implementation details |
| 176 | + |
| 177 | +## Comparison with Example Plugin |
| 178 | + |
| 179 | +- **Basic Plugin**: Minimal implementation, good for learning and simple use cases |
| 180 | +- **Example Plugin**: Full-featured CSV-based configuration system, good for production use |
| 181 | + |
| 182 | +Choose the basic plugin if you want to: |
| 183 | +- Learn the tuner plugin interface |
| 184 | +- Implement simple, hardcoded tuning strategies |
| 185 | +- Build a custom plugin from scratch |
| 186 | + |
| 187 | +Choose the example plugin if you want: |
| 188 | +- File-based configuration |
| 189 | +- Complex tuning strategies |
| 190 | +- Production-ready features |
| 191 | + |
| 192 | +## Resources |
| 193 | + |
| 194 | +- [Parent Directory README](../README.md) - General tuner plugin development guide |
| 195 | +- [Example Plugin](../example/README.md) - Fully featured implementation |
| 196 | + |
| 197 | +This basic plugin provides the foundation you need to start developing custom NCCL tuner plugins. Extend it with your specific tuning logic and requirements. |
0 commit comments