Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
aidge_core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Eclipse Projects
aidge
aidge_core
Commits
c3e8588e
Commit
c3e8588e
authored
1 year ago
by
Inna Kucher
Browse files
Options
Downloads
Patches
Plain Diff
adding scaling operator
parent
1d0c8d19
No related branches found
No related tags found
1 merge request
!12
Quantization ptq
Pipeline
#31989
passed
1 year ago
Stage: static_analysis
Stage: build
Stage: test
Stage: coverage
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
include/aidge/operator/Scaling.hpp
+130
-0
130 additions, 0 deletions
include/aidge/operator/Scaling.hpp
with
130 additions
and
0 deletions
include/aidge/operator/Scaling.hpp
0 → 100644
+
130
−
0
View file @
c3e8588e
/********************************************************************************
* Copyright (c) 2023 CEA-List
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*
********************************************************************************/
#ifndef __AIDGE_CORE_OPERATOR_Scaling_H__
#define __AIDGE_CORE_OPERATOR_Scaling_H__
#include
<vector>
#include
<memory>
#include
<memory>
#include
<iostream>
#include
"aidge/utils/Parameter.hpp"
#include
"aidge/utils/Registrar.hpp"
#include
"aidge/operator/Operator.hpp"
#include
"aidge/backend/OperatorImpl.hpp"
#include
"aidge/data/Tensor.hpp"
#include
"aidge/data/Data.hpp"
#include
"aidge/graph/Node.hpp"
#include
"aidge/utils/Types.h"
namespace
Aidge
{
enum
class
ScalingParam
{
scalingFactor
};
class
Scaling_Op
:
public
Operator
,
public
Registrable
<
Scaling_Op
,
std
::
string
,
std
::
unique_ptr
<
OperatorImpl
>
(
const
Scaling_Op
&
)
>
,
public
Parameterizable
<
ScalingParam
,
float
>
{
public:
// FIXME: change accessibility
std
::
shared_ptr
<
Tensor
>
mInput
=
std
::
make_shared
<
Tensor
>
();
const
std
::
shared_ptr
<
Tensor
>
mOutput
=
std
::
make_shared
<
Tensor
>
();
public:
static
constexpr
const
char
*
Type
=
"Scaling"
;
Scaling_Op
()
=
delete
;
using
Parameterizable_
=
Parameterizable
<
ScalingParam
,
float
>
;
template
<
ScalingParam
e
>
using
param
=
typename
Parameterizable_
::
template
param
<
e
>;
Scaling_Op
(
float
scalingFactor
)
:
Operator
(
Type
),
Parameterizable_
(
param
<
ScalingParam
::
scalingFactor
>
(
scalingFactor
))
{
setDatatype
(
DataType
::
Float32
);
}
void
associateInput
(
__attribute__
((
unused
))
const
IOIndex_t
inputIdx
,
std
::
shared_ptr
<
Data
>
data
)
override
final
{
assert
(
inputIdx
==
0
&&
"operator supports only 1 input"
);
assert
(
strcmp
(
data
->
type
(),
Tensor
::
Type
)
==
0
&&
"input data must be of Tensor type"
);
mInput
=
std
::
dynamic_pointer_cast
<
Tensor
>
(
data
);
}
void
computeOutputDims
()
override
final
{
if
(
!
mInput
->
empty
())
mOutput
->
resize
(
mInput
->
dims
());
}
bool
outputDimsForwarded
()
const
override
final
{
return
!
(
mOutput
->
empty
());
}
inline
Tensor
&
input
(
__attribute__
((
unused
))
const
IOIndex_t
inputIdx
)
const
override
final
{
return
*
(
mInput
.
get
());
}
inline
Tensor
&
output
(
__attribute__
((
unused
))
const
IOIndex_t
outputIdx
)
const
override
final
{
return
*
(
mOutput
.
get
());
}
inline
std
::
shared_ptr
<
Tensor
>
getInput
(
__attribute__
((
unused
))
const
IOIndex_t
inputIdx
)
const
override
final
{
assert
((
inputIdx
==
0
)
&&
"Scaling Operator has only 1 input"
);
return
mInput
;
}
inline
std
::
shared_ptr
<
Tensor
>
getOutput
(
__attribute__
((
unused
))
const
IOIndex_t
outputIdx
)
const
override
final
{
assert
((
outputIdx
==
0
)
&&
"Scaling Operator has only 1 output"
);
return
mOutput
;
}
std
::
shared_ptr
<
Data
>
getRawInput
(
__attribute__
((
unused
))
const
IOIndex_t
inputIdx
)
const
override
final
{
assert
(
inputIdx
==
0
&&
"operator supports only 1 input"
);
return
std
::
static_pointer_cast
<
Data
>
(
mInput
);
}
std
::
shared_ptr
<
Data
>
getRawOutput
(
__attribute__
((
unused
))
const
IOIndex_t
outputIdx
)
const
override
final
{
assert
(
outputIdx
==
0
&&
"operator supports only 1 output"
);
return
mOutput
;
}
void
setBackend
(
const
std
::
string
&
name
)
{
mImpl
=
Registrar
<
Scaling_Op
>::
create
(
name
)(
*
this
);
mOutput
->
setBackend
(
name
);
// FIXME: temporary workaround
mInput
->
setBackend
(
name
);
}
void
setDatatype
(
const
DataType
&
datatype
)
{
mOutput
->
setDatatype
(
datatype
);
// FIXME: temporary workaround
mInput
->
setDatatype
(
datatype
);
}
inline
IOIndex_t
nbInputs
()
const
noexcept
override
final
{
return
1
;
}
inline
IOIndex_t
nbDataInputs
()
const
noexcept
override
final
{
return
1
;
}
inline
IOIndex_t
nbOutputs
()
const
noexcept
override
final
{
return
1
;
}
};
inline
std
::
shared_ptr
<
Node
>
Scaling
(
float
scalingFactor
=
1.0
f
,
const
char
*
name
=
nullptr
)
{
// FIXME: properly handle default w&b initialization in every cases
return
std
::
make_shared
<
Node
>
(
std
::
make_shared
<
Scaling_Op
>
(
scalingFactor
),
name
);
}
}
namespace
{
template
<
>
const
char
*
const
EnumStrings
<
Aidge
::
ScalingParam
>::
data
[]
=
{
"scalingFactor"
};
}
#endif
/* __AIDGE_CORE_OPERATOR_RELU_H__ */
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment