MCPcopy Create free account
hub / github.com/0xShug0/audio.cpp / build

Method build

src/framework/modules/conv_modules.cpp:233–291  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

231}
232
233core::TensorValue view_batch_matrix(
234 core::ModuleBuildContext & ctx,
235 const core::TensorValue & input,
236 int64_t batch_index,
237 int64_t channels,
238 int64_t frames) {
239 auto * view = ggml_view_2d(
240 ctx.ggml,
241 input.tensor,
242 frames,
243 channels,
244 input.tensor->nb[1],
245 static_cast<size_t>(batch_index) * input.tensor->nb[2]);
246 return core::wrap_tensor(view, core::TensorShape::from_dims({channels, frames}), input.type);
247}
248
249} // namespace
250
251bool is_conv_transpose1d_col2im_fast_path_eligible(
252 const core::ModuleBuildContext & ctx,
253 const ConvTranspose1dConfig & config) noexcept {
254 return ctx.backend_type == core::BackendType::Cuda && config.dilation == 1;
255}
256
257Conv1dModule::Conv1dModule(Conv1dConfig config) : config_(config) {
258 if (config_.in_channels <= 0 || config_.out_channels <= 0 || config_.kernel_size <= 0) {
259 throw std::runtime_error("Conv1dConfig dimensions must be positive");
260 }
261 if (config_.stride <= 0 || config_.dilation <= 0) {
262 throw std::runtime_error("Conv1d stride and dilation must be positive");
263 }
264}
265
266const Conv1dConfig & Conv1dModule::config() const noexcept {
267 return config_;
268}
269
270const core::ModuleSchema & Conv1dModule::schema() const noexcept {
271 return static_schema();
272}
273
274core::TensorValue Conv1dModule::build(
275 core::ModuleBuildContext & ctx,
276 const core::TensorValue & input,
277 const Conv1dWeights & weights) const {
278 if (ctx.ggml == nullptr) {
279 throw std::runtime_error("ModuleBuildContext.ggml is null");
280 }
281 core::validate_rank_between(input, 3, 3, "input");
282 core::validate_shape(
283 input,
284 core::TensorShape::from_dims({input.shape.dims[0], config_.in_channels, input.shape.dims[2]}),
285 "input");
286 core::validate_shape(
287 weights.weight,
288 core::TensorShape::from_dims({config_.out_channels, config_.in_channels, config_.kernel_size}),
289 "weight");
290

Calls 15

validate_rank_betweenFunction · 0.85
validate_shapeFunction · 0.85
wrap_tensorFunction · 0.85
ggml_conv_1dFunction · 0.85
ConcatModuleClass · 0.85
conv2d_output_dimFunction · 0.85
ggml_conv_2dFunction · 0.85
reshape_tensorFunction · 0.85
ggml_repeatFunction · 0.85
ggml_addFunction · 0.85

Tested by

no test coverage detected