MCPcopy Create free account
hub / github.com/NVIDIA/TensorRT / sparsify

Function sparsify

samples/common/sampleUtils.cpp:329–355  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

327 IFullyConnectedLayer& l, int32_t k, int32_t trs, std::vector<int8_t>& sparseWeights);
328
329void sparsify(nvinfer1::INetworkDefinition& network, std::vector<std::vector<int8_t>>& sparseWeights)
330{
331 for (int32_t l = 0; l < network.getNbLayers(); ++l)
332 {
333 auto* layer = network.getLayer(l);
334 auto const t = layer->getType();
335 if (t == nvinfer1::LayerType::kCONVOLUTION)
336 {
337 auto& conv = *static_cast<IConvolutionLayer*>(layer);
338 auto const& dims = conv.getKernelSizeNd();
339 ASSERT(dims.nbDims == 2 || dims.nbDims == 3);
340 auto const k = conv.getNbOutputMaps();
341 auto const trs = std::accumulate(dims.d, dims.d + dims.nbDims, 1, std::multiplies<int32_t>());
342 sparseWeights.emplace_back();
343 setSparseWeights(conv, k, trs, sparseWeights.back());
344 }
345 else if (t == nvinfer1::LayerType::kFULLY_CONNECTED)
346 {
347 auto& fc = *static_cast<nvinfer1::IFullyConnectedLayer*>(layer);
348 auto const k = fc.getNbOutputChannels();
349 sparseWeights.emplace_back();
350 setSparseWeights(fc, k, 1, sparseWeights.back());
351 }
352 }
353
354 sparsifyMatMulKernelWeights(network, sparseWeights);
355}
356
357void sparsify(Weights const& weights, int32_t k, int32_t trs, std::vector<int8_t>& sparseWeights)
358{

Callers 3

setupNetworkAndConfigFunction · 0.85
setSparseWeightsFunction · 0.85

Calls 9

setSparseWeightsFunction · 0.85
getLayerMethod · 0.80
getNbLayersMethod · 0.45
getTypeMethod · 0.45
getKernelSizeNdMethod · 0.45
getNbOutputMapsMethod · 0.45
resizeMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected